diff --git a/assets/index.es-45d7fec3.js b/assets/index.es-3acd4243.js similarity index 99% rename from assets/index.es-45d7fec3.js rename to assets/index.es-3acd4243.js index 99a157b..0408095 100644 --- a/assets/index.es-45d7fec3.js +++ b/assets/index.es-3acd4243.js @@ -1,4 +1,4 @@ -import{c as Je,g as Do}from"./main-9cddcd54.js";import{_ as Ha}from"./jspdf.es.min-2fc60f34.js";var ct=function(a){return a&&a.Math===Math&&a},U=ct(typeof globalThis=="object"&&globalThis)||ct(typeof window=="object"&&window)||ct(typeof self=="object"&&self)||ct(typeof Je=="object"&&Je)||ct(typeof Je=="object"&&Je)||function(){return this}()||Function("return this")(),ut={},L=function(a){try{return!!a()}catch{return!0}},Rl=L,ce=!Rl(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),Il=L,br=!Il(function(){var a=(function(){}).bind();return typeof a!="function"||a.hasOwnProperty("prototype")}),Nl=br,Ht=Function.prototype.call,Y=Nl?Ht.bind(Ht):function(){return Ht.apply(Ht,arguments)},Vo={},Lo={}.propertyIsEnumerable,ko=Object.getOwnPropertyDescriptor,Ml=ko&&!Lo.call({1:2},1);Vo.f=Ml?function(e){var t=ko(this,e);return!!t&&t.enumerable}:Lo;var xr=function(a,e){return{enumerable:!(a&1),configurable:!(a&2),writable:!(a&4),value:e}},Bo=br,Fo=Function.prototype,Ya=Fo.call,_l=Bo&&Fo.bind.bind(Ya,Ya),k=Bo?_l:function(a){return function(){return Ya.apply(a,arguments)}},jo=k,Dl=jo({}.toString),Vl=jo("".slice),Fe=function(a){return Vl(Dl(a),8,-1)},Ll=k,kl=L,Bl=Fe,Jr=Object,Fl=Ll("".split),Uo=kl(function(){return!Jr("z").propertyIsEnumerable(0)})?function(a){return Bl(a)==="String"?Fl(a,""):Jr(a)}:Jr,je=function(a){return a==null},jl=je,Ul=TypeError,ge=function(a){if(jl(a))throw new Ul("Can't call method on "+a);return a},zl=Uo,Gl=ge,At=function(a){return zl(Gl(a))},Xa=typeof document=="object"&&document.all,Hl=typeof Xa>"u"&&Xa!==void 0,zo={all:Xa,IS_HTMLDDA:Hl},Go=zo,Yl=Go.all,D=Go.IS_HTMLDDA?function(a){return typeof a=="function"||a===Yl}:function(a){return typeof a=="function"},yn=D,Ho=zo,Xl=Ho.all,Te=Ho.IS_HTMLDDA?function(a){return typeof a=="object"?a!==null:yn(a)||a===Xl}:function(a){return typeof a=="object"?a!==null:yn(a)},ea=U,Wl=D,ql=function(a){return Wl(a)?a:void 0},Ue=function(a,e){return arguments.length<2?ql(ea[a]):ea[a]&&ea[a][e]},Ql=k,Tr=Ql({}.isPrototypeOf),Sr=typeof navigator<"u"&&String(navigator.userAgent)||"",Yo=U,ta=Sr,mn=Yo.process,bn=Yo.Deno,xn=mn&&mn.versions||bn&&bn.version,Tn=xn&&xn.v8,ue,cr;Tn&&(ue=Tn.split("."),cr=ue[0]>0&&ue[0]<4?1:+(ue[0]+ue[1]));!cr&&ta&&(ue=ta.match(/Edge\/(\d+)/),(!ue||ue[1]>=74)&&(ue=ta.match(/Chrome\/(\d+)/),ue&&(cr=+ue[1])));var Oi=cr,Sn=Oi,Kl=L,Zl=U,Jl=Zl.String,Xo=!!Object.getOwnPropertySymbols&&!Kl(function(){var a=Symbol("symbol detection");return!Jl(a)||!(Object(a)instanceof Symbol)||!Symbol.sham&&Sn&&Sn<41}),eh=Xo,Wo=eh&&!Symbol.sham&&typeof Symbol.iterator=="symbol",th=Ue,rh=D,ah=Tr,ih=Wo,nh=Object,qo=ih?function(a){return typeof a=="symbol"}:function(a){var e=th("Symbol");return rh(e)&&ah(e.prototype,nh(a))},sh=String,Or=function(a){try{return sh(a)}catch{return"Object"}},oh=D,uh=Or,lh=TypeError,Se=function(a){if(oh(a))return a;throw new lh(uh(a)+" is not a function")},hh=Se,vh=je,lt=function(a,e){var t=a[e];return vh(t)?void 0:hh(t)},ra=Y,aa=D,ia=Te,fh=TypeError,ch=function(a,e){var t,r;if(e==="string"&&aa(t=a.toString)&&!ia(r=ra(t,a))||aa(t=a.valueOf)&&!ia(r=ra(t,a))||e!=="string"&&aa(t=a.toString)&&!ia(r=ra(t,a)))return r;throw new fh("Can't convert object to primitive value")},Qo={exports:{}},On=U,gh=Object.defineProperty,Ei=function(a,e){try{gh(On,a,{value:e,configurable:!0,writable:!0})}catch{On[a]=e}return e},dh=U,ph=Ei,En="__core-js_shared__",yh=dh[En]||ph(En,{}),$i=yh,$n=$i;(Qo.exports=function(a,e){return $n[a]||($n[a]=e!==void 0?e:{})})("versions",[]).push({version:"3.34.0",mode:"global",copyright:"© 2014-2023 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.34.0/LICENSE",source:"https://github.com/zloirock/core-js"});var wi=Qo.exports,mh=ge,bh=Object,Er=function(a){return bh(mh(a))},xh=k,Th=Er,Sh=xh({}.hasOwnProperty),le=Object.hasOwn||function(e,t){return Sh(Th(e),t)},Oh=k,Eh=0,$h=Math.random(),wh=Oh(1 .toString),Ko=function(a){return"Symbol("+(a===void 0?"":a)+")_"+wh(++Eh+$h,36)},Ch=U,Ah=wi,wn=le,Ph=Ko,Rh=Xo,Ih=Wo,et=Ch.Symbol,na=Ah("wks"),Nh=Ih?et.for||et:et&&et.withoutSetter||Ph,G=function(a){return wn(na,a)||(na[a]=Rh&&wn(et,a)?et[a]:Nh("Symbol."+a)),na[a]},Mh=Y,Cn=Te,An=qo,_h=lt,Dh=ch,Vh=G,Lh=TypeError,kh=Vh("toPrimitive"),Bh=function(a,e){if(!Cn(a)||An(a))return a;var t=_h(a,kh),r;if(t){if(e===void 0&&(e="default"),r=Mh(t,a,e),!Cn(r)||An(r))return r;throw new Lh("Can't convert object to primitive value")}return e===void 0&&(e="number"),Dh(a,e)},Fh=Bh,jh=qo,Ci=function(a){var e=Fh(a,"string");return jh(e)?e:e+""},Uh=U,Pn=Te,Wa=Uh.document,zh=Pn(Wa)&&Pn(Wa.createElement),$r=function(a){return zh?Wa.createElement(a):{}},Gh=ce,Hh=L,Yh=$r,Zo=!Gh&&!Hh(function(){return Object.defineProperty(Yh("div"),"a",{get:function(){return 7}}).a!==7}),Xh=ce,Wh=Y,qh=Vo,Qh=xr,Kh=At,Zh=Ci,Jh=le,ev=Zo,Rn=Object.getOwnPropertyDescriptor;ut.f=Xh?Rn:function(e,t){if(e=Kh(e),t=Zh(t),ev)try{return Rn(e,t)}catch{}if(Jh(e,t))return Qh(!Wh(qh.f,e,t),e[t])};var de={},tv=ce,rv=L,Jo=tv&&rv(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),av=Te,iv=String,nv=TypeError,K=function(a){if(av(a))return a;throw new nv(iv(a)+" is not an object")},sv=ce,ov=Zo,uv=Jo,Yt=K,In=Ci,lv=TypeError,sa=Object.defineProperty,hv=Object.getOwnPropertyDescriptor,oa="enumerable",ua="configurable",la="writable";de.f=sv?uv?function(e,t,r){if(Yt(e),t=In(t),Yt(r),typeof e=="function"&&t==="prototype"&&"value"in r&&la in r&&!r[la]){var i=hv(e,t);i&&i[la]&&(e[t]=r.value,r={configurable:ua in r?r[ua]:i[ua],enumerable:oa in r?r[oa]:i[oa],writable:!1})}return sa(e,t,r)}:sa:function(e,t,r){if(Yt(e),t=In(t),Yt(r),ov)try{return sa(e,t,r)}catch{}if("get"in r||"set"in r)throw new lv("Accessors not supported");return"value"in r&&(e[t]=r.value),e};var vv=ce,fv=de,cv=xr,Pt=vv?function(a,e,t){return fv.f(a,e,cv(1,t))}:function(a,e,t){return a[e]=t,a},eu={exports:{}},qa=ce,gv=le,tu=Function.prototype,dv=qa&&Object.getOwnPropertyDescriptor,Ai=gv(tu,"name"),pv=Ai&&(function(){}).name==="something",yv=Ai&&(!qa||qa&&dv(tu,"name").configurable),wr={EXISTS:Ai,PROPER:pv,CONFIGURABLE:yv},mv=k,bv=D,Qa=$i,xv=mv(Function.toString);bv(Qa.inspectSource)||(Qa.inspectSource=function(a){return xv(a)});var Pi=Qa.inspectSource,Tv=U,Sv=D,Nn=Tv.WeakMap,Ov=Sv(Nn)&&/native code/.test(String(Nn)),Ev=wi,$v=Ko,Mn=Ev("keys"),Ri=function(a){return Mn[a]||(Mn[a]=$v(a))},Ii={},wv=Ov,ru=U,Cv=Te,Av=Pt,ha=le,va=$i,Pv=Ri,Rv=Ii,_n="Object already initialized",Ka=ru.TypeError,Iv=ru.WeakMap,gr,$t,dr,Nv=function(a){return dr(a)?$t(a):gr(a,{})},Mv=function(a){return function(e){var t;if(!Cv(e)||(t=$t(e)).type!==a)throw new Ka("Incompatible receiver, "+a+" required");return t}};if(wv||va.state){var fe=va.state||(va.state=new Iv);fe.get=fe.get,fe.has=fe.has,fe.set=fe.set,gr=function(a,e){if(fe.has(a))throw new Ka(_n);return e.facade=a,fe.set(a,e),e},$t=function(a){return fe.get(a)||{}},dr=function(a){return fe.has(a)}}else{var Xe=Pv("state");Rv[Xe]=!0,gr=function(a,e){if(ha(a,Xe))throw new Ka(_n);return e.facade=a,Av(a,Xe,e),e},$t=function(a){return ha(a,Xe)?a[Xe]:{}},dr=function(a){return ha(a,Xe)}}var Cr={set:gr,get:$t,has:dr,enforce:Nv,getterFor:Mv},Ni=k,_v=L,Dv=D,Xt=le,Za=ce,Vv=wr.CONFIGURABLE,Lv=Pi,au=Cr,kv=au.enforce,Bv=au.get,Dn=String,or=Object.defineProperty,Fv=Ni("".slice),jv=Ni("".replace),Uv=Ni([].join),zv=Za&&!_v(function(){return or(function(){},"length",{value:8}).length!==8}),Gv=String(String).split("String"),Hv=eu.exports=function(a,e,t){Fv(Dn(e),0,7)==="Symbol("&&(e="["+jv(Dn(e),/^Symbol\(([^)]*)\)/,"$1")+"]"),t&&t.getter&&(e="get "+e),t&&t.setter&&(e="set "+e),(!Xt(a,"name")||Vv&&a.name!==e)&&(Za?or(a,"name",{value:e,configurable:!0}):a.name=e),zv&&t&&Xt(t,"arity")&&a.length!==t.arity&&or(a,"length",{value:t.arity});try{t&&Xt(t,"constructor")&&t.constructor?Za&&or(a,"prototype",{writable:!1}):a.prototype&&(a.prototype=void 0)}catch{}var r=kv(a);return Xt(r,"source")||(r.source=Uv(Gv,typeof e=="string"?e:"")),a};Function.prototype.toString=Hv(function(){return Dv(this)&&Bv(this).source||Lv(this)},"toString");var iu=eu.exports,Yv=D,Xv=de,Wv=iu,qv=Ei,ze=function(a,e,t,r){r||(r={});var i=r.enumerable,n=r.name!==void 0?r.name:e;if(Yv(t)&&Wv(t,n,r),r.global)i?a[e]=t:qv(e,t);else{try{r.unsafe?a[e]&&(i=!0):delete a[e]}catch{}i?a[e]=t:Xv.f(a,e,{value:t,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return a},nu={},Qv=Math.ceil,Kv=Math.floor,Zv=Math.trunc||function(e){var t=+e;return(t>0?Kv:Qv)(t)},Jv=Zv,Ar=function(a){var e=+a;return e!==e||e===0?0:Jv(e)},ef=Ar,tf=Math.max,rf=Math.min,su=function(a,e){var t=ef(a);return t<0?tf(t+e,0):rf(t,e)},af=Ar,nf=Math.min,ht=function(a){return a>0?nf(af(a),9007199254740991):0},sf=ht,Pr=function(a){return sf(a.length)},of=At,uf=su,lf=Pr,Vn=function(a){return function(e,t,r){var i=of(e),n=lf(i),o=uf(r,n),s;if(a&&t!==t){for(;n>o;)if(s=i[o++],s!==s)return!0}else for(;n>o;o++)if((a||o in i)&&i[o]===t)return a||o||0;return!a&&-1}},ou={includes:Vn(!0),indexOf:Vn(!1)},hf=k,fa=le,vf=At,ff=ou.indexOf,cf=Ii,Ln=hf([].push),uu=function(a,e){var t=vf(a),r=0,i=[],n;for(n in t)!fa(cf,n)&&fa(t,n)&&Ln(i,n);for(;e.length>r;)fa(t,n=e[r++])&&(~ff(i,n)||Ln(i,n));return i},Mi=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],gf=uu,df=Mi,pf=df.concat("length","prototype");nu.f=Object.getOwnPropertyNames||function(e){return gf(e,pf)};var lu={};lu.f=Object.getOwnPropertySymbols;var yf=Ue,mf=k,bf=nu,xf=lu,Tf=K,Sf=mf([].concat),Of=yf("Reflect","ownKeys")||function(e){var t=bf.f(Tf(e)),r=xf.f;return r?Sf(t,r(e)):t},kn=le,Ef=Of,$f=ut,wf=de,Cf=function(a,e,t){for(var r=Ef(e),i=wf.f,n=$f.f,o=0;of;f++)if(v=y(a[f]),v&&gs(ps,v))return v;return new hr(!1)}l=$d(a,h)}for(d=n?a.next:l.next;!(g=xd(d,l)).done;){try{v=y(g.value)}catch(x){ds(l,"throw",x)}if(typeof v=="object"&&v&&gs(ps,v))return v}return new hr(!1)},Ad=G,ju=Ad("iterator"),Uu=!1;try{var Pd=0,ys={next:function(){return{done:!!Pd++}},return:function(){Uu=!0}};ys[ju]=function(){return this},Array.from(ys,function(){throw 2})}catch{}var Rd=function(a,e){try{if(!e&&!Uu)return!1}catch{return!1}var t=!1;try{var r={};r[ju]=function(){return{next:function(){return{done:t=!0}}}},a(r)}catch{}return t},Id=Ir,Nd=Rd,Md=Mt.CONSTRUCTOR,zu=Md||!Nd(function(a){Id.all(a).then(void 0,function(){})}),_d=ee,Dd=Y,Vd=Se,Ld=vt,kd=Bi,Bd=Fu,Fd=zu;_d({target:"Promise",stat:!0,forced:Fd},{all:function(e){var t=this,r=Ld.f(t),i=r.resolve,n=r.reject,o=kd(function(){var s=Vd(t.resolve),u=[],l=0,h=1;Bd(e,function(f){var c=l++,v=!1;h++,Dd(s,t,f).then(function(d){v||(v=!0,u[c]=d,--h||i(u))},n)}),--h||i(u)});return o.error&&n(o.value),r.promise}});var jd=ee,Ud=Mt.CONSTRUCTOR,si=Ir,zd=Ue,Gd=D,Hd=ze,ms=si&&si.prototype;jd({target:"Promise",proto:!0,forced:Ud,real:!0},{catch:function(a){return this.then(void 0,a)}});if(Gd(si)){var bs=zd("Promise").prototype.catch;ms.catch!==bs&&Hd(ms,"catch",bs,{unsafe:!0})}var Yd=ee,Xd=Y,Wd=Se,qd=vt,Qd=Bi,Kd=Fu,Zd=zu;Yd({target:"Promise",stat:!0,forced:Zd},{race:function(e){var t=this,r=qd.f(t),i=r.reject,n=Qd(function(){var o=Wd(t.resolve);Kd(e,function(s){Xd(o,t,s).then(r.resolve,i)})});return n.error&&i(n.value),r.promise}});var Jd=ee,ep=Y,tp=vt,rp=Mt.CONSTRUCTOR;Jd({target:"Promise",stat:!0,forced:rp},{reject:function(e){var t=tp.f(this);return ep(t.reject,void 0,e),t.promise}});var ap=K,ip=Te,np=vt,sp=function(a,e){if(ap(a),ip(e)&&e.constructor===a)return e;var t=np.f(a),r=t.resolve;return r(e),t.promise},op=ee,up=Ue,lp=Mt.CONSTRUCTOR,hp=sp;up("Promise");op({target:"Promise",stat:!0,forced:lp},{resolve:function(e){return hp(this,e)}});function xs(a,e,t,r,i,n,o){try{var s=a[n](o),u=s.value}catch(l){t(l);return}s.done?e(u):Promise.resolve(u).then(r,i)}function xe(a){return function(){var e=this,t=arguments;return new Promise(function(r,i){var n=a.apply(e,t);function o(u){xs(n,r,i,o,s,"next",u)}function s(u){xs(n,r,i,o,s,"throw",u)}o(void 0)})}}var vp=_i,fp=String,pe=function(a){if(vp(a)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return fp(a)},cp=K,Gu=function(){var a=cp(this),e="";return a.hasIndices&&(e+="d"),a.global&&(e+="g"),a.ignoreCase&&(e+="i"),a.multiline&&(e+="m"),a.dotAll&&(e+="s"),a.unicode&&(e+="u"),a.unicodeSets&&(e+="v"),a.sticky&&(e+="y"),e},Gi=L,gp=U,Hi=gp.RegExp,Yi=Gi(function(){var a=Hi("a","y");return a.lastIndex=2,a.exec("abcd")!==null}),dp=Yi||Gi(function(){return!Hi("a","y").sticky}),pp=Yi||Gi(function(){var a=Hi("^r","gy");return a.lastIndex=2,a.exec("str")!==null}),Hu={BROKEN_CARET:pp,MISSED_STICKY:dp,UNSUPPORTED_Y:Yi},Yu={},yp=uu,mp=Mi,bp=Object.keys||function(e){return yp(e,mp)},xp=ce,Tp=Jo,Sp=de,Op=K,Ep=At,$p=bp;Yu.f=xp&&!Tp?Object.defineProperties:function(e,t){Op(e);for(var r=Ep(t),i=$p(t),n=i.length,o=0,s;n>o;)Sp.f(e,s=i[o++],r[s]);return e};var wp=K,Cp=Yu,Ts=Mi,Ap=Ii,Pp=bu,Rp=$r,Ip=Ri,Ss=">",Os="<",oi="prototype",ui="script",Xu=Ip("IE_PROTO"),$a=function(){},Wu=function(a){return Os+ui+Ss+a+Os+"/"+ui+Ss},Es=function(a){a.write(Wu("")),a.close();var e=a.parentWindow.Object;return a=null,e},Np=function(){var a=Rp("iframe"),e="java"+ui+":",t;return a.style.display="none",Pp.appendChild(a),a.src=String(e),t=a.contentWindow.document,t.open(),t.write(Wu("document.F=Object")),t.close(),t.F},er,vr=function(){try{er=new ActiveXObject("htmlfile")}catch{}vr=typeof document<"u"?document.domain&&er?Es(er):Np():Es(er);for(var a=Ts.length;a--;)delete vr[oi][Ts[a]];return vr()};Ap[Xu]=!0;var Xi=Object.create||function(e,t){var r;return e!==null?($a[oi]=wp(e),r=new $a,$a[oi]=null,r[Xu]=e):r=vr(),t===void 0?r:Cp.f(r,t)},Mp=L,_p=U,Dp=_p.RegExp,Vp=Mp(function(){var a=Dp(".","s");return!(a.dotAll&&a.test(` +import{c as Je,g as Do}from"./main-316b396b.js";import{_ as Ha}from"./jspdf.es.min-5cd5e647.js";var ct=function(a){return a&&a.Math===Math&&a},U=ct(typeof globalThis=="object"&&globalThis)||ct(typeof window=="object"&&window)||ct(typeof self=="object"&&self)||ct(typeof Je=="object"&&Je)||ct(typeof Je=="object"&&Je)||function(){return this}()||Function("return this")(),ut={},L=function(a){try{return!!a()}catch{return!0}},Rl=L,ce=!Rl(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),Il=L,br=!Il(function(){var a=(function(){}).bind();return typeof a!="function"||a.hasOwnProperty("prototype")}),Nl=br,Ht=Function.prototype.call,Y=Nl?Ht.bind(Ht):function(){return Ht.apply(Ht,arguments)},Vo={},Lo={}.propertyIsEnumerable,ko=Object.getOwnPropertyDescriptor,Ml=ko&&!Lo.call({1:2},1);Vo.f=Ml?function(e){var t=ko(this,e);return!!t&&t.enumerable}:Lo;var xr=function(a,e){return{enumerable:!(a&1),configurable:!(a&2),writable:!(a&4),value:e}},Bo=br,Fo=Function.prototype,Ya=Fo.call,_l=Bo&&Fo.bind.bind(Ya,Ya),k=Bo?_l:function(a){return function(){return Ya.apply(a,arguments)}},jo=k,Dl=jo({}.toString),Vl=jo("".slice),Fe=function(a){return Vl(Dl(a),8,-1)},Ll=k,kl=L,Bl=Fe,Jr=Object,Fl=Ll("".split),Uo=kl(function(){return!Jr("z").propertyIsEnumerable(0)})?function(a){return Bl(a)==="String"?Fl(a,""):Jr(a)}:Jr,je=function(a){return a==null},jl=je,Ul=TypeError,ge=function(a){if(jl(a))throw new Ul("Can't call method on "+a);return a},zl=Uo,Gl=ge,At=function(a){return zl(Gl(a))},Xa=typeof document=="object"&&document.all,Hl=typeof Xa>"u"&&Xa!==void 0,zo={all:Xa,IS_HTMLDDA:Hl},Go=zo,Yl=Go.all,D=Go.IS_HTMLDDA?function(a){return typeof a=="function"||a===Yl}:function(a){return typeof a=="function"},yn=D,Ho=zo,Xl=Ho.all,Te=Ho.IS_HTMLDDA?function(a){return typeof a=="object"?a!==null:yn(a)||a===Xl}:function(a){return typeof a=="object"?a!==null:yn(a)},ea=U,Wl=D,ql=function(a){return Wl(a)?a:void 0},Ue=function(a,e){return arguments.length<2?ql(ea[a]):ea[a]&&ea[a][e]},Ql=k,Tr=Ql({}.isPrototypeOf),Sr=typeof navigator<"u"&&String(navigator.userAgent)||"",Yo=U,ta=Sr,mn=Yo.process,bn=Yo.Deno,xn=mn&&mn.versions||bn&&bn.version,Tn=xn&&xn.v8,ue,cr;Tn&&(ue=Tn.split("."),cr=ue[0]>0&&ue[0]<4?1:+(ue[0]+ue[1]));!cr&&ta&&(ue=ta.match(/Edge\/(\d+)/),(!ue||ue[1]>=74)&&(ue=ta.match(/Chrome\/(\d+)/),ue&&(cr=+ue[1])));var Oi=cr,Sn=Oi,Kl=L,Zl=U,Jl=Zl.String,Xo=!!Object.getOwnPropertySymbols&&!Kl(function(){var a=Symbol("symbol detection");return!Jl(a)||!(Object(a)instanceof Symbol)||!Symbol.sham&&Sn&&Sn<41}),eh=Xo,Wo=eh&&!Symbol.sham&&typeof Symbol.iterator=="symbol",th=Ue,rh=D,ah=Tr,ih=Wo,nh=Object,qo=ih?function(a){return typeof a=="symbol"}:function(a){var e=th("Symbol");return rh(e)&&ah(e.prototype,nh(a))},sh=String,Or=function(a){try{return sh(a)}catch{return"Object"}},oh=D,uh=Or,lh=TypeError,Se=function(a){if(oh(a))return a;throw new lh(uh(a)+" is not a function")},hh=Se,vh=je,lt=function(a,e){var t=a[e];return vh(t)?void 0:hh(t)},ra=Y,aa=D,ia=Te,fh=TypeError,ch=function(a,e){var t,r;if(e==="string"&&aa(t=a.toString)&&!ia(r=ra(t,a))||aa(t=a.valueOf)&&!ia(r=ra(t,a))||e!=="string"&&aa(t=a.toString)&&!ia(r=ra(t,a)))return r;throw new fh("Can't convert object to primitive value")},Qo={exports:{}},On=U,gh=Object.defineProperty,Ei=function(a,e){try{gh(On,a,{value:e,configurable:!0,writable:!0})}catch{On[a]=e}return e},dh=U,ph=Ei,En="__core-js_shared__",yh=dh[En]||ph(En,{}),$i=yh,$n=$i;(Qo.exports=function(a,e){return $n[a]||($n[a]=e!==void 0?e:{})})("versions",[]).push({version:"3.34.0",mode:"global",copyright:"© 2014-2023 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.34.0/LICENSE",source:"https://github.com/zloirock/core-js"});var wi=Qo.exports,mh=ge,bh=Object,Er=function(a){return bh(mh(a))},xh=k,Th=Er,Sh=xh({}.hasOwnProperty),le=Object.hasOwn||function(e,t){return Sh(Th(e),t)},Oh=k,Eh=0,$h=Math.random(),wh=Oh(1 .toString),Ko=function(a){return"Symbol("+(a===void 0?"":a)+")_"+wh(++Eh+$h,36)},Ch=U,Ah=wi,wn=le,Ph=Ko,Rh=Xo,Ih=Wo,et=Ch.Symbol,na=Ah("wks"),Nh=Ih?et.for||et:et&&et.withoutSetter||Ph,G=function(a){return wn(na,a)||(na[a]=Rh&&wn(et,a)?et[a]:Nh("Symbol."+a)),na[a]},Mh=Y,Cn=Te,An=qo,_h=lt,Dh=ch,Vh=G,Lh=TypeError,kh=Vh("toPrimitive"),Bh=function(a,e){if(!Cn(a)||An(a))return a;var t=_h(a,kh),r;if(t){if(e===void 0&&(e="default"),r=Mh(t,a,e),!Cn(r)||An(r))return r;throw new Lh("Can't convert object to primitive value")}return e===void 0&&(e="number"),Dh(a,e)},Fh=Bh,jh=qo,Ci=function(a){var e=Fh(a,"string");return jh(e)?e:e+""},Uh=U,Pn=Te,Wa=Uh.document,zh=Pn(Wa)&&Pn(Wa.createElement),$r=function(a){return zh?Wa.createElement(a):{}},Gh=ce,Hh=L,Yh=$r,Zo=!Gh&&!Hh(function(){return Object.defineProperty(Yh("div"),"a",{get:function(){return 7}}).a!==7}),Xh=ce,Wh=Y,qh=Vo,Qh=xr,Kh=At,Zh=Ci,Jh=le,ev=Zo,Rn=Object.getOwnPropertyDescriptor;ut.f=Xh?Rn:function(e,t){if(e=Kh(e),t=Zh(t),ev)try{return Rn(e,t)}catch{}if(Jh(e,t))return Qh(!Wh(qh.f,e,t),e[t])};var de={},tv=ce,rv=L,Jo=tv&&rv(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),av=Te,iv=String,nv=TypeError,K=function(a){if(av(a))return a;throw new nv(iv(a)+" is not an object")},sv=ce,ov=Zo,uv=Jo,Yt=K,In=Ci,lv=TypeError,sa=Object.defineProperty,hv=Object.getOwnPropertyDescriptor,oa="enumerable",ua="configurable",la="writable";de.f=sv?uv?function(e,t,r){if(Yt(e),t=In(t),Yt(r),typeof e=="function"&&t==="prototype"&&"value"in r&&la in r&&!r[la]){var i=hv(e,t);i&&i[la]&&(e[t]=r.value,r={configurable:ua in r?r[ua]:i[ua],enumerable:oa in r?r[oa]:i[oa],writable:!1})}return sa(e,t,r)}:sa:function(e,t,r){if(Yt(e),t=In(t),Yt(r),ov)try{return sa(e,t,r)}catch{}if("get"in r||"set"in r)throw new lv("Accessors not supported");return"value"in r&&(e[t]=r.value),e};var vv=ce,fv=de,cv=xr,Pt=vv?function(a,e,t){return fv.f(a,e,cv(1,t))}:function(a,e,t){return a[e]=t,a},eu={exports:{}},qa=ce,gv=le,tu=Function.prototype,dv=qa&&Object.getOwnPropertyDescriptor,Ai=gv(tu,"name"),pv=Ai&&(function(){}).name==="something",yv=Ai&&(!qa||qa&&dv(tu,"name").configurable),wr={EXISTS:Ai,PROPER:pv,CONFIGURABLE:yv},mv=k,bv=D,Qa=$i,xv=mv(Function.toString);bv(Qa.inspectSource)||(Qa.inspectSource=function(a){return xv(a)});var Pi=Qa.inspectSource,Tv=U,Sv=D,Nn=Tv.WeakMap,Ov=Sv(Nn)&&/native code/.test(String(Nn)),Ev=wi,$v=Ko,Mn=Ev("keys"),Ri=function(a){return Mn[a]||(Mn[a]=$v(a))},Ii={},wv=Ov,ru=U,Cv=Te,Av=Pt,ha=le,va=$i,Pv=Ri,Rv=Ii,_n="Object already initialized",Ka=ru.TypeError,Iv=ru.WeakMap,gr,$t,dr,Nv=function(a){return dr(a)?$t(a):gr(a,{})},Mv=function(a){return function(e){var t;if(!Cv(e)||(t=$t(e)).type!==a)throw new Ka("Incompatible receiver, "+a+" required");return t}};if(wv||va.state){var fe=va.state||(va.state=new Iv);fe.get=fe.get,fe.has=fe.has,fe.set=fe.set,gr=function(a,e){if(fe.has(a))throw new Ka(_n);return e.facade=a,fe.set(a,e),e},$t=function(a){return fe.get(a)||{}},dr=function(a){return fe.has(a)}}else{var Xe=Pv("state");Rv[Xe]=!0,gr=function(a,e){if(ha(a,Xe))throw new Ka(_n);return e.facade=a,Av(a,Xe,e),e},$t=function(a){return ha(a,Xe)?a[Xe]:{}},dr=function(a){return ha(a,Xe)}}var Cr={set:gr,get:$t,has:dr,enforce:Nv,getterFor:Mv},Ni=k,_v=L,Dv=D,Xt=le,Za=ce,Vv=wr.CONFIGURABLE,Lv=Pi,au=Cr,kv=au.enforce,Bv=au.get,Dn=String,or=Object.defineProperty,Fv=Ni("".slice),jv=Ni("".replace),Uv=Ni([].join),zv=Za&&!_v(function(){return or(function(){},"length",{value:8}).length!==8}),Gv=String(String).split("String"),Hv=eu.exports=function(a,e,t){Fv(Dn(e),0,7)==="Symbol("&&(e="["+jv(Dn(e),/^Symbol\(([^)]*)\)/,"$1")+"]"),t&&t.getter&&(e="get "+e),t&&t.setter&&(e="set "+e),(!Xt(a,"name")||Vv&&a.name!==e)&&(Za?or(a,"name",{value:e,configurable:!0}):a.name=e),zv&&t&&Xt(t,"arity")&&a.length!==t.arity&&or(a,"length",{value:t.arity});try{t&&Xt(t,"constructor")&&t.constructor?Za&&or(a,"prototype",{writable:!1}):a.prototype&&(a.prototype=void 0)}catch{}var r=kv(a);return Xt(r,"source")||(r.source=Uv(Gv,typeof e=="string"?e:"")),a};Function.prototype.toString=Hv(function(){return Dv(this)&&Bv(this).source||Lv(this)},"toString");var iu=eu.exports,Yv=D,Xv=de,Wv=iu,qv=Ei,ze=function(a,e,t,r){r||(r={});var i=r.enumerable,n=r.name!==void 0?r.name:e;if(Yv(t)&&Wv(t,n,r),r.global)i?a[e]=t:qv(e,t);else{try{r.unsafe?a[e]&&(i=!0):delete a[e]}catch{}i?a[e]=t:Xv.f(a,e,{value:t,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return a},nu={},Qv=Math.ceil,Kv=Math.floor,Zv=Math.trunc||function(e){var t=+e;return(t>0?Kv:Qv)(t)},Jv=Zv,Ar=function(a){var e=+a;return e!==e||e===0?0:Jv(e)},ef=Ar,tf=Math.max,rf=Math.min,su=function(a,e){var t=ef(a);return t<0?tf(t+e,0):rf(t,e)},af=Ar,nf=Math.min,ht=function(a){return a>0?nf(af(a),9007199254740991):0},sf=ht,Pr=function(a){return sf(a.length)},of=At,uf=su,lf=Pr,Vn=function(a){return function(e,t,r){var i=of(e),n=lf(i),o=uf(r,n),s;if(a&&t!==t){for(;n>o;)if(s=i[o++],s!==s)return!0}else for(;n>o;o++)if((a||o in i)&&i[o]===t)return a||o||0;return!a&&-1}},ou={includes:Vn(!0),indexOf:Vn(!1)},hf=k,fa=le,vf=At,ff=ou.indexOf,cf=Ii,Ln=hf([].push),uu=function(a,e){var t=vf(a),r=0,i=[],n;for(n in t)!fa(cf,n)&&fa(t,n)&&Ln(i,n);for(;e.length>r;)fa(t,n=e[r++])&&(~ff(i,n)||Ln(i,n));return i},Mi=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],gf=uu,df=Mi,pf=df.concat("length","prototype");nu.f=Object.getOwnPropertyNames||function(e){return gf(e,pf)};var lu={};lu.f=Object.getOwnPropertySymbols;var yf=Ue,mf=k,bf=nu,xf=lu,Tf=K,Sf=mf([].concat),Of=yf("Reflect","ownKeys")||function(e){var t=bf.f(Tf(e)),r=xf.f;return r?Sf(t,r(e)):t},kn=le,Ef=Of,$f=ut,wf=de,Cf=function(a,e,t){for(var r=Ef(e),i=wf.f,n=$f.f,o=0;of;f++)if(v=y(a[f]),v&&gs(ps,v))return v;return new hr(!1)}l=$d(a,h)}for(d=n?a.next:l.next;!(g=xd(d,l)).done;){try{v=y(g.value)}catch(x){ds(l,"throw",x)}if(typeof v=="object"&&v&&gs(ps,v))return v}return new hr(!1)},Ad=G,ju=Ad("iterator"),Uu=!1;try{var Pd=0,ys={next:function(){return{done:!!Pd++}},return:function(){Uu=!0}};ys[ju]=function(){return this},Array.from(ys,function(){throw 2})}catch{}var Rd=function(a,e){try{if(!e&&!Uu)return!1}catch{return!1}var t=!1;try{var r={};r[ju]=function(){return{next:function(){return{done:t=!0}}}},a(r)}catch{}return t},Id=Ir,Nd=Rd,Md=Mt.CONSTRUCTOR,zu=Md||!Nd(function(a){Id.all(a).then(void 0,function(){})}),_d=ee,Dd=Y,Vd=Se,Ld=vt,kd=Bi,Bd=Fu,Fd=zu;_d({target:"Promise",stat:!0,forced:Fd},{all:function(e){var t=this,r=Ld.f(t),i=r.resolve,n=r.reject,o=kd(function(){var s=Vd(t.resolve),u=[],l=0,h=1;Bd(e,function(f){var c=l++,v=!1;h++,Dd(s,t,f).then(function(d){v||(v=!0,u[c]=d,--h||i(u))},n)}),--h||i(u)});return o.error&&n(o.value),r.promise}});var jd=ee,Ud=Mt.CONSTRUCTOR,si=Ir,zd=Ue,Gd=D,Hd=ze,ms=si&&si.prototype;jd({target:"Promise",proto:!0,forced:Ud,real:!0},{catch:function(a){return this.then(void 0,a)}});if(Gd(si)){var bs=zd("Promise").prototype.catch;ms.catch!==bs&&Hd(ms,"catch",bs,{unsafe:!0})}var Yd=ee,Xd=Y,Wd=Se,qd=vt,Qd=Bi,Kd=Fu,Zd=zu;Yd({target:"Promise",stat:!0,forced:Zd},{race:function(e){var t=this,r=qd.f(t),i=r.reject,n=Qd(function(){var o=Wd(t.resolve);Kd(e,function(s){Xd(o,t,s).then(r.resolve,i)})});return n.error&&i(n.value),r.promise}});var Jd=ee,ep=Y,tp=vt,rp=Mt.CONSTRUCTOR;Jd({target:"Promise",stat:!0,forced:rp},{reject:function(e){var t=tp.f(this);return ep(t.reject,void 0,e),t.promise}});var ap=K,ip=Te,np=vt,sp=function(a,e){if(ap(a),ip(e)&&e.constructor===a)return e;var t=np.f(a),r=t.resolve;return r(e),t.promise},op=ee,up=Ue,lp=Mt.CONSTRUCTOR,hp=sp;up("Promise");op({target:"Promise",stat:!0,forced:lp},{resolve:function(e){return hp(this,e)}});function xs(a,e,t,r,i,n,o){try{var s=a[n](o),u=s.value}catch(l){t(l);return}s.done?e(u):Promise.resolve(u).then(r,i)}function xe(a){return function(){var e=this,t=arguments;return new Promise(function(r,i){var n=a.apply(e,t);function o(u){xs(n,r,i,o,s,"next",u)}function s(u){xs(n,r,i,o,s,"throw",u)}o(void 0)})}}var vp=_i,fp=String,pe=function(a){if(vp(a)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return fp(a)},cp=K,Gu=function(){var a=cp(this),e="";return a.hasIndices&&(e+="d"),a.global&&(e+="g"),a.ignoreCase&&(e+="i"),a.multiline&&(e+="m"),a.dotAll&&(e+="s"),a.unicode&&(e+="u"),a.unicodeSets&&(e+="v"),a.sticky&&(e+="y"),e},Gi=L,gp=U,Hi=gp.RegExp,Yi=Gi(function(){var a=Hi("a","y");return a.lastIndex=2,a.exec("abcd")!==null}),dp=Yi||Gi(function(){return!Hi("a","y").sticky}),pp=Yi||Gi(function(){var a=Hi("^r","gy");return a.lastIndex=2,a.exec("str")!==null}),Hu={BROKEN_CARET:pp,MISSED_STICKY:dp,UNSUPPORTED_Y:Yi},Yu={},yp=uu,mp=Mi,bp=Object.keys||function(e){return yp(e,mp)},xp=ce,Tp=Jo,Sp=de,Op=K,Ep=At,$p=bp;Yu.f=xp&&!Tp?Object.defineProperties:function(e,t){Op(e);for(var r=Ep(t),i=$p(t),n=i.length,o=0,s;n>o;)Sp.f(e,s=i[o++],r[s]);return e};var wp=K,Cp=Yu,Ts=Mi,Ap=Ii,Pp=bu,Rp=$r,Ip=Ri,Ss=">",Os="<",oi="prototype",ui="script",Xu=Ip("IE_PROTO"),$a=function(){},Wu=function(a){return Os+ui+Ss+a+Os+"/"+ui+Ss},Es=function(a){a.write(Wu("")),a.close();var e=a.parentWindow.Object;return a=null,e},Np=function(){var a=Rp("iframe"),e="java"+ui+":",t;return a.style.display="none",Pp.appendChild(a),a.src=String(e),t=a.contentWindow.document,t.open(),t.write(Wu("document.F=Object")),t.close(),t.F},er,vr=function(){try{er=new ActiveXObject("htmlfile")}catch{}vr=typeof document<"u"?document.domain&&er?Es(er):Np():Es(er);for(var a=Ts.length;a--;)delete vr[oi][Ts[a]];return vr()};Ap[Xu]=!0;var Xi=Object.create||function(e,t){var r;return e!==null?($a[oi]=wp(e),r=new $a,$a[oi]=null,r[Xu]=e):r=vr(),t===void 0?r:Cp.f(r,t)},Mp=L,_p=U,Dp=_p.RegExp,Vp=Mp(function(){var a=Dp(".","s");return!(a.dotAll&&a.test(` `)&&a.flags==="s")}),Lp=L,kp=U,Bp=kp.RegExp,Fp=Lp(function(){var a=Bp("(?b)","g");return a.exec("b").groups.a!=="b"||"b".replace(a,"$c")!=="bc"}),rt=Y,Mr=k,jp=pe,Up=Gu,zp=Hu,Gp=wi,Hp=Xi,Yp=Cr.get,Xp=Vp,Wp=Fp,qp=Gp("native-string-replace",String.prototype.replace),mr=RegExp.prototype.exec,li=mr,Qp=Mr("".charAt),Kp=Mr("".indexOf),Zp=Mr("".replace),wa=Mr("".slice),hi=function(){var a=/a/,e=/b*/g;return rt(mr,a,"a"),rt(mr,e,"a"),a.lastIndex!==0||e.lastIndex!==0}(),qu=zp.BROKEN_CARET,vi=/()??/.exec("")[1]!==void 0,Jp=hi||vi||qu||Xp||Wp;Jp&&(li=function(e){var t=this,r=Yp(t),i=jp(e),n=r.raw,o,s,u,l,h,f,c;if(n)return n.lastIndex=t.lastIndex,o=rt(li,n,i),t.lastIndex=n.lastIndex,o;var v=r.groups,d=qu&&t.sticky,g=rt(Up,t),p=t.source,y=0,x=i;if(d&&(g=Zp(g,"y",""),Kp(g,"g")===-1&&(g+="g"),x=wa(i,t.lastIndex),t.lastIndex>0&&(!t.multiline||t.multiline&&Qp(i,t.lastIndex-1)!==` `)&&(p="(?: "+p+")",x=" "+x,y++),s=new RegExp("^(?:"+p+")",g)),vi&&(s=new RegExp("^"+p+"$(?!\\s)",g)),hi&&(u=t.lastIndex),l=rt(mr,d?s:t,x),d?l?(l.input=wa(l.input,y),l[0]=wa(l[0],y),l.index=t.lastIndex,t.lastIndex+=l[0].length):t.lastIndex=0:hi&&l&&(t.lastIndex=t.global?l.index+l[0].length:u),vi&&l&&l.length>1&&rt(qp,l[0],s,function(){for(h=1;h=n?a?"":void 0:(o=Ps(r,i),o<55296||o>56319||i+1===n||(s=Ps(r,i+1))<56320||s>57343?a?oy(r,i):o:a?uy(r,i,i+2):(o-55296<<10)+(s-56320)+65536)}},ly={codeAt:Rs(!1),charAt:Rs(!0)},hy=ly.charAt,Qi=function(a,e,t){return e+(t?hy(a,e).length:1)},Is=Y,vy=K,fy=D,cy=Fe,gy=_r,dy=TypeError,Ki=function(a,e){var t=a.exec;if(fy(t)){var r=Is(t,a,e);return r!==null&&vy(r),r}if(cy(a)==="RegExp")return Is(gy,a,e);throw new dy("RegExp#exec called on incompatible receiver")},py=Y,yy=Wi,my=K,by=je,xy=ht,Aa=pe,Ty=ge,Sy=lt,Oy=Qi,Ns=Ki;yy("match",function(a,e,t){return[function(i){var n=Ty(this),o=by(i)?void 0:Sy(i,a);return o?py(o,i,n):new RegExp(i)[a](Aa(n))},function(r){var i=my(this),n=Aa(r),o=t(e,i,n);if(o.done)return o.value;if(!i.global)return Ns(i,n);var s=i.unicode;i.lastIndex=0;for(var u=[],l=0,h;(h=Ns(i,n))!==null;){var f=Aa(h[0]);u[l]=f,f===""&&(i.lastIndex=Oy(n,xy(i.lastIndex),s)),l++}return l===0?null:u}]});var Zi=k,Ey=Er,$y=Math.floor,Pa=Zi("".charAt),wy=Zi("".replace),Ra=Zi("".slice),Cy=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,Ay=/\$([$&'`]|\d{1,2})/g,Py=function(a,e,t,r,i,n){var o=t+a.length,s=r.length,u=Ay;return i!==void 0&&(i=Ey(i),u=Cy),wy(n,u,function(l,h){var f;switch(Pa(h,0)){case"$":return"$";case"&":return a;case"`":return Ra(e,0,t);case"'":return Ra(e,o);case"<":f=i[Ra(h,1,-1)];break;default:var c=+h;if(c===0)return l;if(c>s){var v=$y(c/10);return v===0?l:v<=s?r[v-1]===void 0?Pa(h,1):r[v-1]+Pa(h,1):l}f=r[c-1]}return f===void 0?"":f})},Ry=Vi,Ms=Y,Dr=k,Iy=Wi,Ny=L,My=K,_y=D,Dy=je,Vy=Ar,Ly=ht,qe=pe,ky=ge,By=Qi,Fy=lt,jy=Py,Uy=Ki,zy=G,fi=zy("replace"),Gy=Math.max,Hy=Math.min,Yy=Dr([].concat),Ia=Dr([].push),_s=Dr("".indexOf),Ds=Dr("".slice),Xy=function(a){return a===void 0?a:String(a)},Wy=function(){return"a".replace(/./,"$0")==="$0"}(),Vs=function(){return/./[fi]?/./[fi]("a","$0")==="":!1}(),qy=!Ny(function(){var a=/./;return a.exec=function(){var e=[];return e.groups={a:"7"},e},"".replace(a,"$")!=="7"});Iy("replace",function(a,e,t){var r=Vs?"$":"$0";return[function(n,o){var s=ky(this),u=Dy(n)?void 0:Fy(n,fi);return u?Ms(u,n,s,o):Ms(e,qe(s),n,o)},function(i,n){var o=My(this),s=qe(i);if(typeof n=="string"&&_s(n,r)===-1&&_s(n,"$<")===-1){var u=t(e,o,s,n);if(u.done)return u.value}var l=_y(n);l||(n=qe(n));var h=o.global,f;h&&(f=o.unicode,o.lastIndex=0);for(var c=[],v;v=Uy(o,s),!(v===null||(Ia(c,v),!h));){var d=qe(v[0]);d===""&&(o.lastIndex=By(s,Ly(o.lastIndex),f))}for(var g="",p=0,y=0;y=p&&(g+=Ds(s,p,b)+$,p=b+x.length)}return g+Ds(s,p)}]},!qy||!Wy||Vs);var Qy=Te,Ky=Fe,Zy=G,Jy=Zy("match"),Ku=function(a){var e;return Qy(a)&&((e=a[Jy])!==void 0?!!e:Ky(a)==="RegExp")},em=Ku,tm=TypeError,Ji=function(a){if(em(a))throw new tm("The method doesn't accept regular expressions");return a},rm=G,am=rm("match"),en=function(a){var e=/./;try{"/./"[a](e)}catch{try{return e[am]=!1,"/./"[a](e)}catch{}}return!1},im=ee,Zu=Nt,nm=ut.f,sm=ht,Ls=pe,om=Ji,um=ge,lm=en,ks=Zu("".startsWith),hm=Zu("".slice),vm=Math.min,Ju=lm("startsWith"),fm=!Ju&&!!function(){var a=nm(String.prototype,"startsWith");return a&&!a.writable}();im({target:"String",proto:!0,forced:!fm&&!Ju},{startsWith:function(e){var t=Ls(um(this));om(e);var r=sm(vm(arguments.length>1?arguments[1]:void 0,t.length)),i=Ls(e);return ks?ks(t,i,r):hm(t,r,r+i.length)===i}});var cm=G,gm=Xi,dm=de.f,ci=cm("unscopables"),gi=Array.prototype;gi[ci]===void 0&&dm(gi,ci,{configurable:!0,value:gm(null)});var pm=function(a){gi[ci][a]=!0},ym=L,mm=!ym(function(){function a(){}return a.prototype.constructor=null,Object.getPrototypeOf(new a)!==a.prototype}),bm=le,xm=D,Tm=Er,Sm=Ri,Om=mm,Bs=Sm("IE_PROTO"),di=Object,Em=di.prototype,el=Om?di.getPrototypeOf:function(a){var e=Tm(a);if(bm(e,Bs))return e[Bs];var t=e.constructor;return xm(t)&&e instanceof t?t.prototype:e instanceof di?Em:null},$m=L,wm=D,Cm=Te,Fs=el,Am=ze,Pm=G,pi=Pm("iterator"),tl=!1,ke,Na,Ma;[].keys&&(Ma=[].keys(),"next"in Ma?(Na=Fs(Fs(Ma)),Na!==Object.prototype&&(ke=Na)):tl=!0);var Rm=!Cm(ke)||$m(function(){var a={};return ke[pi].call(a)!==a});Rm&&(ke={});wm(ke[pi])||Am(ke,pi,function(){return this});var rl={IteratorPrototype:ke,BUGGY_SAFARI_ITERATORS:tl},Im=rl.IteratorPrototype,Nm=Xi,Mm=xr,_m=Rr,Dm=_t,Vm=function(){return this},Lm=function(a,e,t,r){var i=e+" Iterator";return a.prototype=Nm(Im,{next:Mm(+!r,t)}),_m(a,i,!1),Dm[i]=Vm,a},km=ee,Bm=Y,al=wr,Fm=D,jm=Lm,js=el,Us=vu,Um=Rr,zm=Pt,_a=ze,Gm=G,Hm=_t,il=rl,Ym=al.PROPER,Xm=al.CONFIGURABLE,zs=il.IteratorPrototype,tr=il.BUGGY_SAFARI_ITERATORS,dt=Gm("iterator"),Gs="keys",pt="values",Hs="entries",Wm=function(){return this},qm=function(a,e,t,r,i,n,o){jm(t,e,r);var s=function(y){if(y===i&&c)return c;if(!tr&&y&&y in h)return h[y];switch(y){case Gs:return function(){return new t(this,y)};case pt:return function(){return new t(this,y)};case Hs:return function(){return new t(this,y)}}return function(){return new t(this)}},u=e+" Iterator",l=!1,h=a.prototype,f=h[dt]||h["@@iterator"]||i&&h[i],c=!tr&&f||s(i),v=e==="Array"&&h.entries||f,d,g,p;if(v&&(d=js(v.call(new a)),d!==Object.prototype&&d.next&&(js(d)!==zs&&(Us?Us(d,zs):Fm(d[dt])||_a(d,dt,Wm)),Um(d,u,!0))),Ym&&i===pt&&f&&f.name!==pt&&(Xm?zm(h,"name",pt):(l=!0,c=function(){return Bm(f,this)})),i)if(g={values:s(pt),keys:n?c:s(Gs),entries:s(Hs)},o)for(p in g)(tr||l||!(p in h))&&_a(h,p,g[p]);else km({target:e,proto:!0,forced:tr||l},g);return h[dt]!==c&&_a(h,dt,c,{name:i}),Hm[e]=c,g},Qm=function(a,e){return{value:a,done:e}},Km=At,tn=pm,Ys=_t,nl=Cr,Zm=de.f,Jm=qm,rr=Qm,e0=ce,sl="Array Iterator",t0=nl.set,r0=nl.getterFor(sl),a0=Jm(Array,"Array",function(a,e){t0(this,{type:sl,target:Km(a),index:0,kind:e})},function(){var a=r0(this),e=a.target,t=a.index++;if(!e||t>=e.length)return a.target=void 0,rr(void 0,!0);switch(a.kind){case"keys":return rr(t,!1);case"values":return rr(e[t],!1)}return rr([t,e[t]],!1)},"values"),Xs=Ys.Arguments=Ys.Array;tn("keys");tn("values");tn("entries");if(e0&&Xs.name!=="values")try{Zm(Xs,"name",{value:"values"})}catch{}var i0={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0},n0=$r,Da=n0("span").classList,Ws=Da&&Da.constructor&&Da.constructor.prototype,s0=Ws===Object.prototype?void 0:Ws,qs=U,ol=i0,o0=s0,xt=a0,Qs=Pt,u0=Rr,l0=G,Va=l0("iterator"),La=xt.values,ul=function(a,e){if(a){if(a[Va]!==La)try{Qs(a,Va,La)}catch{a[Va]=La}if(u0(a,e,!0),ol[e]){for(var t in xt)if(a[t]!==xt[t])try{Qs(a,t,xt[t])}catch{a[t]=xt[t]}}}};for(var ka in ol)ul(qs[ka]&&qs[ka].prototype,ka);ul(o0,"DOMTokenList");function h0(a,e){if(Ha(a)!=="object"||a===null)return a;var t=a[Symbol.toPrimitive];if(t!==void 0){var r=t.call(a,e||"default");if(Ha(r)!=="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(a)}function v0(a){var e=h0(a,"string");return Ha(e)==="symbol"?e:String(e)}function rn(a,e,t){return e=v0(e),e in a?Object.defineProperty(a,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):a[e]=t,a}var f0=Se,c0=Er,g0=Uo,d0=Pr,p0=TypeError,Ks=function(a){return function(e,t,r,i){var n=c0(e),o=g0(n),s=d0(n);f0(t);var u=a?s-1:0,l=a?-1:1;if(r<2)for(;;){if(u in o){i=o[u],u+=l;break}if(u+=l,a?u<0:s<=u)throw new p0("Reduce of empty array with no initial value")}for(;a?u>=0:s>u;u+=l)u in o&&(i=t(i,o[u],u,n));return i}},y0={left:Ks(!1),right:Ks(!0)},m0=L,ll=function(a,e){var t=[][a];return!!t&&m0(function(){t.call(null,e||function(){return 1},1)})},b0=ee,x0=y0.left,T0=ll,Zs=Oi,S0=It,O0=!S0&&Zs>79&&Zs<83,E0=O0||!T0("reduce");b0({target:"Array",proto:!0,forced:E0},{reduce:function(e){var t=arguments.length;return x0(this,e,t,t>1?arguments[1]:void 0)}});var $0=ee,hl=Nt,w0=ut.f,C0=ht,Js=pe,A0=Ji,P0=ge,R0=en,eo=hl("".endsWith),I0=hl("".slice),N0=Math.min,vl=R0("endsWith"),M0=!vl&&!!function(){var a=w0(String.prototype,"endsWith");return a&&!a.writable}();$0({target:"String",proto:!0,forced:!M0&&!vl},{endsWith:function(e){var t=Js(P0(this));A0(e);var r=arguments.length>1?arguments[1]:void 0,i=t.length,n=r===void 0?i:N0(C0(r),i),o=Js(e);return eo?eo(t,o,n):I0(t,n-o.length,n)===o}});var _0=Ci,D0=de,V0=xr,L0=function(a,e,t){var r=_0(e);r in a?D0.f(a,r,V0(0,t)):a[r]=t},to=su,k0=Pr,B0=L0,F0=Array,j0=Math.max,U0=function(a,e,t){for(var r=k0(a),i=to(e,r),n=to(t===void 0?r:t,r),o=F0(j0(n-i,0)),s=0;i1||"".split(/.?/).length?r=function(i,n){var o=Ba(ro(this)),s=n===void 0?no:n>>>0;if(s===0)return[];if(i===void 0)return[o];if(!X0(i))return yt(e,o,i,s);for(var u=[],l=(i.ignoreCase?"i":"")+(i.multiline?"m":"")+(i.unicode?"u":"")+(i.sticky?"y":""),h=0,f=new RegExp(i.source,l+"g"),c,v,d;(c=yt(Z0,f,o))&&(v=f.lastIndex,!(v>h&&(Ke(u,mt(o,h,c.index)),c.length>1&&c.index=s)));)f.lastIndex===c.index&&f.lastIndex++;return h===o.length?(d||!rb(f,""))&&Ke(u,""):Ke(u,mt(o,h)),u.length>s?ao(u,0,s):u}:"0".split(void 0,0).length?r=function(i,n){return i===void 0&&n===0?[]:yt(e,this,i,n)}:r=e,[function(n,o){var s=ro(this),u=Y0(n)?void 0:K0(n,a);return u?yt(u,n,s,o):yt(r,Ba(s),n,o)},function(i,n){var o=H0(this),s=Ba(i),u=t(r,o,s,n,r!==e);if(u.done)return u.value;var l=W0(o,RegExp),h=o.unicode,f=(o.ignoreCase?"i":"")+(o.multiline?"m":"")+(o.unicode?"u":"")+(Qe?"g":"y"),c=new l(Qe?"^(?:"+o.source+")":o,f),v=n===void 0?no:n>>>0;if(v===0)return[];if(s.length===0)return io(c,s)===null?[s]:[];for(var d=0,g=0,p=[];g"u"?Je:window,ar=["moz","webkit"],it="AnimationFrame",ot=be["request"+it],Ct=be["cancel"+it]||be["cancelRequest"+it];for(var bt=0;!ot&&bt3&&(this.alpha=s[3]),this.ok=!0}}this.r=this.r<0||isNaN(this.r)?0:this.r>255?255:this.r,this.g=this.g<0||isNaN(this.g)?0:this.g>255?255:this.g,this.b=this.b<0||isNaN(this.b)?0:this.b>255?255:this.b,this.alpha=this.alpha<0?0:this.alpha>1||isNaN(this.alpha)?1:this.alpha,this.toRGB=function(){return"rgb("+this.r+", "+this.g+", "+this.b+")"},this.toRGBA=function(){return"rgba("+this.r+", "+this.g+", "+this.b+", "+this.alpha+")"},this.toHex=function(){var u=this.r.toString(16),l=this.g.toString(16),h=this.b.toString(16);return u.length==1&&(u="0"+u),l.length==1&&(l="0"+l),h.length==1&&(h="0"+h),"#"+u+l+h},this.getHelpXML=function(){for(var u=new Array,l=0;l "+g.toRGB()+" -> "+g.toHex());d.appendChild(p),d.appendChild(y),v.appendChild(d)}catch{}return v}};const mi=Do(xb);var Tb=ee,Sb=Nt,Ob=ou.indexOf,Eb=ll,bi=Sb([].indexOf),gl=!!bi&&1/bi([1],1,-0)<0,$b=gl||!Eb("indexOf");Tb({target:"Array",proto:!0,forced:$b},{indexOf:function(e){var t=arguments.length>1?arguments[1]:void 0;return gl?bi(this,e,t)||0:Ob(this,e,t)}});var wb=ee,Cb=k,Ab=Ji,Pb=ge,ho=pe,Rb=en,Ib=Cb("".indexOf);wb({target:"String",proto:!0,forced:!Rb("includes")},{includes:function(e){return!!~Ib(ho(Pb(this)),ho(Ab(e)),arguments.length>1?arguments[1]:void 0)}});var Nb=Fe,Mb=Array.isArray||function(e){return Nb(e)==="Array"},_b=ee,Db=k,Vb=Mb,Lb=Db([].reverse),vo=[1,2];_b({target:"Array",proto:!0,forced:String(vo)===String(vo.reverse())},{reverse:function(){return Vb(this)&&(this.length=this.length),Lb(this)}});/*! ***************************************************************************** diff --git a/assets/jspdf.es.min-2fc60f34.js b/assets/jspdf.es.min-5cd5e647.js similarity index 99% rename from assets/jspdf.es.min-2fc60f34.js rename to assets/jspdf.es.min-5cd5e647.js index a6f809b..d3d5b48 100644 --- a/assets/jspdf.es.min-2fc60f34.js +++ b/assets/jspdf.es.min-5cd5e647.js @@ -1,4 +1,4 @@ -import{_ as ls}from"./main-9cddcd54.js";function fe(i){"@babel/helpers - typeof";return fe=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},fe(i)}var Qe=Uint8Array,tn=Uint16Array,ha=Uint32Array,so=new Qe([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),co=new Qe([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),hs=new Qe([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),xc=function(i,e){for(var n=new tn(31),a=0;a<31;++a)n[a]=e+=1<>>1|(ye&21845)<<1;Pr=(Pr&52428)>>>2|(Pr&13107)<<2,Pr=(Pr&61680)>>>4|(Pr&3855)<<4,ds[ye]=((Pr&65280)>>>8|(Pr&255)<<8)>>>1}var Kn=function(i,e,n){for(var a=i.length,c=0,o=new tn(e);c>>f]=g}else for(h=new tn(a),c=0;c>>15-i[c];return h},jr=new Qe(288);for(var ye=0;ye<144;++ye)jr[ye]=8;for(var ye=144;ye<256;++ye)jr[ye]=9;for(var ye=256;ye<280;++ye)jr[ye]=7;for(var ye=280;ye<288;++ye)jr[ye]=8;var fa=new Qe(32);for(var ye=0;ye<32;++ye)fa[ye]=5;var Su=Kn(jr,9,0),_u=Kn(jr,9,1),Pu=Kn(fa,5,0),ku=Kn(fa,5,1),es=function(i){for(var e=i[0],n=1;ne&&(e=i[n]);return e},Mn=function(i,e,n){var a=e/8>>0;return(i[a]|i[a+1]<<8)>>>(e&7)&n},ns=function(i,e){var n=e/8>>0;return(i[n]|i[n+1]<<8|i[n+2]<<16)>>>(e&7)},Ns=function(i){return(i/8>>0)+(i&7&&1)},kc=function(i,e,n){(e==null||e<0)&&(e=0),(n==null||n>i.length)&&(n=i.length);var a=new(i instanceof tn?tn:i instanceof ha?ha:Qe)(n-e);return a.set(i.subarray(e,n)),a},Fu=function(i,e,n){var a=i.length,c=!e||n,o=!n||n.i;n||(n={}),e||(e=new Qe(a*3));var l=function(Y){var Q=e.length;if(Y>Q){var et=new Qe(Math.max(Q*2,Y));et.set(e),e=et}},h=n.f||0,f=n.p||0,g=n.b||0,b=n.l,A=n.d,S=n.m,p=n.n,O=a*8;do{if(!b){n.f=h=Mn(i,f,1);var I=Mn(i,f+1,3);if(f+=3,I)if(I==1)b=_u,A=ku,S=9,p=5;else if(I==2){var X=Mn(i,f,31)+257,ot=Mn(i,f+10,15)+4,ut=X+Mn(i,f+5,31)+1;f+=14;for(var wt=new Qe(ut),tt=new Qe(19),R=0;RO)break;for(var F=Kn(tt,gt,1),R=0;R>>4;if(q<16)wt[R++]=q;else{var z=0,D=0;for(q==16?(D=3+Mn(i,f,3),f+=2,z=wt[R-1]):q==17?(D=3+Mn(i,f,7),f+=3):q==18&&(D=11+Mn(i,f,127),f+=7);D--;)wt[R++]=z}}var at=wt.subarray(0,X),nt=wt.subarray(X);S=es(at),p=es(nt),b=Kn(at,S,1),A=Kn(nt,p,1)}else throw"invalid block type";else{var q=Ns(f)+4,_=i[q-4]|i[q-3]<<8,B=q+_;if(B>a){if(o)throw"unexpected EOF";break}c&&l(g+_),e.set(i.subarray(q,B),g),n.b=g+=_,n.p=f=B*8;continue}if(f>O)throw"unexpected EOF"}c&&l(g+131072);for(var lt=(1<>>4;if(f+=z&15,f>O)throw"unexpected EOF";if(!z)throw"invalid length/literal";if(ht<256)e[g++]=ht;else if(ht==256){b=null;break}else{var kt=ht-254;if(ht>264){var R=ht-257,L=so[R];kt=Mn(i,f,(1<>>4;if(!j)throw"invalid distance";f+=j&15;var nt=xu[M];if(M>3){var L=co[M];nt+=ns(i,f)&(1<O)throw"unexpected EOF";c&&l(g+131072);for(var W=g+kt;g>0;i[a]|=n,i[a+1]|=n>>>8},ia=function(i,e,n){n<<=e&7;var a=e/8>>0;i[a]|=n,i[a+1]|=n>>>8,i[a+2]|=n>>>16},rs=function(i,e){for(var n=[],a=0;aS&&(S=o[a].s);var p=new tn(S+1),O=ps(n[b-1],p,0);if(O>e){var a=0,I=0,q=O-e,_=1<e)I+=_-(1<>>=q;I>0;){var X=o[a].s;p[X]=0&&I;--a){var ot=o[a].s;p[ot]==e&&(--p[ot],++I)}O=e}return[new Qe(p),O]},ps=function(i,e,n){return i.s==-1?Math.max(ps(i.l,e,n+1),ps(i.r,e,n+1)):e[i.s]=n},ac=function(i){for(var e=i.length;e&&!i[--e];);for(var n=new tn(++e),a=0,c=i[0],o=1,l=function(f){n[a++]=f},h=1;h<=e;++h)if(i[h]==c&&h!=e)++o;else{if(!c&&o>2){for(;o>138;o-=138)l(32754);o>2&&(l(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(l(c),--o;o>6;o-=6)l(8304);o>2&&(l(o-3<<5|8208),o=0)}for(;o--;)l(c);o=1,c=i[h]}return[n.subarray(0,a),e]},aa=function(i,e){for(var n=0,a=0;a>>8,i[c+2]=i[c]^255,i[c+3]=i[c+1]^255;for(var o=0;o4&&!dt[hs[P-1]];--P);var z=g+5<<3,D=aa(c,jr)+aa(o,fa)+l,at=aa(c,S)+aa(o,I)+l+14+3*P+aa(tt,dt)+(2*tt[16]+3*tt[17]+7*tt[18]);if(z<=D&&z<=at)return ao(e,b,i.subarray(f,f+g));var nt,lt,$,ft;if(lr(e,b,1+(at15&&(lr(e,b,j[R]>>>5&127),b+=j[R]>>>12)}}else nt=Su,lt=jr,$=Pu,ft=fa;for(var R=0;R255){var M=a[R]>>>18&31;ia(e,b,nt[M+257]),b+=lt[M+257],M>7&&(lr(e,b,a[R]>>>23&31),b+=so[M]);var W=a[R]&31;ia(e,b,$[W]),b+=ft[W],W>3&&(ia(e,b,a[R]>>>5&8191),b+=co[W])}else ia(e,b,nt[a[R]]),b+=lt[a[R]];return ia(e,b,nt[256]),b+lt[256]},Iu=new ha([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),Cu=new Qe(0),ju=function(i,e,n,a,c,o){var l=i.length,h=new Qe(a+l+5*(1+Math.floor(l/7e3))+c),f=h.subarray(a,h.length-c),g=0;if(!e||l<8)for(var b=0;b<=l;b+=65535){var A=b+65535;A>>13,O=S&8191,I=(1<7e3||dt>24576)&&nt>423){g=oc(i,f,0,ut,wt,tt,gt,dt,P,b-P,g),dt=R=gt=0,P=b;for(var lt=0;lt<286;++lt)wt[lt]=0;for(var lt=0;lt<30;++lt)tt[lt]=0}var $=2,ft=0,ht=O,kt=D-at&32767;if(nt>2&&z==ot(b-kt))for(var L=Math.min(p,nt)-1,j=Math.min(32767,b),M=Math.min(258,nt);kt<=j&&--ht&&D!=at;){if(i[b+$]==i[b+$-kt]){for(var W=0;W$){if($=W,ft=kt,W>L)break;for(var Y=Math.min(kt,W-2),Q=0,lt=0;ltQ&&(Q=At,at=et)}}}D=at,at=q[D],kt+=D-at+32768&32767}if(ft){ut[dt++]=268435456|fs[$]<<18|ic[ft];var Nt=fs[$]&31,Ct=ic[ft]&31;gt+=so[Nt]+co[Ct],++wt[257+Nt],++tt[Ct],F=b+$,++R}else ut[dt++]=i[b],++wt[i[b]]}}g=oc(i,f,o,ut,wt,tt,gt,dt,P,b-P,g),o||(g=ao(f,g,Cu))}return kc(h,0,a+Ns(g)+c)},Ou=function(){var i=1,e=0;return{p:function(n){for(var a=i,c=e,o=n.length,l=0;l!=o;){for(var h=Math.min(l+5552,o);l>>8<<16|(e&255)<<8|e>>>8)+((i&255)<<23)*2}}},Bu=function(i,e,n,a,c){return ju(i,e.level==null?6:e.level,e.mem==null?Math.ceil(Math.max(8,Math.min(13,Math.log(i.length)))*1.5):12+e.mem,n,a,!c)},Mu=function(i,e,n){for(;n;++e)i[e]=n,n>>>=8},Eu=function(i,e){var n=e.level,a=n==0?0:n<6?1:n==9?3:2;i[0]=120,i[1]=a<<6|(a?32-2*a:1)},qu=function(i){if((i[0]&15)!=8||i[0]>>>4>7||(i[0]<<8|i[1])%31)throw"invalid zlib data";if(i[1]&32)throw"invalid zlib data: preset dictionaries not supported"};function gs(i,e){e===void 0&&(e={});var n=Ou();n.p(i);var a=Bu(i,e,2,4);return Eu(a,e),Mu(a,a.length-4,n.d()),a}function Du(i,e){return Fu((qu(i),i.subarray(2,-4)),e)}var Ht=function(){return typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:this}();function is(){Ht.console&&typeof Ht.console.log=="function"&&Ht.console.log.apply(Ht.console,arguments)}var ve={log:is,warn:function(i){Ht.console&&(typeof Ht.console.warn=="function"?Ht.console.warn.apply(Ht.console,arguments):is.call(null,arguments))},error:function(i){Ht.console&&(typeof Ht.console.error=="function"?Ht.console.error.apply(Ht.console,arguments):is(i))}};function as(i,e,n){var a=new XMLHttpRequest;a.open("GET",i),a.responseType="blob",a.onload=function(){Wr(a.response,e,n)},a.onerror=function(){ve.error("could not download file")},a.send()}function sc(i){var e=new XMLHttpRequest;e.open("HEAD",i,!1);try{e.send()}catch{}return e.status>=200&&e.status<=299}function eo(i){try{i.dispatchEvent(new MouseEvent("click"))}catch{var e=document.createEvent("MouseEvents");e.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),i.dispatchEvent(e)}}var oa,ms,Wr=Ht.saveAs||((typeof window>"u"?"undefined":fe(window))!=="object"||window!==Ht?function(){}:typeof HTMLAnchorElement<"u"&&"download"in HTMLAnchorElement.prototype?function(i,e,n){var a=Ht.URL||Ht.webkitURL,c=document.createElement("a");e=e||i.name||"download",c.download=e,c.rel="noopener",typeof i=="string"?(c.href=i,c.origin!==location.origin?sc(c.href)?as(i,e,n):eo(c,c.target="_blank"):eo(c)):(c.href=a.createObjectURL(i),setTimeout(function(){a.revokeObjectURL(c.href)},4e4),setTimeout(function(){eo(c)},0))}:"msSaveOrOpenBlob"in navigator?function(i,e,n){if(e=e||i.name||"download",typeof i=="string")if(sc(i))as(i,e,n);else{var a=document.createElement("a");a.href=i,a.target="_blank",setTimeout(function(){eo(a)})}else navigator.msSaveOrOpenBlob(function(c,o){return o===void 0?o={autoBom:!1}:fe(o)!=="object"&&(ve.warn("Deprecated: Expected third argument to be a object"),o={autoBom:!o}),o.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(c.type)?new Blob([String.fromCharCode(65279),c],{type:c.type}):c}(i,n),e)}:function(i,e,n,a){if((a=a||open("","_blank"))&&(a.document.title=a.document.body.innerText="downloading..."),typeof i=="string")return as(i,e,n);var c=i.type==="application/octet-stream",o=/constructor/i.test(Ht.HTMLElement)||Ht.safari,l=/CriOS\/[\d]+/.test(navigator.userAgent);if((l||c&&o)&&(typeof FileReader>"u"?"undefined":fe(FileReader))==="object"){var h=new FileReader;h.onloadend=function(){var b=h.result;b=l?b:b.replace(/^data:[^;]*;/,"data:attachment/file;"),a?a.location.href=b:location=b,a=null},h.readAsDataURL(i)}else{var f=Ht.URL||Ht.webkitURL,g=f.createObjectURL(i);a?a.location=g:location.href=g,a=null,setTimeout(function(){f.revokeObjectURL(g)},4e4)}});/** +import{_ as ls}from"./main-316b396b.js";function fe(i){"@babel/helpers - typeof";return fe=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},fe(i)}var Qe=Uint8Array,tn=Uint16Array,ha=Uint32Array,so=new Qe([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),co=new Qe([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),hs=new Qe([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),xc=function(i,e){for(var n=new tn(31),a=0;a<31;++a)n[a]=e+=1<>>1|(ye&21845)<<1;Pr=(Pr&52428)>>>2|(Pr&13107)<<2,Pr=(Pr&61680)>>>4|(Pr&3855)<<4,ds[ye]=((Pr&65280)>>>8|(Pr&255)<<8)>>>1}var Kn=function(i,e,n){for(var a=i.length,c=0,o=new tn(e);c>>f]=g}else for(h=new tn(a),c=0;c>>15-i[c];return h},jr=new Qe(288);for(var ye=0;ye<144;++ye)jr[ye]=8;for(var ye=144;ye<256;++ye)jr[ye]=9;for(var ye=256;ye<280;++ye)jr[ye]=7;for(var ye=280;ye<288;++ye)jr[ye]=8;var fa=new Qe(32);for(var ye=0;ye<32;++ye)fa[ye]=5;var Su=Kn(jr,9,0),_u=Kn(jr,9,1),Pu=Kn(fa,5,0),ku=Kn(fa,5,1),es=function(i){for(var e=i[0],n=1;ne&&(e=i[n]);return e},Mn=function(i,e,n){var a=e/8>>0;return(i[a]|i[a+1]<<8)>>>(e&7)&n},ns=function(i,e){var n=e/8>>0;return(i[n]|i[n+1]<<8|i[n+2]<<16)>>>(e&7)},Ns=function(i){return(i/8>>0)+(i&7&&1)},kc=function(i,e,n){(e==null||e<0)&&(e=0),(n==null||n>i.length)&&(n=i.length);var a=new(i instanceof tn?tn:i instanceof ha?ha:Qe)(n-e);return a.set(i.subarray(e,n)),a},Fu=function(i,e,n){var a=i.length,c=!e||n,o=!n||n.i;n||(n={}),e||(e=new Qe(a*3));var l=function(Y){var Q=e.length;if(Y>Q){var et=new Qe(Math.max(Q*2,Y));et.set(e),e=et}},h=n.f||0,f=n.p||0,g=n.b||0,b=n.l,A=n.d,S=n.m,p=n.n,O=a*8;do{if(!b){n.f=h=Mn(i,f,1);var I=Mn(i,f+1,3);if(f+=3,I)if(I==1)b=_u,A=ku,S=9,p=5;else if(I==2){var X=Mn(i,f,31)+257,ot=Mn(i,f+10,15)+4,ut=X+Mn(i,f+5,31)+1;f+=14;for(var wt=new Qe(ut),tt=new Qe(19),R=0;RO)break;for(var F=Kn(tt,gt,1),R=0;R>>4;if(q<16)wt[R++]=q;else{var z=0,D=0;for(q==16?(D=3+Mn(i,f,3),f+=2,z=wt[R-1]):q==17?(D=3+Mn(i,f,7),f+=3):q==18&&(D=11+Mn(i,f,127),f+=7);D--;)wt[R++]=z}}var at=wt.subarray(0,X),nt=wt.subarray(X);S=es(at),p=es(nt),b=Kn(at,S,1),A=Kn(nt,p,1)}else throw"invalid block type";else{var q=Ns(f)+4,_=i[q-4]|i[q-3]<<8,B=q+_;if(B>a){if(o)throw"unexpected EOF";break}c&&l(g+_),e.set(i.subarray(q,B),g),n.b=g+=_,n.p=f=B*8;continue}if(f>O)throw"unexpected EOF"}c&&l(g+131072);for(var lt=(1<>>4;if(f+=z&15,f>O)throw"unexpected EOF";if(!z)throw"invalid length/literal";if(ht<256)e[g++]=ht;else if(ht==256){b=null;break}else{var kt=ht-254;if(ht>264){var R=ht-257,L=so[R];kt=Mn(i,f,(1<>>4;if(!j)throw"invalid distance";f+=j&15;var nt=xu[M];if(M>3){var L=co[M];nt+=ns(i,f)&(1<O)throw"unexpected EOF";c&&l(g+131072);for(var W=g+kt;g>0;i[a]|=n,i[a+1]|=n>>>8},ia=function(i,e,n){n<<=e&7;var a=e/8>>0;i[a]|=n,i[a+1]|=n>>>8,i[a+2]|=n>>>16},rs=function(i,e){for(var n=[],a=0;aS&&(S=o[a].s);var p=new tn(S+1),O=ps(n[b-1],p,0);if(O>e){var a=0,I=0,q=O-e,_=1<e)I+=_-(1<>>=q;I>0;){var X=o[a].s;p[X]=0&&I;--a){var ot=o[a].s;p[ot]==e&&(--p[ot],++I)}O=e}return[new Qe(p),O]},ps=function(i,e,n){return i.s==-1?Math.max(ps(i.l,e,n+1),ps(i.r,e,n+1)):e[i.s]=n},ac=function(i){for(var e=i.length;e&&!i[--e];);for(var n=new tn(++e),a=0,c=i[0],o=1,l=function(f){n[a++]=f},h=1;h<=e;++h)if(i[h]==c&&h!=e)++o;else{if(!c&&o>2){for(;o>138;o-=138)l(32754);o>2&&(l(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(l(c),--o;o>6;o-=6)l(8304);o>2&&(l(o-3<<5|8208),o=0)}for(;o--;)l(c);o=1,c=i[h]}return[n.subarray(0,a),e]},aa=function(i,e){for(var n=0,a=0;a>>8,i[c+2]=i[c]^255,i[c+3]=i[c+1]^255;for(var o=0;o4&&!dt[hs[P-1]];--P);var z=g+5<<3,D=aa(c,jr)+aa(o,fa)+l,at=aa(c,S)+aa(o,I)+l+14+3*P+aa(tt,dt)+(2*tt[16]+3*tt[17]+7*tt[18]);if(z<=D&&z<=at)return ao(e,b,i.subarray(f,f+g));var nt,lt,$,ft;if(lr(e,b,1+(at15&&(lr(e,b,j[R]>>>5&127),b+=j[R]>>>12)}}else nt=Su,lt=jr,$=Pu,ft=fa;for(var R=0;R255){var M=a[R]>>>18&31;ia(e,b,nt[M+257]),b+=lt[M+257],M>7&&(lr(e,b,a[R]>>>23&31),b+=so[M]);var W=a[R]&31;ia(e,b,$[W]),b+=ft[W],W>3&&(ia(e,b,a[R]>>>5&8191),b+=co[W])}else ia(e,b,nt[a[R]]),b+=lt[a[R]];return ia(e,b,nt[256]),b+lt[256]},Iu=new ha([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),Cu=new Qe(0),ju=function(i,e,n,a,c,o){var l=i.length,h=new Qe(a+l+5*(1+Math.floor(l/7e3))+c),f=h.subarray(a,h.length-c),g=0;if(!e||l<8)for(var b=0;b<=l;b+=65535){var A=b+65535;A>>13,O=S&8191,I=(1<7e3||dt>24576)&&nt>423){g=oc(i,f,0,ut,wt,tt,gt,dt,P,b-P,g),dt=R=gt=0,P=b;for(var lt=0;lt<286;++lt)wt[lt]=0;for(var lt=0;lt<30;++lt)tt[lt]=0}var $=2,ft=0,ht=O,kt=D-at&32767;if(nt>2&&z==ot(b-kt))for(var L=Math.min(p,nt)-1,j=Math.min(32767,b),M=Math.min(258,nt);kt<=j&&--ht&&D!=at;){if(i[b+$]==i[b+$-kt]){for(var W=0;W$){if($=W,ft=kt,W>L)break;for(var Y=Math.min(kt,W-2),Q=0,lt=0;ltQ&&(Q=At,at=et)}}}D=at,at=q[D],kt+=D-at+32768&32767}if(ft){ut[dt++]=268435456|fs[$]<<18|ic[ft];var Nt=fs[$]&31,Ct=ic[ft]&31;gt+=so[Nt]+co[Ct],++wt[257+Nt],++tt[Ct],F=b+$,++R}else ut[dt++]=i[b],++wt[i[b]]}}g=oc(i,f,o,ut,wt,tt,gt,dt,P,b-P,g),o||(g=ao(f,g,Cu))}return kc(h,0,a+Ns(g)+c)},Ou=function(){var i=1,e=0;return{p:function(n){for(var a=i,c=e,o=n.length,l=0;l!=o;){for(var h=Math.min(l+5552,o);l>>8<<16|(e&255)<<8|e>>>8)+((i&255)<<23)*2}}},Bu=function(i,e,n,a,c){return ju(i,e.level==null?6:e.level,e.mem==null?Math.ceil(Math.max(8,Math.min(13,Math.log(i.length)))*1.5):12+e.mem,n,a,!c)},Mu=function(i,e,n){for(;n;++e)i[e]=n,n>>>=8},Eu=function(i,e){var n=e.level,a=n==0?0:n<6?1:n==9?3:2;i[0]=120,i[1]=a<<6|(a?32-2*a:1)},qu=function(i){if((i[0]&15)!=8||i[0]>>>4>7||(i[0]<<8|i[1])%31)throw"invalid zlib data";if(i[1]&32)throw"invalid zlib data: preset dictionaries not supported"};function gs(i,e){e===void 0&&(e={});var n=Ou();n.p(i);var a=Bu(i,e,2,4);return Eu(a,e),Mu(a,a.length-4,n.d()),a}function Du(i,e){return Fu((qu(i),i.subarray(2,-4)),e)}var Ht=function(){return typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:this}();function is(){Ht.console&&typeof Ht.console.log=="function"&&Ht.console.log.apply(Ht.console,arguments)}var ve={log:is,warn:function(i){Ht.console&&(typeof Ht.console.warn=="function"?Ht.console.warn.apply(Ht.console,arguments):is.call(null,arguments))},error:function(i){Ht.console&&(typeof Ht.console.error=="function"?Ht.console.error.apply(Ht.console,arguments):is(i))}};function as(i,e,n){var a=new XMLHttpRequest;a.open("GET",i),a.responseType="blob",a.onload=function(){Wr(a.response,e,n)},a.onerror=function(){ve.error("could not download file")},a.send()}function sc(i){var e=new XMLHttpRequest;e.open("HEAD",i,!1);try{e.send()}catch{}return e.status>=200&&e.status<=299}function eo(i){try{i.dispatchEvent(new MouseEvent("click"))}catch{var e=document.createEvent("MouseEvents");e.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),i.dispatchEvent(e)}}var oa,ms,Wr=Ht.saveAs||((typeof window>"u"?"undefined":fe(window))!=="object"||window!==Ht?function(){}:typeof HTMLAnchorElement<"u"&&"download"in HTMLAnchorElement.prototype?function(i,e,n){var a=Ht.URL||Ht.webkitURL,c=document.createElement("a");e=e||i.name||"download",c.download=e,c.rel="noopener",typeof i=="string"?(c.href=i,c.origin!==location.origin?sc(c.href)?as(i,e,n):eo(c,c.target="_blank"):eo(c)):(c.href=a.createObjectURL(i),setTimeout(function(){a.revokeObjectURL(c.href)},4e4),setTimeout(function(){eo(c)},0))}:"msSaveOrOpenBlob"in navigator?function(i,e,n){if(e=e||i.name||"download",typeof i=="string")if(sc(i))as(i,e,n);else{var a=document.createElement("a");a.href=i,a.target="_blank",setTimeout(function(){eo(a)})}else navigator.msSaveOrOpenBlob(function(c,o){return o===void 0?o={autoBom:!1}:fe(o)!=="object"&&(ve.warn("Deprecated: Expected third argument to be a object"),o={autoBom:!o}),o.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(c.type)?new Blob([String.fromCharCode(65279),c],{type:c.type}):c}(i,n),e)}:function(i,e,n,a){if((a=a||open("","_blank"))&&(a.document.title=a.document.body.innerText="downloading..."),typeof i=="string")return as(i,e,n);var c=i.type==="application/octet-stream",o=/constructor/i.test(Ht.HTMLElement)||Ht.safari,l=/CriOS\/[\d]+/.test(navigator.userAgent);if((l||c&&o)&&(typeof FileReader>"u"?"undefined":fe(FileReader))==="object"){var h=new FileReader;h.onloadend=function(){var b=h.result;b=l?b:b.replace(/^data:[^;]*;/,"data:attachment/file;"),a?a.location.href=b:location=b,a=null},h.readAsDataURL(i)}else{var f=Ht.URL||Ht.webkitURL,g=f.createObjectURL(i);a?a.location=g:location.href=g,a=null,setTimeout(function(){f.revokeObjectURL(g)},4e4)}});/** * A class to parse color values * @author Stoyan Stefanov * {@link http://www.phpied.com/rgb-color-parser-in-javascript/} @@ -163,7 +163,7 @@ endobj\r * http://opensource.org/licenses/mit-license */function En(i,e){if(this.pos=0,this.buffer=i,this.datav=new DataView(i.buffer),this.is_with_alpha=!!e,this.bottom_up=!0,this.flag=String.fromCharCode(this.buffer[0])+String.fromCharCode(this.buffer[1]),this.pos+=2,["BM","BA","CI","CP","IC","PT"].indexOf(this.flag)===-1)throw new Error("Invalid BMP File");this.parseHeader(),this.parseBGR()}function Nc(i){function e(R){if(!R)throw Error("assert :P")}function n(R,gt,dt){for(var F=0;4>F;F++)if(R[gt+F]!=dt.charCodeAt(F))return!0;return!1}function a(R,gt,dt,F,P){for(var z=0;zz+1?[]:new gt),!(D.length>>0;t&u;)u>>>=1;return u?(t&u-1)+u:t}function dt(t,r,u,d,m){e(!(d%u));do t[r+(d-=u)]=m;while(0=m),512>=m)var w=o(512);else if((w=o(m))==null)return 0;return function(y,N,x,k,U,K){var Z,G,vt=N,it=1<Z;++Z){if(H[Z]>1<(Rt-=H[Z]))return 0;for(;0=Z;++Z,U<<=1){if(St+=Rt<<=1,0>(Rt-=H[Z]))return 0;for(;0bt&&!(0>=(pt-=H[bt]));)++bt,pt<<=1;it+=_t=1<<(pt=bt-x),y[N+(bt=Ot&mt)].g=pt+x,y[N+bt].value=vt-N-bt}k.g=Z-x,k.value=K[G++],dt(y,vt+(Ot>>x),U,_t,k),Ot=gt(Ot,Z)}}return St!=2*V[15]-1?0:it}(t,r,u,d,m,w)}function P(){this.value=this.g=0}function z(){this.value=this.g=0}function D(){this.G=l(5,P),this.H=o(5),this.jc=this.Qb=this.qb=this.nd=0,this.pd=l(rn,z)}function at(t,r,u,d){e(t!=null),e(r!=null),e(2147483648>d),t.Ca=254,t.I=0,t.b=-8,t.Ka=0,t.oa=r,t.pa=u,t.Jd=r,t.Yc=u+d,t.Zc=4<=d?u+d-4+1:u,Q(t)}function nt(t,r){for(var u=0;0d),t.Sb=d,t.Ra=0,t.u=0,t.h=0,4>>=8,t.Ra+=t.oa[t.pa+t.bb]<>>0,++t.bb,t.u-=8;M(t)&&(t.h=1,t.u=0)}function ht(t,r){if(e(0<=r),!t.h&&r<=gi){var u=j(t)&pi[r];return t.u+=r,ft(t),u}return t.h=1,t.u=0}function kt(){this.b=this.Ca=this.I=0,this.oa=[],this.pa=0,this.Jd=[],this.Yc=0,this.Zc=[],this.Ka=0}function L(){this.Ra=0,this.oa=[],this.h=this.u=this.bb=this.Sb=this.pa=0}function j(t){return t.Ra>>>(t.u&mi-1)>>>0}function M(t){return e(t.bb<=t.Sb),t.h||t.bb==t.Sb&&t.u>mi}function W(t,r){t.u=r,t.h=M(t)}function Y(t){t.u>=Yi&&(e(t.u>=Yi),ft(t))}function Q(t){e(t!=null&&t.oa!=null),t.pa>>0,t.b+=8):(e(t!=null&&t.oa!=null),t.pat.b&&Q(t);var d=t.b,m=u*r>>>8,w=(t.I>>>d>m)+0;for(w?(u-=m,t.I-=m+1<>>0):u=m+1,d=u,m=0;256<=d;)m+=8,d>>=8;return d=7^m+an[d],t.b-=d,t.Ca=(u<>24&255,t[r+1]=u>>16&255,t[r+2]=u>>8&255,t[r+3]=u>>0&255}function Nt(t,r){return t[r+0]<<0|t[r+1]<<8}function Ct(t,r){return Nt(t,r)|t[r+2]<<16}function Bt(t,r){return Nt(t,r)|Nt(t,r+2)<<16}function Ut(t,r){var u=1<=m||0>=w?0:(u[0]=m,d[0]=w,1)}function Et(t,r){return t+(1<>>r}function Lt(t,r){return((4278255360&t)+(4278255360&r)>>>0&4278255360)+((16711935&t)+(16711935&r)>>>0&16711935)>>>0}function xt(t,r){R[r]=function(u,d,m,w,y,N,x){var k;for(k=0;k>>1)+(t&r)>>>0}function qt(t){return 0<=t&&256>t?t:0>t?0:255>1))}function $t(t,r,u){return Math.abs(r-u)-Math.abs(t-u)}function te(t,r,u,d,m,w,y){for(d=w[y-1],u=0;u>8&255,x=16711935&(x=(x=16711935&y)+((N<<16)+N));d[m+w]=(4278255360&y)+x>>>0}}function de(t,r){r.jd=t>>0&255,r.hd=t>>8&255,r.ud=t>>16&255}function Wt(t,r,u,d,m,w){var y;for(y=0;y>>8,k=N,U=255&(U=(U=N>>>16)+((t.jd<<24>>24)*(x<<24>>24)>>>5));k=255&(k=(k=k+((t.hd<<24>>24)*(x<<24>>24)>>>5))+((t.ud<<24>>24)*(U<<24>>24)>>>5)),m[w+y]=(4278255360&N)+(U<<16)+k}}function ee(t,r,u,d,m){R[r]=function(w,y,N,x,k,U,K,Z,G){for(x=K;x>w.b,G=w.Ea,vt=w.K[0],it=w.w;if(8>Z)for(w=(1<>=Z}else R["VP8LMapColor"+u](x,k,vt,it,U,K,y,N,G)}}function It(t,r,u,d,m){for(u=r+u;r>16&255,d[m++]=w>>8&255,d[m++]=w>>0&255}}function Ve(t,r,u,d,m){for(u=r+u;r>16&255,d[m++]=w>>8&255,d[m++]=w>>0&255,d[m++]=w>>24&255}}function oe(t,r,u,d,m){for(u=r+u;r>16&240|y>>12&15,y=y>>0&240|y>>28&15;d[m++]=w,d[m++]=y}}function yn(t,r,u,d,m){for(u=r+u;r>16&248|y>>13&7,y=y>>5&224|y>>3&31;d[m++]=w,d[m++]=y}}function ge(t,r,u,d,m){for(u=r+u;r>0&255,d[m++]=w>>8&255,d[m++]=w>>16&255}}function Le(t,r,u,d,m,w){if(w==0)for(u=r+u;r>24|w[1]>>8&65280|w[2]<<8&16711680|w[3]<<24)>>>0),m+=32;else a(d,m,t,r,u)}function Rn(t,r){R[r][0]=R[t+"0"],R[r][1]=R[t+"1"],R[r][2]=R[t+"2"],R[r][3]=R[t+"3"],R[r][4]=R[t+"4"],R[r][5]=R[t+"5"],R[r][6]=R[t+"6"],R[r][7]=R[t+"7"],R[r][8]=R[t+"8"],R[r][9]=R[t+"9"],R[r][10]=R[t+"10"],R[r][11]=R[t+"11"],R[r][12]=R[t+"12"],R[r][13]=R[t+"13"],R[r][14]=R[t+"0"],R[r][15]=R[t+"0"]}function ce(t){return t==To||t==zo||t==za||t==Uo}function Br(){this.eb=[],this.size=this.A=this.fb=0}function Ae(){this.y=[],this.f=[],this.ea=[],this.F=[],this.Tc=this.Ed=this.Cd=this.Fd=this.lb=this.Db=this.Ab=this.fa=this.J=this.W=this.N=this.O=0}function Ln(){this.Rd=this.height=this.width=this.S=0,this.f={},this.f.RGBA=new Br,this.f.kb=new Ae,this.sd=null}function $n(){this.width=[0],this.height=[0],this.Pd=[0],this.Qd=[0],this.format=[0]}function xe(){this.Id=this.fd=this.Md=this.hb=this.ib=this.da=this.bd=this.cd=this.j=this.v=this.Da=this.Sd=this.ob=0}function Yt(t){return alert("todo:WebPSamplerProcessPlane"),t.T}function ue(t,r){var u=t.T,d=r.ba.f.RGBA,m=d.eb,w=d.fb+t.ka*d.A,y=bn[r.ba.S],N=t.y,x=t.O,k=t.f,U=t.N,K=t.ea,Z=t.W,G=r.cc,vt=r.dc,it=r.Mc,H=r.Nc,V=t.ka,pt=t.ka+t.T,bt=t.U,mt=bt+1>>1;for(V==0?y(N,x,null,null,k,U,K,Z,k,U,K,Z,m,w,null,null,bt):(y(r.ec,r.fc,N,x,G,vt,it,H,k,U,K,Z,m,w-d.A,m,w,bt),++u);V+2u,m=u==Da||u==Ra||u==Ta||u==Ro||u==12||ce(u);if(r.memory=null,r.Ib=null,r.Jb=null,r.Nd=null,!Vi(r.Oa,t,m?11:12))return 0;if(m&&ce(u)&&yt(),t.da)alert("todo:use_scaling");else{if(d){if(r.Ib=Yt,t.Kb){if(u=t.U+1>>1,r.memory=o(t.U+2*u),r.memory==null)return 0;r.ec=r.memory,r.fc=0,r.cc=r.ec,r.dc=r.fc+t.U,r.Mc=r.cc,r.Nc=r.dc+u,r.Ib=ue,yt()}}else alert("todo:EmitYUV");m&&(r.Jb=Mr,d&&J())}if(d&&!Ts){for(t=0;256>t;++t)au[t]=89858*(t-128)+Ha>>Ua,cu[t]=-22014*(t-128)+Ha,su[t]=-45773*(t-128),ou[t]=113618*(t-128)+Ha>>Ua;for(t=Qi;t>Ua,uu[t-Qi]=ln(r,255),lu[t-Qi]=ln(r+8>>4,15);Ts=1}return 1}function Tn(t){var r=t.ma,u=t.U,d=t.T;return e(!(1&t.ka)),0>=u||0>=d?0:(u=r.Ib(t,r),r.Jb!=null&&r.Jb(t,r,u),r.Dc+=u,1)}function zn(t){t.ma.memory=null}function zt(t,r,u,d){return ht(t,8)!=47?0:(r[0]=ht(t,14)+1,u[0]=ht(t,14)+1,d[0]=ht(t,1),ht(t,3)!=0?0:!t.h)}function Nn(t,r){if(4>t)return t+1;var u=t-2>>1;return(2+(1&t)<>4)*t+(8-(15&u)))?u:1;var u}function en(t,r,u){var d=j(u),m=t[r+=255&d].g-8;return 0>>0,e(8>=u.g),t.g}function Oe(t,r,u){var d=t.xc;return e((r=d==0?0:t.vc[t.md*(u>>d)+(r>>d)])>_t.b)*St;itbt&&(ne=bt),(0,gr[se[le++]>>8&15])(Z,G+ +ae,V,pt+ae-bt,ne-ae,V,pt+ae),ae=ne}G+=bt,pt+=bt,++it&Ot||(_t+=St)}K!=k.nc&&a(x,N-vt,x,N+(K-U-1)*vt,vt);break;case 1:for(vt=Z,H=G,bt=(Z=k.Ea)-(pt=Z&~(V=(G=1<>k.b)*it;U=m),0w.o&&(d=w.o),u=d?u=0:(m[0]+=4*w.v,w.ka=u-w.j,w.U=w.va-w.v,w.T=d-u,u=1),u){if(N=N[0],11>(u=t.ca).S){var U=u.f.RGBA,K=(d=u.S,m=w.U,w=w.T,k=U.eb,U.A),Z=w;for(U=U.fb+t.Ma*U.A;0d){var m=t.l.width,w=u.ca,y=u.tb+m*d,N=t.V,x=t.Ba+t.c*d,k=t.gc;e(t.ab==1),e(k[0].hc==3),Eo(k[0],d,r,N,x,w,y),An(u,d,r,w,y,m)}t.C=t.Ma=r}function Sn(t,r,u,d,m,w,y){var N=t.$/d,x=t.$%d,k=t.m,U=t.s,K=u+t.$,Z=K;m=u+d*m;var G=u+d*w,vt=280+U.ua,it=t.Pb?N:16777216,H=0=it){var Ot=K-u;e((it=t).Pb),it.wd=it.m,it.xd=Ot,0Rt.g?(W(mt,mt.u+Rt.g),Ot[St]=Rt.value,mt=0):(W(mt,mt.u+Rt.g-256),e(256<=Rt.value),mt=Rt.value),mt==0&&(bt=!0)}else mt=en(pt.G[0],pt.H[0],k);if(k.h)break;if(bt||256>mt){if(!bt)if(pt.nd)r[K]=(pt.qb|mt<<8)>>>0;else{if(Y(k),bt=en(pt.G[1],pt.H[1],k),Y(k),Ot=en(pt.G[2],pt.H[2],k),St=en(pt.G[3],pt.H[3],k),k.h)break;r[K]=(St<<24|bt<<16|mt<<8|Ot)>>>0}if(bt=!1,++K,++x>=d&&(x=0,++N,y!=null&&N<=w&&!(N%16)&&y(t,N),H!=null))for(;Z>>H.Mb]=mt}else if(280>mt){if(mt=Nn(mt-256,k),Ot=en(pt.G[4],pt.H[4],k),Y(k),Ot=Un(d,Ot=Nn(Ot,k)),k.h)break;if(K-u=d;)x-=d,++N,y!=null&&N<=w&&!(N%16)&&y(t,N);if(e(K<=m),x&V&&(pt=Oe(U,x,N)),H!=null)for(;Z>>H.Mb]=mt}else{if(!(mt>>H.Mb]=mt;mt=K,e(!(bt>>>(Ot=H).Xa)),r[mt]=Ot.X[bt],bt=!0}bt||e(k.h==M(k))}if(t.Pb&&k.h&&Kw?w:N),t.a=0,t.$=K-u}return 1}return t.a=3,0}function Hn(t){e(t!=null),t.vc=null,t.yc=null,t.Ya=null;var r=t.Wa;r!=null&&(r.X=null),t.vb=null,e(t!=null)}function pn(){var t=new Bo;return t==null?null:(t.a=0,t.xb=Bs,Rn("Predictor","VP8LPredictors"),Rn("Predictor","VP8LPredictors_C"),Rn("PredictorAdd","VP8LPredictorsAdd"),Rn("PredictorAdd","VP8LPredictorsAdd_C"),Ba=ie,gn=Wt,In=It,mr=Ve,Gn=oe,rr=yn,vi=ge,R.VP8LMapColor32b=Xi,R.VP8LMapColor8b=qo,t)}function Wn(t,r,u,d,m){var w=1,y=[t],N=[r],x=d.m,k=d.s,U=null,K=0;t:for(;;){if(u)for(;w&&ht(x,1);){var Z=y,G=N,vt=d,it=1,H=vt.m,V=vt.gc[vt.ab],pt=ht(H,2);if(vt.Oc&1<=vt.ab),pt){case 0:case 1:V.b=ht(H,3)+2,it=Wn(Et(V.Ea,V.b),Et(V.nc,V.b),0,vt,V.K),V.K=V.K[0];break;case 3:var bt,mt=ht(H,8)+1,Ot=16>_t.b),le=o(se);if(le==null)bt=0;else{var ae=_t.K[0],ne=_t.w;for(le[0]=_t.K[0][0],St=1;St<1*Rt;++St)le[St]=Lt(ae[ne+St],le[St-1]);for(;St<4*se;++St)le[St]=0;_t.K[0]=null,_t.K[0]=le,bt=1}}it=bt;break;case 2:break;default:e(0)}w=it}}if(y=y[0],N=N[0],w&&ht(x,1)&&!(w=1<=(K=ht(x,4))&&11>=K)){d.a=3;break t}var me;if(me=w)e:{var pe,Zt,Me,on=d,Ee=y,sn=N,he=K,fn=u,dn=on.m,ze=on.s,We=[null],$e=1,wn=0,Yn=Gc[he];n:for(;;){if(fn&&ht(dn,1)){var Ue=ht(dn,3)+2,cr=Et(Ee,Ue),Hr=Et(sn,Ue),Li=cr*Hr;if(!Wn(cr,Hr,0,on,We))break n;for(We=We[0],ze.xc=Ue,pe=0;pe>8&65535;We[pe]=Nr,Nr>=$e&&($e=Nr+1)}}if(dn.h)break n;for(Zt=0;5>Zt;++Zt){var _e=js[Zt];!Zt&&0=Hs),Va=Ws;var ta=o(wn);if(Va==null||ta==null||Go==null){on.a=1;break n}var Ga=Go;for(pe=Me=0;pe<$e;++pe){var Bn=Va[pe],Ni=Bn.G,Ai=Bn.H,Vs=0,Ya=1,Gs=0;for(Zt=0;5>Zt;++Zt){_e=js[Zt],Ni[Zt]=Ga,Ai[Zt]=Me,!Zt&&0$a)break r}else Xo=$a;for(na=0;na<$a&&Xo--;){Y(xr);var tc=Qs[0+(127&j(xr))];W(xr,xr.u+tc.g);var xi=tc.value;if(16>xi)Zs[na++]=xi,xi!=0&&($s=xi);else{var yu=xi==16,ec=xi-16,Lu=Uc[ec],nc=ht(xr,zc[ec])+Lu;if(na+nc>$a)break r;for(var Nu=yu?$s:0;0=Zt){var ra,Zo=ta[0];for(ra=1;ra<_e;++ra)ta[ra]>Zo&&(Zo=ta[ra]);Gs+=Zo}}if(Bn.nd=Ya,Bn.Qb=0,Ya&&(Bn.qb=(Ni[3][Ai[3]+0].value<<24|Ni[1][Ai[1]+0].value<<16|Ni[2][Ai[2]+0].value)>>>0,Vs==0&&256>Ni[0][Ai[0]+0].value&&(Bn.Qb=1,Bn.qb+=Ni[0][Ai[0]+0].value<<8)),Bn.jc=!Bn.Qb&&6>Gs,Bn.jc){var Qa,ur=Bn;for(Qa=0;Qa>=qe(to,8,_r),Sr>>=qe(ur.G[1][ur.H[1]+Sr],16,_r),Sr>>=qe(ur.G[2][ur.H[2]+Sr],0,_r),qe(ur.G[3][ur.H[3]+Sr],24,_r))}}}ze.vc=We,ze.Wb=$e,ze.Ya=Va,ze.yc=Go,me=1;break e}me=0}if(!(w=me)){d.a=3;break t}if(0d+1?[]:0),!(m.lengthm)return ke(t,7,"Truncated header.");var w=u[d+0]|u[d+1]<<8|u[d+2]<<16,y=t.Od;if(y.Rb=!(1&w),y.td=w>>1&7,y.yd=w>>4&1,y.ub=w>>5,3m)return ke(t,7,"cannot parse picture header");if(!va(u,d,m))return ke(t,3,"Bad code word");N.c=16383&(u[d+4]<<8|u[d+3]),N.Td=u[d+4]>>6,N.i=16383&(u[d+6]<<8|u[d+5]),N.Ud=u[d+6]>>6,d+=7,m-=7,t.za=N.c+15>>4,t.Ub=N.i+15>>4,r.width=N.c,r.height=N.i,r.Da=0,r.j=0,r.v=0,r.va=r.width,r.o=r.height,r.da=0,r.ib=r.width,r.hb=r.height,r.U=r.width,r.T=r.height,c((w=t.Pa).jb,0,255,w.jb.length),e((w=t.Qa)!=null),w.Cb=0,w.Bb=0,w.Fb=1,c(w.Zb,0,0,w.Zb.length),c(w.Lb,0,0,w.Lb)}if(y.ub>m)return ke(t,7,"bad partition length");at(w=t.m,u,d,y.ub),d+=y.ub,m-=y.ub,y.Rb&&(N.Ld=et(w),N.Kd=et(w)),N=t.Qa;var x,k=t.Pa;if(e(w!=null),e(N!=null),N.Cb=et(w),N.Cb){if(N.Bb=et(w),et(w)){for(N.Fb=et(w),x=0;4>x;++x)N.Zb[x]=et(w)?lt(w,7):0;for(x=0;4>x;++x)N.Lb[x]=et(w)?lt(w,6):0}if(N.Bb)for(x=0;3>x;++x)k.jb[x]=et(w)?nt(w,8):255}else N.Bb=0;if(w.Ka)return ke(t,3,"cannot parse segment header");if((N=t.ed).zd=et(w),N.Tb=nt(w,6),N.wb=nt(w,3),N.Pc=et(w),N.Pc&&et(w)){for(k=0;4>k;++k)et(w)&&(N.vd[k]=lt(w,6));for(k=0;4>k;++k)et(w)&&(N.od[k]=lt(w,6))}if(t.L=N.Tb==0?0:N.zd?1:2,w.Ka)return ke(t,3,"cannot parse filter header");var U=m;if(m=x=d,d=x+U,N=U,t.Xb=(1<N&&(K=N),at(t.Jc[+U],u,x,K),x+=K,N-=K,m+=3}at(t.Jc[+k],u,x,N),u=xK;++K){if(U.Cb){var Z=U.Zb[K];U.Fb||(Z+=u)}else{if(0>16,8>G.Eb[1]&&(G.Eb[1]=8),G.Qc[0]=Ho[ln(Z+k,117)],G.Qc[1]=Wo[ln(Z+x,127)],G.lc=Z+x}if(!y.Rb)return ke(t,4,"Not a key frame.");for(et(w),y=t.Pa,u=0;4>u;++u){for(m=0;8>m;++m)for(d=0;3>d;++d)for(N=0;11>N;++N)k=rt(w,$c[u][m][d][N])?nt(w,8):Kc[u][m][d][N],y.Wc[u][m].Yb[d][N]=k;for(m=0;17>m;++m)y.Xc[u][m]=y.Wc[u][Qc[m]]}return t.kc=et(w),t.kc&&(t.Bd=nt(w,8)),t.cb=1}function wa(t,r,u,d,m,w,y){var N=r[m].Yb[u];for(u=0;16>m;++m){if(!rt(t,N[u+0]))return m;for(;!rt(t,N[u+1]);)if(N=r[++m].Yb[0],u=0,m==16)return 16;var x=r[m+1].Yb;if(rt(t,N[u+2])){var k=t,U=0;if(rt(k,(Z=N)[(K=u)+3]))if(rt(k,Z[K+6])){for(N=0,K=2*(U=rt(k,Z[K+8]))+(Z=rt(k,Z[K+9+U])),U=0,Z=Jc[K];Z[N];++N)U+=U+rt(k,Z[N]);U+=3+(8<(k=t).b&&Q(k);var K,Z=k.b,G=(K=k.Ca>>1)-(k.I>>Z)>>31;--k.b,k.Ca+=G,k.Ca|=1,k.I-=(K+1&G)<>4,t.zb=r.j-u>>4,0>t.yb&&(t.yb=0),0>t.zb&&(t.zb=0)),t.Va=r.o+15+u>>4,t.Hb=r.va+15+u>>4,t.Hb>t.za&&(t.Hb=t.za),t.Va>t.Ub&&(t.Va=t.Ub),0u;++u){var m;if(t.Qa.Cb){var w=t.Qa.Lb[u];t.Qa.Fb||(w+=d.Tb)}else w=d.Tb;for(m=0;1>=m;++m){var y=t.gd[u][m],N=w;if(d.Pc&&(N+=d.vd[0],m&&(N+=d.od[0])),0<(N=0>N?0:63>2:x>>1)>9-d.wb&&(x=9-d.wb),1>x&&(x=1),y.dd=x,y.tc=2*N+x,y.ld=40<=N?2:15<=N?1:0}else y.tc=0;y.La=m}}}u=0}else ke(t,6,"Frame setup failed"),u=t.a;if(u=u==0){if(u){t.$c=0,0t.Vb){if(t.Vb=0,t.Ec=o(y),t.Fc=0,t.Ec==null){u=ke(t,1,"no memory during frame initialization.");break t}t.Vb=y}y=t.Ec,N=t.Fc,t.Ac=y,t.Bc=N,N+=d,t.Gd=l(k,ma),t.Hd=0,t.rb=l(U+1,ga),t.sb=1,t.wa=K?l(K,ni):null,t.Y=0,t.D.Nb=0,t.D.wa=t.wa,t.D.Y=t.Y,0=u;++u)Ss[255+u]=0>u?-u:u;for(u=-1020;1020>=u;++u)_s[1020+u]=-128>u?-128:127=u;++u)Ps[112+u]=-16>u?-16:15=u;++u)ks[255+u]=0>u?0:255mt;++mt){var ae,ne=Rt[0+mt];for(ae=0;4>ae;++ae){ne=Zc[Ot[St+ae]][ne];for(var me=Os[rt(bt,ne[0])];0>3;for(me=0;256>me;me+=16)mt[se+me]=sn}Me=1,on=St[0]}var he=15&bt.la,fn=15&le.la;for(me=0;4>me;++me){var dn=1&fn;for(sn=Zt=0;4>sn;++sn)he=he>>1|(dn=(Ee=$i(Ot,on,Ee=dn+(1&he),_t.Sc,Me,mt,se))>Me)<<7,Zt=Zt<<2|(3>=4,fn=fn>>1|dn<<7,ae=(ae<<8|Zt)>>>0}for(on=he,Me=fn>>4,pe=0;4>pe;pe+=2){for(Zt=0,he=bt.la>>4+pe,fn=le.la>>4+pe,me=0;2>me;++me){for(dn=1&fn,sn=0;2>sn;++sn)Ee=dn+(1&he),he=he>>1|(dn=0<(Ee=$i(Ot,St[2],Ee,_t.Qc,0,mt,se)))<<3,Zt=Zt<<2|(3>=2,fn=fn>>1|dn<<5}ne|=Zt<<4*pe,on|=he<<4<=H.zb&&H.M<=H.Va,H.Aa==0)t:{if(it.M=H.M,it.uc=bt,Wi(H,it),pt=1,it=(Zt=H.D).Nb,bt=(ne=Wa[H.L])*H.R,Ot=ne/2*H.B,me=16*it*H.R,sn=8*it*H.B,St=H.sa,Rt=H.ta-bt+me,_t=H.qa,mt=H.ra-Ot+sn,se=H.Ha,le=H.Ia-Ot+sn,fn=(he=Zt.M)==0,ae=he>=H.Va-1,H.Aa==2&&Wi(H,Zt),Zt.uc)for(dn=(Ee=H).D.M,e(Ee.D.uc),Zt=Ee.yb;ZtV.o&&(he=V.o),V.F=null,V.J=null,H.Fa!=null&&0>1),V.W+=H.B*(ne>>1),V.F!=null&&(V.J+=V.width*ne)),Zt>1,V.W+=V.v>>1,V.F!=null&&(V.J+=V.v),V.ka=Zt-V.j,V.U=V.va-V.v,V.T=he-Zt,pt=V.put(V))}it+1!=H.Ic||ae||(a(H.sa,H.ta-bt,St,Rt+16*H.R,bt),a(H.qa,H.ra-Ot,_t,mt+8*H.B,Ot),a(H.Ha,H.Ia-Ot,se,le+8*H.B,Ot))}if(!pt)return ke(G,6,"Output aborted.")}return 1}(t,r)),r.bc!=null&&r.bc(r),u&=1}return u?(t.cb=0,u):0}function _n(t,r,u,d,m){m=t[r+u+32*d]+(m>>3),t[r+u+32*d]=-256&m?0>m?0:255:m}function ii(t,r,u,d,m,w){_n(t,r,0,u,d+m),_n(t,r,1,u,d+w),_n(t,r,2,u,d-w),_n(t,r,3,u,d-m)}function nn(t){return(20091*t>>16)+t}function Ci(t,r,u,d){var m,w=0,y=o(16);for(m=0;4>m;++m){var N=t[r+0]+t[r+8],x=t[r+0]-t[r+8],k=(35468*t[r+4]>>16)-nn(t[r+12]),U=nn(t[r+4])+(35468*t[r+12]>>16);y[w+0]=N+U,y[w+1]=x+k,y[w+2]=x-k,y[w+3]=N-U,w+=4,r++}for(m=w=0;4>m;++m)N=(t=y[w+0]+4)+y[w+8],x=t-y[w+8],k=(35468*y[w+4]>>16)-nn(y[w+12]),_n(u,d,0,0,N+(U=nn(y[w+4])+(35468*y[w+12]>>16))),_n(u,d,1,0,x+k),_n(u,d,2,0,x-k),_n(u,d,3,0,N-U),w++,d+=32}function ya(t,r,u,d){var m=t[r+0]+4,w=35468*t[r+4]>>16,y=nn(t[r+4]),N=35468*t[r+1]>>16;ii(u,d,0,m+y,t=nn(t[r+1]),N),ii(u,d,1,m+w,t,N),ii(u,d,2,m-w,t,N),ii(u,d,3,m-y,t,N)}function bo(t,r,u,d,m){Ci(t,r,u,d),m&&Ci(t,r+16,u,d+4)}function La(t,r,u,d){bi(t,r+0,u,d,1),bi(t,r+32,u,d+128,1)}function wo(t,r,u,d){var m;for(t=t[r+0]+4,m=0;4>m;++m)for(r=0;4>r;++r)_n(u,d,r,m,t)}function Na(t,r,u,d){t[r+0]&&jn(t,r+0,u,d),t[r+16]&&jn(t,r+16,u,d+4),t[r+32]&&jn(t,r+32,u,d+128),t[r+48]&&jn(t,r+48,u,d+128+4)}function yo(t,r,u,d){var m,w=o(16);for(m=0;4>m;++m){var y=t[r+0+m]+t[r+12+m],N=t[r+4+m]+t[r+8+m],x=t[r+4+m]-t[r+8+m],k=t[r+0+m]-t[r+12+m];w[0+m]=y+N,w[8+m]=y-N,w[4+m]=k+x,w[12+m]=k-x}for(m=0;4>m;++m)y=(t=w[0+4*m]+3)+w[3+4*m],N=w[1+4*m]+w[2+4*m],x=w[1+4*m]-w[2+4*m],k=t-w[3+4*m],u[d+0]=y+N>>3,u[d+16]=k+x>>3,u[d+32]=y-N>>3,u[d+48]=k-x>>3,d+=64}function ji(t,r,u){var d,m=r-32,w=hn,y=255-t[m-1];for(d=0;du;++u)a(t,r+32*u,t,r-32,16)}function ai(t,r){var u;for(u=16;0d;++d)c(r,u+32*d,t,16)}function Aa(t,r){var u,d=16;for(u=0;16>u;++u)d+=t[r-1+32*u]+t[r+u-32];oi(d>>5,t,r)}function Ge(t,r){var u,d=8;for(u=0;16>u;++u)d+=t[r-1+32*u];oi(d>>4,t,r)}function xo(t,r){var u,d=8;for(u=0;16>u;++u)d+=t[r+u-32];oi(d>>4,t,r)}function xa(t,r){oi(128,t,r)}function Vt(t,r,u){return t+2*r+u+2>>2}function So(t,r){var u,d=r-32;for(d=new Uint8Array([Vt(t[d-1],t[d+0],t[d+1]),Vt(t[d+0],t[d+1],t[d+2]),Vt(t[d+1],t[d+2],t[d+3]),Vt(t[d+2],t[d+3],t[d+4])]),u=0;4>u;++u)a(t,r+32*u,d,0,d.length)}function _o(t,r){var u=t[r-1],d=t[r-1+32],m=t[r-1+64],w=t[r-1+96];At(t,r+0,16843009*Vt(t[r-1-32],u,d)),At(t,r+32,16843009*Vt(u,d,m)),At(t,r+64,16843009*Vt(d,m,w)),At(t,r+96,16843009*Vt(m,w,w))}function Vn(t,r){var u,d=4;for(u=0;4>u;++u)d+=t[r+u-32]+t[r-1+32*u];for(d>>=3,u=0;4>u;++u)c(t,r+32*u,d,4)}function Sa(t,r){var u=t[r-1+0],d=t[r-1+32],m=t[r-1+64],w=t[r-1-32],y=t[r+0-32],N=t[r+1-32],x=t[r+2-32],k=t[r+3-32];t[r+0+96]=Vt(d,m,t[r-1+96]),t[r+1+96]=t[r+0+64]=Vt(u,d,m),t[r+2+96]=t[r+1+64]=t[r+0+32]=Vt(w,u,d),t[r+3+96]=t[r+2+64]=t[r+1+32]=t[r+0+0]=Vt(y,w,u),t[r+3+64]=t[r+2+32]=t[r+1+0]=Vt(N,y,w),t[r+3+32]=t[r+2+0]=Vt(x,N,y),t[r+3+0]=Vt(k,x,N)}function _a(t,r){var u=t[r+1-32],d=t[r+2-32],m=t[r+3-32],w=t[r+4-32],y=t[r+5-32],N=t[r+6-32],x=t[r+7-32];t[r+0+0]=Vt(t[r+0-32],u,d),t[r+1+0]=t[r+0+32]=Vt(u,d,m),t[r+2+0]=t[r+1+32]=t[r+0+64]=Vt(d,m,w),t[r+3+0]=t[r+2+32]=t[r+1+64]=t[r+0+96]=Vt(m,w,y),t[r+3+32]=t[r+2+64]=t[r+1+96]=Vt(w,y,N),t[r+3+64]=t[r+2+96]=Vt(y,N,x),t[r+3+96]=Vt(N,x,x)}function si(t,r){var u=t[r-1+0],d=t[r-1+32],m=t[r-1+64],w=t[r-1-32],y=t[r+0-32],N=t[r+1-32],x=t[r+2-32],k=t[r+3-32];t[r+0+0]=t[r+1+64]=w+y+1>>1,t[r+1+0]=t[r+2+64]=y+N+1>>1,t[r+2+0]=t[r+3+64]=N+x+1>>1,t[r+3+0]=x+k+1>>1,t[r+0+96]=Vt(m,d,u),t[r+0+64]=Vt(d,u,w),t[r+0+32]=t[r+1+96]=Vt(u,w,y),t[r+1+32]=t[r+2+96]=Vt(w,y,N),t[r+2+32]=t[r+3+96]=Vt(y,N,x),t[r+3+32]=Vt(N,x,k)}function Oi(t,r){var u=t[r+0-32],d=t[r+1-32],m=t[r+2-32],w=t[r+3-32],y=t[r+4-32],N=t[r+5-32],x=t[r+6-32],k=t[r+7-32];t[r+0+0]=u+d+1>>1,t[r+1+0]=t[r+0+64]=d+m+1>>1,t[r+2+0]=t[r+1+64]=m+w+1>>1,t[r+3+0]=t[r+2+64]=w+y+1>>1,t[r+0+32]=Vt(u,d,m),t[r+1+32]=t[r+0+96]=Vt(d,m,w),t[r+2+32]=t[r+1+96]=Vt(m,w,y),t[r+3+32]=t[r+2+96]=Vt(w,y,N),t[r+3+64]=Vt(y,N,x),t[r+3+96]=Vt(N,x,k)}function Po(t,r){var u=t[r-1+0],d=t[r-1+32],m=t[r-1+64],w=t[r-1+96];t[r+0+0]=u+d+1>>1,t[r+2+0]=t[r+0+32]=d+m+1>>1,t[r+2+32]=t[r+0+64]=m+w+1>>1,t[r+1+0]=Vt(u,d,m),t[r+3+0]=t[r+1+32]=Vt(d,m,w),t[r+3+32]=t[r+1+64]=Vt(m,w,w),t[r+3+64]=t[r+2+64]=t[r+0+96]=t[r+1+96]=t[r+2+96]=t[r+3+96]=w}function ko(t,r){var u=t[r-1+0],d=t[r-1+32],m=t[r-1+64],w=t[r-1+96],y=t[r-1-32],N=t[r+0-32],x=t[r+1-32],k=t[r+2-32];t[r+0+0]=t[r+2+32]=u+y+1>>1,t[r+0+32]=t[r+2+64]=d+u+1>>1,t[r+0+64]=t[r+2+96]=m+d+1>>1,t[r+0+96]=w+m+1>>1,t[r+3+0]=Vt(N,x,k),t[r+2+0]=Vt(y,N,x),t[r+1+0]=t[r+3+32]=Vt(u,y,N),t[r+1+32]=t[r+3+64]=Vt(d,u,y),t[r+1+64]=t[r+3+96]=Vt(m,d,u),t[r+1+96]=Vt(w,m,d)}function Fo(t,r){var u;for(u=0;8>u;++u)a(t,r+32*u,t,r-32,8)}function Bi(t,r){var u;for(u=0;8>u;++u)c(t,r,t[r-1],8),r+=32}function qr(t,r,u){var d;for(d=0;8>d;++d)c(r,u+32*d,t,8)}function hr(t,r){var u,d=8;for(u=0;8>u;++u)d+=t[r+u-32]+t[r-1+32*u];qr(d>>4,t,r)}function Io(t,r){var u,d=4;for(u=0;8>u;++u)d+=t[r+u-32];qr(d>>3,t,r)}function Dr(t,r){var u,d=4;for(u=0;8>u;++u)d+=t[r-1+32*u];qr(d>>3,t,r)}function Mi(t,r){qr(128,t,r)}function ci(t,r,u){var d=t[r-u],m=t[r+0],w=3*(m-d)+Do[1020+t[r-2*u]-t[r+u]],y=Ea[112+(w+4>>3)];t[r-u]=hn[255+d+Ea[112+(w+3>>3)]],t[r+0]=hn[255+m-y]}function Pa(t,r,u,d){var m=t[r+0],w=t[r+u];return vn[255+t[r-2*u]-t[r-u]]>d||vn[255+w-m]>d}function ka(t,r,u,d){return 4*vn[255+t[r-u]-t[r+0]]+vn[255+t[r-2*u]-t[r+u]]<=d}function Fa(t,r,u,d,m){var w=t[r-3*u],y=t[r-2*u],N=t[r-u],x=t[r+0],k=t[r+u],U=t[r+2*u],K=t[r+3*u];return 4*vn[255+N-x]+vn[255+y-k]>d?0:vn[255+t[r-4*u]-w]<=m&&vn[255+w-y]<=m&&vn[255+y-N]<=m&&vn[255+K-U]<=m&&vn[255+U-k]<=m&&vn[255+k-x]<=m}function Ia(t,r,u,d){var m=2*d+1;for(d=0;16>d;++d)ka(t,r+d,u,m)&&ci(t,r+d,u)}function er(t,r,u,d){var m=2*d+1;for(d=0;16>d;++d)ka(t,r+d*u,1,m)&&ci(t,r+d*u,1)}function fr(t,r,u,d){var m;for(m=3;0>7,V=18*pt+63>>7,pt=9*pt+63>>7;x[k-3*U]=hn[255+x[k-3*U]+pt],x[k-2*U]=hn[255+K+V],x[k-U]=hn[255+Z+H],x[k+0]=hn[255+G-H],x[k+U]=hn[255+vt-V],x[k+2*U]=hn[255+it-pt]}r+=d}}function Pn(t,r,u,d,m,w,y,N){for(w=2*w+1;0>3)],it=Ea[112+(it+3>>3)],H=vt+1>>1;x[k-2*U]=hn[255+x[k-2*U]+H],x[k-U]=hn[255+K+it],x[k+0]=hn[255+Z-vt],x[k+U]=hn[255+G-H]}r+=d}}function Ei(t,r,u,d,m,w){dr(t,r,u,1,16,d,m,w)}function Rr(t,r,u,d,m,w){dr(t,r,1,u,16,d,m,w)}function jo(t,r,u,d,m,w){var y;for(y=3;0k?0:255:k)&255,k=x,m[w+N]=U}}function Ui(t,r,u,d){var m=r.width,w=r.o;if(e(t!=null&&r!=null),0>u||0>=d||u+d>w)return null;if(!t.Cc){if(t.ga==null){var y;if(t.ga=new hi,(y=t.ga==null)||(y=r.width*r.o,e(t.Gb.length==0),t.Gb=o(y),t.Uc=0,t.Gb==null?y=0:(t.mb=t.Gb,t.nb=t.Uc,t.rc=null,y=1),y=!y),!y){y=t.ga;var N=t.Fa,x=t.P,k=t.qc,U=t.mb,K=t.nb,Z=x+1,G=k-1,vt=y.l;if(e(N!=null&&U!=null&&r!=null),Lr[0]=null,Lr[1]=Tr,Lr[2]=zi,Lr[3]=pr,y.ca=U,y.tb=K,y.c=r.width,y.i=r.height,e(0=k)r=0;else if(y.$a=N[x+0]>>0&3,y.Z=N[x+0]>>2&3,y.Lc=N[x+0]>>4&3,x=N[x+0]>>6&3,0>y.$a||1=y.c*y.i;y=!r}if(y)return null;t.ga.Lc!=1?t.Ga=0:d=w-u}e(t.ga!=null),e(u+d<=w);t:{if(r=(N=t.ga).c,w=N.l.o,N.$a==0){if(Z=t.rc,G=t.Vc,vt=t.Fa,x=t.P+1+u*r,k=t.mb,U=t.nb+u*r,e(x<=t.P+t.qc),N.Z!=0)for(e(Lr[N.Z]!=null),y=0;y=r)r=1;else if(N.ic||J(),N.ic){N=y.V,Z=y.Ba,G=y.c;var it=y.i,H=(vt=1,x=y.$/G,k=y.$%G,U=y.m,K=y.s,y.$),V=G*it,pt=G*r,bt=K.wc,mt=H(it=en(mt.G[0],mt.H[0],U)))N[Z+H]=it,++H,++k>=G&&(k=0,++x<=r&&!(x%16)&&xn(y,x));else{if(!(280>it)){vt=0;break e}it=Nn(it-256,U);var Ot,St=en(mt.G[4],mt.H[4],U);if(Y(U),!(H>=(St=Un(G,St=Nn(St,U)))&&V-H>=it)){vt=0;break e}for(Ot=0;Ot=G;)k-=G,++x<=r&&!(x%16)&&xn(y,x);Hr?r:x);break e}!vt||U.h&&H=w&&(t.Cc=1),d=1}if(!d)return null;if(t.Cc&&((d=t.ga)!=null&&(d.mc=null),t.ga=null,0>23,N[x+4*y+1]=N[x+4*y+1]*K>>23,N[x+4*y+2]=N[x+4*y+2]*K>>23)}r+=w}}function v(t,r,u,d,m){for(;0>4)*x>>16;t[r+2*w+0]=(240&y|y>>4)*x>>16&240|(15&y|y<<4)*x>>16>>4&15,t[r+2*w+1]=240&k|N}r+=m}}function C(t,r,u,d,m,w,y,N){var x,k,U=255;for(k=0;k>8}function J(){wr=s,yi=v,Ma=C,xs=T}function st(t,r,u){R[t]=function(d,m,w,y,N,x,k,U,K,Z,G,vt,it,H,V,pt,bt){var mt,Ot=bt-1>>1,St=N[x+0]|k[U+0]<<16,Rt=K[Z+0]|G[vt+0]<<16;e(d!=null);var _t=3*St+Rt+131074>>2;for(r(d[m+0],255&_t,_t>>16,it,H),w!=null&&(_t=3*Rt+St+131074>>2,r(w[y+0],255&_t,_t>>16,V,pt)),mt=1;mt<=Ot;++mt){var se=N[x+mt]|k[U+mt]<<16,le=K[Z+mt]|G[vt+mt]<<16,ae=St+se+Rt+le+524296,ne=ae+2*(se+Rt)>>3;_t=ne+St>>1,St=(ae=ae+2*(St+le)>>3)+se>>1,r(d[m+2*mt-1],255&_t,_t>>16,it,H+(2*mt-1)*u),r(d[m+2*mt-0],255&St,St>>16,it,H+(2*mt-0)*u),w!=null&&(_t=ae+Rt>>1,St=ne+le>>1,r(w[y+2*mt-1],255&_t,_t>>16,V,pt+(2*mt-1)*u),r(w[y+2*mt+0],255&St,St>>16,V,pt+(2*mt+0)*u)),St=se,Rt=le}1&bt||(_t=3*St+Rt+131074>>2,r(d[m+bt-1],255&_t,_t>>16,it,H+(bt-1)*u),w!=null&&(_t=3*Rt+St+131074>>2,r(w[y+bt-1],255&_t,_t>>16,V,pt+(bt-1)*u)))}}function yt(){bn[qa]=eu,bn[Da]=Ms,bn[Is]=nu,bn[Ra]=Es,bn[Ta]=qs,bn[Ro]=Ds,bn[Cs]=ru,bn[To]=Ms,bn[zo]=Es,bn[za]=qs,bn[Uo]=Ds}function jt(t){return t&~iu?0>t?0:255:t>>Rs}function Dt(t,r){return jt((19077*t>>8)+(26149*r>>8)-14234)}function Kt(t,r,u){return jt((19077*t>>8)-(6419*r>>8)-(13320*u>>8)+8708)}function Qt(t,r){return jt((19077*t>>8)+(33050*r>>8)-17685)}function re(t,r,u,d,m){d[m+0]=Dt(t,u),d[m+1]=Kt(t,r,u),d[m+2]=Qt(t,r)}function Ne(t,r,u,d,m){d[m+0]=Qt(t,r),d[m+1]=Kt(t,r,u),d[m+2]=Dt(t,u)}function Se(t,r,u,d,m){var w=Kt(t,r,u);r=w<<3&224|Qt(t,r)>>3,d[m+0]=248&Dt(t,u)|w>>5,d[m+1]=r}function Be(t,r,u,d,m){var w=240&Qt(t,r)|15;d[m+0]=240&Dt(t,u)|Kt(t,r,u)>>4,d[m+1]=w}function Ye(t,r,u,d,m){d[m+0]=255,re(t,r,u,d,m+1)}function Te(t,r,u,d,m){Ne(t,r,u,d,m),d[m+3]=255}function kn(t,r,u,d,m){re(t,r,u,d,m),d[m+3]=255}function ln(t,r){return 0>t?0:t>r?r:t}function nr(t,r,u){R[t]=function(d,m,w,y,N,x,k,U,K){for(var Z=U+(-2&K)*u;U!=Z;)r(d[m+0],w[y+0],N[x+0],k,U),r(d[m+1],w[y+0],N[x+0],k,U+u),m+=2,++y,++x,U+=2*u;1&K&&r(d[m+0],w[y+0],N[x+0],k,U)}}function Oa(t,r,u){return u==0?t==0?r==0?6:5:r==0?4:0:u}function Hi(t,r,u,d,m){switch(t>>>30){case 3:bi(r,u,d,m,0);break;case 2:Ki(r,u,d,m);break;case 1:jn(r,u,d,m)}}function Wi(t,r){var u,d,m=r.M,w=r.Nb,y=t.oc,N=t.pc+40,x=t.oc,k=t.pc+584,U=t.oc,K=t.pc+600;for(u=0;16>u;++u)y[N+32*u-1]=129;for(u=0;8>u;++u)x[k+32*u-1]=129,U[K+32*u-1]=129;for(0u;++u)a(y,N+32*u-4,y,N+32*u+12,4);for(u=-1;8>u;++u)a(x,k+32*u-4,x,k+32*u+4,4),a(U,K+32*u-4,U,K+32*u+4,4)}var G=t.Gd,vt=t.Hd+d,it=Z.ad,H=Z.Hc;if(0=t.za-1?c(V,pt,G[vt].y[15],4):a(V,pt,G[vt+1].y,0,4)),u=0;4>u;u++)V[pt+128+u]=V[pt+256+u]=V[pt+384+u]=V[pt+0+u];for(u=0;16>u;++u,H<<=2)V=y,pt=N+zs[u],On[Z.Ob[u]](V,pt),Hi(H,it,16*+u,V,pt)}else if(V=Oa(d,m,Z.Ob[0]),yr[V](y,N),H!=0)for(u=0;16>u;++u,H<<=2)Hi(H,it,16*+u,y,N+zs[u]);for(u=Z.Gc,V=Oa(d,m,Z.Dd),sr[V](x,k),sr[V](U,K),H=it,V=x,pt=k,255&(Z=u>>0)&&(170&Z?vr(H,256,V,pt):ir(H,256,V,pt)),Z=U,H=K,255&(u>>=8)&&(170&u?vr(it,320,Z,H):ir(it,320,Z,H)),mu;++u)a(G,vt+u*t.R,y,N+32*u,16);for(u=0;8>u;++u)a(it,Z+u*t.B,x,k+32*u,8),a(H,V+u*t.B,U,K+32*u,8)}}function fi(t,r,u,d,m,w,y,N,x){var k=[0],U=[0],K=0,Z=x!=null?x.kd:0,G=x??new Ri;if(t==null||12>u)return 7;G.data=t,G.w=r,G.ha=u,r=[r],u=[u],G.gb=[G.gb];t:{var vt=r,it=u,H=G.gb;if(e(t!=null),e(it!=null),e(H!=null),H[0]=0,12<=it[0]&&!n(t,vt[0],"RIFF")){if(n(t,vt[0]+8,"WEBP")){H=3;break t}var V=Bt(t,vt[0]+4);if(12>V||4294967286it[0]-8){H=7;break t}H[0]=V,vt[0]+=12,it[0]-=12}H=0}if(H!=0)return H;for(V=0H[0])H=7;else{if(!n(pt,it[0],"VP8X")){if(Bt(pt,it[0]+4)!=10){H=3;break t}if(18>H[0]){H=7;break t}var St=Bt(pt,it[0]+8),Rt=1+Ct(pt,it[0]+12);if(2147483648<=Rt*(pt=1+Ct(pt,it[0]+15))){H=3;break t}Ot!=null&&(Ot[0]=St),bt!=null&&(bt[0]=Rt),mt!=null&&(mt[0]=pt),it[0]+=18,H[0]-=18,_t[0]=1}H=0}}if(K=K[0],vt=vt[0],H!=0)return H;if(it=!!(2&vt),!V&&K)return 3;if(w!=null&&(w[0]=!!(16&vt)),y!=null&&(y[0]=it),N!=null&&(N[0]=0),y=k[0],vt=U[0],K&&it&&x==null){H=0;break}if(4>u){H=7;break}if(V&&K||!V&&!K&&!n(t,r[0],"ALPH")){u=[u],G.na=[G.na],G.P=[G.P],G.Sa=[G.Sa];t:{St=t,H=r,V=u;var _t=G.gb;bt=G.na,mt=G.P,Ot=G.Sa,Rt=22,e(St!=null),e(V!=null),pt=H[0];var se=V[0];for(e(bt!=null),e(Ot!=null),bt[0]=null,mt[0]=null,Ot[0]=0;;){if(H[0]=pt,V[0]=se,8>se){H=7;break t}var le=Bt(St,pt+4);if(4294967286_t){H=3;break t}if(!n(St,pt,"VP8 ")||!n(St,pt,"VP8L")){H=0;break t}if(se[0]V[0])H=7;else{if(pt||Rt){if(_t=Bt(_t,St+4),12<=bt&&_t>bt-12){H=3;break t}if(Z&&_t>V[0]-8){H=7;break t}mt[0]=_t,H[0]+=8,V[0]-=8,Ot[0]=Rt}else Ot[0]=5<=V[0]&&_t[St+0]==47&&!(_t[St+4]>>5),mt[0]=V[0];H=0}if(u=u[0],G.Ja=G.Ja[0],G.xa=G.xa[0],r=r[0],H!=0)break;if(4294967286u){H=7;break}N=y,Z=vt,it=w,t==null||5>u?t=0:5<=u&&t[r+0]==47&&!(t[r+4]>>5)?(V=[0],_t=[0],bt=[0],$(mt=new L,t,r,u),zt(mt,V,_t,bt)?(N!=null&&(N[0]=V[0]),Z!=null&&(Z[0]=_t[0]),it!=null&&(it[0]=bt[0]),t=1):t=0):t=0}else{if(10>u){H=7;break}N=vt,t==null||10>u||!va(t,r+3,u-3)?t=0:(Z=t[r+0]|t[r+1]<<8|t[r+2]<<16,it=16383&(t[r+7]<<8|t[r+6]),t=16383&(t[r+9]<<8|t[r+8]),1&Z||3<(Z>>1&7)||!(Z>>4&1)||Z>>5>=G.Ja||!it||!t?t=0:(y&&(y[0]=it),N&&(N[0]=t),t=1))}if(!t||(y=y[0],vt=vt[0],K&&(k[0]!=y||U[0]!=vt)))return 3;x!=null&&(x[0]=G,x.offset=r-x.w,e(4294967286>r-x.w),e(x.offset==x.ha-u));break}return H==0||H==7&&K&&x==null?(w!=null&&(w[0]|=G.na!=null&&0u||(w&=-2,y&=-2),0>w||0>y||0>=N||0>=x||w+N>d||y+x>m))return 0;if(r.v=w,r.j=y,r.va=w+N,r.o=y+x,r.U=N,r.T=x,r.da=t!=null&&0t.S){var r=t.f.RGBA;r.fb+=(t.height-1)*r.A,r.A=-r.A}else r=t.f.kb,t=t.height,r.O+=(t-1)*r.fa,r.fa=-r.fa,r.N+=(t-1>>1)*r.Ab,r.Ab=-r.Ab,r.W+=(t-1>>1)*r.Db,r.Db=-r.Db,r.F!=null&&(r.J+=(t-1)*r.lb,r.lb=-r.lb);return 0}function di(t,r,u,d){if(d==null||0>=t||0>=r)return 2;if(u!=null){if(u.Da){var m=u.cd,w=u.bd,y=-2&u.v,N=-2&u.j;if(0>y||0>N||0>=m||0>=w||y+m>t||N+w>r)return 2;t=m,r=w}if(u.da){if(!Xt(t,r,m=[u.ib],w=[u.hb]))return 2;t=m[0],r=w[0]}}d.width=t,d.height=r;t:{var x=d.width,k=d.height;if(t=d.S,0>=x||0>=k||!(t>=qa&&13>t))t=2;else{if(0>=d.Rd&&d.sd==null){y=w=m=r=0;var U=(N=x*Us[t])*k;if(11>t||(w=(k+1)/2*(r=(x+1)/2),t==12&&(y=(m=x)*k)),(k=o(U+2*w+y))==null){t=1;break t}d.sd=k,11>t?((x=d.f.RGBA).eb=k,x.fb=0,x.A=N,x.size=U):((x=d.f.kb).y=k,x.O=0,x.fa=N,x.Fd=U,x.f=k,x.N=0+U,x.Ab=r,x.Cd=w,x.ea=k,x.W=0+U+w,x.Db=r,x.Ed=w,t==12&&(x.F=k,x.J=0+U+2*w),x.Tc=y,x.lb=m)}if(r=1,m=d.S,w=d.width,y=d.height,m>=qa&&13>m)if(11>m)t=d.f.RGBA,r&=(N=Math.abs(t.A))*(y-1)+w<=t.size,r&=N>=w*Us[m],r&=t.eb!=null;else{t=d.f.kb,N=(w+1)/2,U=(y+1)/2,x=Math.abs(t.fa),k=Math.abs(t.Ab);var K=Math.abs(t.Db),Z=Math.abs(t.lb),G=Z*(y-1)+w;r&=x*(y-1)+w<=t.Fd,r&=k*(U-1)+N<=t.Cd,r=(r&=K*(U-1)+N<=t.Ed)&x>=w&k>=N&K>=N,r&=t.y!=null,r&=t.f!=null,r&=t.ea!=null,m==12&&(r&=Z>=w,r&=G<=t.Tc,r&=t.F!=null)}else r=0;t=r?0:2}}return t!=0||u!=null&&u.fd&&(t=Gi(d)),t}var rn=64,pi=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535,131071,262143,524287,1048575,2097151,4194303,8388607,16777215],gi=24,mi=32,Yi=8,an=[0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7];xt("Predictor0","PredictorAdd0"),R.Predictor0=function(){return 4278190080},R.Predictor1=function(t){return t},R.Predictor2=function(t,r,u){return r[u+0]},R.Predictor3=function(t,r,u){return r[u+1]},R.Predictor4=function(t,r,u){return r[u-1]},R.Predictor5=function(t,r,u){return Pt(Pt(t,r[u+1]),r[u+0])},R.Predictor6=function(t,r,u){return Pt(t,r[u-1])},R.Predictor7=function(t,r,u){return Pt(t,r[u+0])},R.Predictor8=function(t,r,u){return Pt(r[u-1],r[u+0])},R.Predictor9=function(t,r,u){return Pt(r[u+0],r[u+1])},R.Predictor10=function(t,r,u){return Pt(Pt(t,r[u-1]),Pt(r[u+0],r[u+1]))},R.Predictor11=function(t,r,u){var d=r[u+0];return 0>=$t(d>>24&255,t>>24&255,(r=r[u-1])>>24&255)+$t(d>>16&255,t>>16&255,r>>16&255)+$t(d>>8&255,t>>8&255,r>>8&255)+$t(255&d,255&t,255&r)?d:t},R.Predictor12=function(t,r,u){var d=r[u+0];return(qt((t>>24&255)+(d>>24&255)-((r=r[u-1])>>24&255))<<24|qt((t>>16&255)+(d>>16&255)-(r>>16&255))<<16|qt((t>>8&255)+(d>>8&255)-(r>>8&255))<<8|qt((255&t)+(255&d)-(255&r)))>>>0},R.Predictor13=function(t,r,u){var d=r[u-1];return(Gt((t=Pt(t,r[u+0]))>>24&255,d>>24&255)<<24|Gt(t>>16&255,d>>16&255)<<16|Gt(t>>8&255,d>>8&255)<<8|Gt(t>>0&255,d>>0&255))>>>0};var Mo=R.PredictorAdd0;R.PredictorAdd1=te,xt("Predictor2","PredictorAdd2"),xt("Predictor3","PredictorAdd3"),xt("Predictor4","PredictorAdd4"),xt("Predictor5","PredictorAdd5"),xt("Predictor6","PredictorAdd6"),xt("Predictor7","PredictorAdd7"),xt("Predictor8","PredictorAdd8"),xt("Predictor9","PredictorAdd9"),xt("Predictor10","PredictorAdd10"),xt("Predictor11","PredictorAdd11"),xt("Predictor12","PredictorAdd12"),xt("Predictor13","PredictorAdd13");var Ji=R.PredictorAdd2;ee("ColorIndexInverseTransform","MapARGB","32b",function(t){return t>>8&255},function(t){return t}),ee("VP8LColorIndexInverseTransformAlpha","MapAlpha","8b",function(t){return t},function(t){return t>>8&255});var Ba,Fn=R.ColorIndexInverseTransform,Xi=R.MapARGB,Eo=R.VP8LColorIndexInverseTransformAlpha,qo=R.MapAlpha,gr=R.VP8LPredictorsAdd=[];gr.length=16,(R.VP8LPredictors=[]).length=16,(R.VP8LPredictorsAdd_C=[]).length=16,(R.VP8LPredictors_C=[]).length=16;var gn,In,mr,Gn,rr,vi,Cn,bi,Ki,vr,jn,ir,zr,wi,Ur,br,Zi,mn,ar,be,we,Fe,De,or,wr,yi,Ma,xs,Ss=o(511),_s=o(2041),Ps=o(225),ks=o(767),Fs=0,Do=_s,Ea=Ps,hn=ks,vn=Ss,qa=0,Da=1,Is=2,Ra=3,Ta=4,Ro=5,Cs=6,To=7,zo=8,za=9,Uo=10,zc=[2,3,7],Uc=[3,3,11],js=[280,256,256,256,40],Hc=[0,1,1,1,0],Wc=[17,18,0,1,2,3,4,5,16,6,7,8,9,10,11,12,13,14,15],Vc=[24,7,23,25,40,6,39,41,22,26,38,42,56,5,55,57,21,27,54,58,37,43,72,4,71,73,20,28,53,59,70,74,36,44,88,69,75,52,60,3,87,89,19,29,86,90,35,45,68,76,85,91,51,61,104,2,103,105,18,30,102,106,34,46,84,92,67,77,101,107,50,62,120,1,119,121,83,93,17,31,100,108,66,78,118,122,33,47,117,123,49,63,99,109,82,94,0,116,124,65,79,16,32,98,110,48,115,125,81,95,64,114,126,97,111,80,113,127,96,112],Gc=[2954,2956,2958,2962,2970,2986,3018,3082,3212,3468,3980,5004],Yc=8,Ho=[4,5,6,7,8,9,10,10,11,12,13,14,15,16,17,17,18,19,20,20,21,21,22,22,23,23,24,25,25,26,27,28,29,30,31,32,33,34,35,36,37,37,38,39,40,41,42,43,44,45,46,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,76,77,78,79,80,81,82,83,84,85,86,87,88,89,91,93,95,96,98,100,101,102,104,106,108,110,112,114,116,118,122,124,126,128,130,132,134,136,138,140,143,145,148,151,154,157],Wo=[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,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,119,122,125,128,131,134,137,140,143,146,149,152,155,158,161,164,167,170,173,177,181,185,189,193,197,201,205,209,213,217,221,225,229,234,239,245,249,254,259,264,269,274,279,284],$i=null,Jc=[[173,148,140,0],[176,155,140,135,0],[180,157,141,134,130,0],[254,254,243,230,196,177,153,140,133,130,129,0]],Xc=[0,1,4,8,5,2,3,6,9,12,13,10,7,11,14,15],Os=[-0,1,-1,2,-2,3,4,6,-3,5,-4,-5,-6,7,-7,8,-8,-9],Kc=[[[[128,128,128,128,128,128,128,128,128,128,128],[128,128,128,128,128,128,128,128,128,128,128],[128,128,128,128,128,128,128,128,128,128,128]],[[253,136,254,255,228,219,128,128,128,128,128],[189,129,242,255,227,213,255,219,128,128,128],[106,126,227,252,214,209,255,255,128,128,128]],[[1,98,248,255,236,226,255,255,128,128,128],[181,133,238,254,221,234,255,154,128,128,128],[78,134,202,247,198,180,255,219,128,128,128]],[[1,185,249,255,243,255,128,128,128,128,128],[184,150,247,255,236,224,128,128,128,128,128],[77,110,216,255,236,230,128,128,128,128,128]],[[1,101,251,255,241,255,128,128,128,128,128],[170,139,241,252,236,209,255,255,128,128,128],[37,116,196,243,228,255,255,255,128,128,128]],[[1,204,254,255,245,255,128,128,128,128,128],[207,160,250,255,238,128,128,128,128,128,128],[102,103,231,255,211,171,128,128,128,128,128]],[[1,152,252,255,240,255,128,128,128,128,128],[177,135,243,255,234,225,128,128,128,128,128],[80,129,211,255,194,224,128,128,128,128,128]],[[1,1,255,128,128,128,128,128,128,128,128],[246,1,255,128,128,128,128,128,128,128,128],[255,128,128,128,128,128,128,128,128,128,128]]],[[[198,35,237,223,193,187,162,160,145,155,62],[131,45,198,221,172,176,220,157,252,221,1],[68,47,146,208,149,167,221,162,255,223,128]],[[1,149,241,255,221,224,255,255,128,128,128],[184,141,234,253,222,220,255,199,128,128,128],[81,99,181,242,176,190,249,202,255,255,128]],[[1,129,232,253,214,197,242,196,255,255,128],[99,121,210,250,201,198,255,202,128,128,128],[23,91,163,242,170,187,247,210,255,255,128]],[[1,200,246,255,234,255,128,128,128,128,128],[109,178,241,255,231,245,255,255,128,128,128],[44,130,201,253,205,192,255,255,128,128,128]],[[1,132,239,251,219,209,255,165,128,128,128],[94,136,225,251,218,190,255,255,128,128,128],[22,100,174,245,186,161,255,199,128,128,128]],[[1,182,249,255,232,235,128,128,128,128,128],[124,143,241,255,227,234,128,128,128,128,128],[35,77,181,251,193,211,255,205,128,128,128]],[[1,157,247,255,236,231,255,255,128,128,128],[121,141,235,255,225,227,255,255,128,128,128],[45,99,188,251,195,217,255,224,128,128,128]],[[1,1,251,255,213,255,128,128,128,128,128],[203,1,248,255,255,128,128,128,128,128,128],[137,1,177,255,224,255,128,128,128,128,128]]],[[[253,9,248,251,207,208,255,192,128,128,128],[175,13,224,243,193,185,249,198,255,255,128],[73,17,171,221,161,179,236,167,255,234,128]],[[1,95,247,253,212,183,255,255,128,128,128],[239,90,244,250,211,209,255,255,128,128,128],[155,77,195,248,188,195,255,255,128,128,128]],[[1,24,239,251,218,219,255,205,128,128,128],[201,51,219,255,196,186,128,128,128,128,128],[69,46,190,239,201,218,255,228,128,128,128]],[[1,191,251,255,255,128,128,128,128,128,128],[223,165,249,255,213,255,128,128,128,128,128],[141,124,248,255,255,128,128,128,128,128,128]],[[1,16,248,255,255,128,128,128,128,128,128],[190,36,230,255,236,255,128,128,128,128,128],[149,1,255,128,128,128,128,128,128,128,128]],[[1,226,255,128,128,128,128,128,128,128,128],[247,192,255,128,128,128,128,128,128,128,128],[240,128,255,128,128,128,128,128,128,128,128]],[[1,134,252,255,255,128,128,128,128,128,128],[213,62,250,255,255,128,128,128,128,128,128],[55,93,255,128,128,128,128,128,128,128,128]],[[128,128,128,128,128,128,128,128,128,128,128],[128,128,128,128,128,128,128,128,128,128,128],[128,128,128,128,128,128,128,128,128,128,128]]],[[[202,24,213,235,186,191,220,160,240,175,255],[126,38,182,232,169,184,228,174,255,187,128],[61,46,138,219,151,178,240,170,255,216,128]],[[1,112,230,250,199,191,247,159,255,255,128],[166,109,228,252,211,215,255,174,128,128,128],[39,77,162,232,172,180,245,178,255,255,128]],[[1,52,220,246,198,199,249,220,255,255,128],[124,74,191,243,183,193,250,221,255,255,128],[24,71,130,219,154,170,243,182,255,255,128]],[[1,182,225,249,219,240,255,224,128,128,128],[149,150,226,252,216,205,255,171,128,128,128],[28,108,170,242,183,194,254,223,255,255,128]],[[1,81,230,252,204,203,255,192,128,128,128],[123,102,209,247,188,196,255,233,128,128,128],[20,95,153,243,164,173,255,203,128,128,128]],[[1,222,248,255,216,213,128,128,128,128,128],[168,175,246,252,235,205,255,255,128,128,128],[47,116,215,255,211,212,255,255,128,128,128]],[[1,121,236,253,212,214,255,255,128,128,128],[141,84,213,252,201,202,255,219,128,128,128],[42,80,160,240,162,185,255,205,128,128,128]],[[1,1,255,128,128,128,128,128,128,128,128],[244,1,255,128,128,128,128,128,128,128,128],[238,1,255,128,128,128,128,128,128,128,128]]]],Zc=[[[231,120,48,89,115,113,120,152,112],[152,179,64,126,170,118,46,70,95],[175,69,143,80,85,82,72,155,103],[56,58,10,171,218,189,17,13,152],[114,26,17,163,44,195,21,10,173],[121,24,80,195,26,62,44,64,85],[144,71,10,38,171,213,144,34,26],[170,46,55,19,136,160,33,206,71],[63,20,8,114,114,208,12,9,226],[81,40,11,96,182,84,29,16,36]],[[134,183,89,137,98,101,106,165,148],[72,187,100,130,157,111,32,75,80],[66,102,167,99,74,62,40,234,128],[41,53,9,178,241,141,26,8,107],[74,43,26,146,73,166,49,23,157],[65,38,105,160,51,52,31,115,128],[104,79,12,27,217,255,87,17,7],[87,68,71,44,114,51,15,186,23],[47,41,14,110,182,183,21,17,194],[66,45,25,102,197,189,23,18,22]],[[88,88,147,150,42,46,45,196,205],[43,97,183,117,85,38,35,179,61],[39,53,200,87,26,21,43,232,171],[56,34,51,104,114,102,29,93,77],[39,28,85,171,58,165,90,98,64],[34,22,116,206,23,34,43,166,73],[107,54,32,26,51,1,81,43,31],[68,25,106,22,64,171,36,225,114],[34,19,21,102,132,188,16,76,124],[62,18,78,95,85,57,50,48,51]],[[193,101,35,159,215,111,89,46,111],[60,148,31,172,219,228,21,18,111],[112,113,77,85,179,255,38,120,114],[40,42,1,196,245,209,10,25,109],[88,43,29,140,166,213,37,43,154],[61,63,30,155,67,45,68,1,209],[100,80,8,43,154,1,51,26,71],[142,78,78,16,255,128,34,197,171],[41,40,5,102,211,183,4,1,221],[51,50,17,168,209,192,23,25,82]],[[138,31,36,171,27,166,38,44,229],[67,87,58,169,82,115,26,59,179],[63,59,90,180,59,166,93,73,154],[40,40,21,116,143,209,34,39,175],[47,15,16,183,34,223,49,45,183],[46,17,33,183,6,98,15,32,183],[57,46,22,24,128,1,54,17,37],[65,32,73,115,28,128,23,128,205],[40,3,9,115,51,192,18,6,223],[87,37,9,115,59,77,64,21,47]],[[104,55,44,218,9,54,53,130,226],[64,90,70,205,40,41,23,26,57],[54,57,112,184,5,41,38,166,213],[30,34,26,133,152,116,10,32,134],[39,19,53,221,26,114,32,73,255],[31,9,65,234,2,15,1,118,73],[75,32,12,51,192,255,160,43,51],[88,31,35,67,102,85,55,186,85],[56,21,23,111,59,205,45,37,192],[55,38,70,124,73,102,1,34,98]],[[125,98,42,88,104,85,117,175,82],[95,84,53,89,128,100,113,101,45],[75,79,123,47,51,128,81,171,1],[57,17,5,71,102,57,53,41,49],[38,33,13,121,57,73,26,1,85],[41,10,67,138,77,110,90,47,114],[115,21,2,10,102,255,166,23,6],[101,29,16,10,85,128,101,196,26],[57,18,10,102,102,213,34,20,43],[117,20,15,36,163,128,68,1,26]],[[102,61,71,37,34,53,31,243,192],[69,60,71,38,73,119,28,222,37],[68,45,128,34,1,47,11,245,171],[62,17,19,70,146,85,55,62,70],[37,43,37,154,100,163,85,160,1],[63,9,92,136,28,64,32,201,85],[75,15,9,9,64,255,184,119,16],[86,6,28,5,64,255,25,248,1],[56,8,17,132,137,255,55,116,128],[58,15,20,82,135,57,26,121,40]],[[164,50,31,137,154,133,25,35,218],[51,103,44,131,131,123,31,6,158],[86,40,64,135,148,224,45,183,128],[22,26,17,131,240,154,14,1,209],[45,16,21,91,64,222,7,1,197],[56,21,39,155,60,138,23,102,213],[83,12,13,54,192,255,68,47,28],[85,26,85,85,128,128,32,146,171],[18,11,7,63,144,171,4,4,246],[35,27,10,146,174,171,12,26,128]],[[190,80,35,99,180,80,126,54,45],[85,126,47,87,176,51,41,20,32],[101,75,128,139,118,146,116,128,85],[56,41,15,176,236,85,37,9,62],[71,30,17,119,118,255,17,18,138],[101,38,60,138,55,70,43,26,142],[146,36,19,30,171,255,97,27,20],[138,45,61,62,219,1,81,188,64],[32,41,20,117,151,142,20,21,163],[112,19,12,61,195,128,48,4,24]]],$c=[[[[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[176,246,255,255,255,255,255,255,255,255,255],[223,241,252,255,255,255,255,255,255,255,255],[249,253,253,255,255,255,255,255,255,255,255]],[[255,244,252,255,255,255,255,255,255,255,255],[234,254,254,255,255,255,255,255,255,255,255],[253,255,255,255,255,255,255,255,255,255,255]],[[255,246,254,255,255,255,255,255,255,255,255],[239,253,254,255,255,255,255,255,255,255,255],[254,255,254,255,255,255,255,255,255,255,255]],[[255,248,254,255,255,255,255,255,255,255,255],[251,255,254,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,253,254,255,255,255,255,255,255,255,255],[251,254,254,255,255,255,255,255,255,255,255],[254,255,254,255,255,255,255,255,255,255,255]],[[255,254,253,255,254,255,255,255,255,255,255],[250,255,254,255,254,255,255,255,255,255,255],[254,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]]],[[[217,255,255,255,255,255,255,255,255,255,255],[225,252,241,253,255,255,254,255,255,255,255],[234,250,241,250,253,255,253,254,255,255,255]],[[255,254,255,255,255,255,255,255,255,255,255],[223,254,254,255,255,255,255,255,255,255,255],[238,253,254,254,255,255,255,255,255,255,255]],[[255,248,254,255,255,255,255,255,255,255,255],[249,254,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,253,255,255,255,255,255,255,255,255,255],[247,254,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,253,254,255,255,255,255,255,255,255,255],[252,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,254,254,255,255,255,255,255,255,255,255],[253,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,254,253,255,255,255,255,255,255,255,255],[250,255,255,255,255,255,255,255,255,255,255],[254,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]]],[[[186,251,250,255,255,255,255,255,255,255,255],[234,251,244,254,255,255,255,255,255,255,255],[251,251,243,253,254,255,254,255,255,255,255]],[[255,253,254,255,255,255,255,255,255,255,255],[236,253,254,255,255,255,255,255,255,255,255],[251,253,253,254,254,255,255,255,255,255,255]],[[255,254,254,255,255,255,255,255,255,255,255],[254,254,254,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,254,255,255,255,255,255,255,255,255,255],[254,254,255,255,255,255,255,255,255,255,255],[254,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[254,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]]],[[[248,255,255,255,255,255,255,255,255,255,255],[250,254,252,254,255,255,255,255,255,255,255],[248,254,249,253,255,255,255,255,255,255,255]],[[255,253,253,255,255,255,255,255,255,255,255],[246,253,253,255,255,255,255,255,255,255,255],[252,254,251,254,254,255,255,255,255,255,255]],[[255,254,252,255,255,255,255,255,255,255,255],[248,254,253,255,255,255,255,255,255,255,255],[253,255,254,254,255,255,255,255,255,255,255]],[[255,251,254,255,255,255,255,255,255,255,255],[245,251,254,255,255,255,255,255,255,255,255],[253,253,254,255,255,255,255,255,255,255,255]],[[255,251,253,255,255,255,255,255,255,255,255],[252,253,254,255,255,255,255,255,255,255,255],[255,254,255,255,255,255,255,255,255,255,255]],[[255,252,255,255,255,255,255,255,255,255,255],[249,255,254,255,255,255,255,255,255,255,255],[255,255,254,255,255,255,255,255,255,255,255]],[[255,255,253,255,255,255,255,255,255,255,255],[250,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[254,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]]]],Qc=[0,1,2,3,6,4,5,6,6,6,6,6,6,6,6,7,0],yr=[],On=[],sr=[],tu=1,Bs=2,Lr=[],bn=[];st("UpsampleRgbLinePair",re,3),st("UpsampleBgrLinePair",Ne,3),st("UpsampleRgbaLinePair",kn,4),st("UpsampleBgraLinePair",Te,4),st("UpsampleArgbLinePair",Ye,4),st("UpsampleRgba4444LinePair",Be,2),st("UpsampleRgb565LinePair",Se,2);var eu=R.UpsampleRgbLinePair,nu=R.UpsampleBgrLinePair,Ms=R.UpsampleRgbaLinePair,Es=R.UpsampleBgraLinePair,qs=R.UpsampleArgbLinePair,Ds=R.UpsampleRgba4444LinePair,ru=R.UpsampleRgb565LinePair,Ua=16,Ha=1<d.ca.S||(alert("todo:WebPInitConvertARGBToYUV"),d.ca.f.kb.F!=null&&J()),d.Pb&&0(x=u.Md)?0:100k;++k)12>(K=m.pb[k]).lc&&(K.ia=x*hu[0>K.lc?0:K.lc]>>3),U|=K.ia;U&&(alert("todo:VP8InitRandom"),m.ia=1)}m.Ga=u.Id,100m.Ga&&(m.Ga=0)}vo(t,d)||(r=t.a)}}else r=t.a}r==0&&y.Oa!=null&&y.Oa.fd&&(r=Gi(y.ba))}y=r}w=y!=0?null:11>w?N.f.RGBA.eb:N.f.kb.y}else w=null;return w};var Us=[3,4,3,4,4,2,2,4,4,4,2,1,1]};function g(R,gt){for(var dt="",F=0;F<4;F++)dt+=String.fromCharCode(R[gt++]);return dt}function b(R,gt){return(R[gt+0]<<0|R[gt+1]<<8|R[gt+2]<<16)>>>0}function A(R,gt){return(R[gt+0]<<0|R[gt+1]<<8|R[gt+2]<<16|R[gt+3]<<24)>>>0}new f;var S=[0],p=[0],O=[],I=new f,q=i,_=function(R,gt){var dt={},F=0,P=!1,z=0,D=0;if(dt.frames=[],!function(j,M,W,Y){for(var Q=0;Q>1&1}lt!="ANMF"&&(gt+=ft)}return dt}}(q,0);_.response=q,_.rgbaoutput=!0,_.dataurl=!1;var B=_.header?_.header:null,X=_.frames?_.frames:null;if(B){B.loop_counter=B.loop_count,S=[B.canvas_height],p=[B.canvas_width];for(var ot=0;ot>>1)&255;return _},f=function(S,p,O){var I,q,_,B,X=[],ot=S.length;X[0]=4;for(var ut=0;ut>>lt&255,lt+=B.bits;gt[z]=P>>>lt&255}}if(B.bits===16){R=(tt=new Uint32Array(B.decodePixels().buffer)).length,dt=new Uint8Array(R*(32/B.pixelBitlength)*B.colors),gt=new Uint8Array(R*(32/B.pixelBitlength)),F=B.colors>1,z=0,D=0;for(var ft=0;z>>0&255,F&&(dt[D++]=P>>>16&255,P=tt[z++],dt[D++]=P>>>0&255),gt[ft++]=P>>>16&255;_=8}I!==i.image_compression.NONE&&e()?(S=n(dt,B.width*B.colors,B.colors,I),wt=n(gt,B.width,1,I)):(S=dt,wt=gt,at=void 0)}if(B.colorType===3&&(q=this.color_spaces.INDEXED,ut=B.palette,B.transparency.indexed)){var ht=B.transparency.indexed,kt=0;for(z=0,R=ht.length;z=0;i--){for(var a=this.bottom_up?i:this.height-1-i,c=0;c>7-h&1];this.data[l+4*h]=f.blue,this.data[l+4*h+1]=f.green,this.data[l+4*h+2]=f.red,this.data[l+4*h+3]=255}n!==0&&(this.pos+=4-n)}},En.prototype.bit4=function(){for(var i=Math.ceil(this.width/2),e=i%4,n=this.height-1;n>=0;n--){for(var a=this.bottom_up?n:this.height-1-n,c=0;c>4,f=15&o,g=this.palette[h];if(this.data[l]=g.blue,this.data[l+1]=g.green,this.data[l+2]=g.red,this.data[l+3]=255,2*c+1>=this.width)break;g=this.palette[f],this.data[l+4]=g.blue,this.data[l+4+1]=g.green,this.data[l+4+2]=g.red,this.data[l+4+3]=255}e!==0&&(this.pos+=4-e)}},En.prototype.bit8=function(){for(var i=this.width%4,e=this.height-1;e>=0;e--){for(var n=this.bottom_up?e:this.height-1-e,a=0;a=0;n--){for(var a=this.bottom_up?n:this.height-1-n,c=0;c>5&e)/e*255|0,f=(o>>10&e)/e*255|0,g=o>>15?255:0,b=a*this.width*4+4*c;this.data[b]=f,this.data[b+1]=h,this.data[b+2]=l,this.data[b+3]=g}this.pos+=i}},En.prototype.bit16=function(){for(var i=this.width%3,e=parseInt("11111",2),n=parseInt("111111",2),a=this.height-1;a>=0;a--){for(var c=this.bottom_up?a:this.height-1-a,o=0;o>5&n)/n*255|0,g=(l>>11)/e*255|0,b=c*this.width*4+4*o;this.data[b]=g,this.data[b+1]=f,this.data[b+2]=h,this.data[b+3]=255}this.pos+=i}},En.prototype.bit24=function(){for(var i=this.height-1;i>=0;i--){for(var e=this.bottom_up?i:this.height-1-i,n=0;n=0;i--)for(var e=this.bottom_up?i:this.height-1-i,n=0;na&&(c.push(i.slice(f,o)),h=0,f=o),h+=e[o],o++;return f!==o&&c.push(i.slice(f,o)),c},yc=function(i,e,n){n||(n={});var a,c,o,l,h,f,g,b=[],A=[b],S=n.textIndent||0,p=0,O=0,I=i.split(" "),q=io.apply(this,[" ",n])[0];if(f=n.lineIndent===-1?I[0].length+2:n.lineIndent||0){var _=Array(f).join(" "),B=[];I.map(function(ot){(ot=ot.split(/\s*\n/)).length>1?B=B.concat(ot.map(function(ut,wt){return(wt&&ut.length?` `:"")+ut})):B.push(ot[0])}),I=B,f=bc.apply(this,[_,n])}for(o=0,l=I.length;oe||X){if(O>e){for(h=wc.apply(this,[a,c,e-(S+p),e]),b.push(h.shift()),b=[h.pop()];h.length;)A.push([h.shift()]);O=c.slice(a.length-(b[0]?b[0].length:0)).reduce(function(ot,ut){return ot+ut},0)}else b=[a];A.push(b),S=O+f,p=q}else b.push(a),S+=p+O,p=q}return g=f?function(ot,ut){return(ut?_:"")+ot.join(" ")}:function(ot){return ot.join(" ")},A.map(g)},_i.splitTextToSize=function(i,e,n){var a,c=(n=n||{}).fontSize||this.internal.getFontSize(),o=(function(b){if(b.widths&&b.kerning)return{widths:b.widths,kerning:b.kerning};var A=this.internal.getFont(b.fontName,b.fontStyle);return A.metadata.Unicode?{widths:A.metadata.Unicode.widths||{0:1},kerning:A.metadata.Unicode.kerning||{}}:{font:A.metadata,fontSize:this.internal.getFontSize(),charSpace:this.internal.getCharSpace()}}).call(this,n);a=Array.isArray(i)?i:String(i).split(/\r?\n/);var l=1*this.internal.scaleFactor*e/c;o.textIndent=n.textIndent?1*n.textIndent*this.internal.scaleFactor/c:0,o.lineIndent=n.lineIndent;var h,f,g=[];for(h=0,f=a.length;himport("./index.es-45d7fec3.js"),["assets/index.es-45d7fec3.js","assets/main-9cddcd54.js"])).catch(function(n){return Promise.reject(new Error("Could not load canvg: "+n))}).then(function(n){return n.default?n.default:n})}Tt.API.addSvgAsImage=function(n,a,c,o,l,h,f,g){if(isNaN(a)||isNaN(c))throw ve.error("jsPDF.addSvgAsImage: Invalid coordinates",arguments),new Error("Invalid coordinates passed to jsPDF.addSvgAsImage");if(isNaN(o)||isNaN(l))throw ve.error("jsPDF.addSvgAsImage: Invalid measurements",arguments),new Error("Invalid measurements (width and/or height) passed to jsPDF.addSvgAsImage");var b=document.createElement("canvas");b.width=o,b.height=l;var A=b.getContext("2d");A.fillStyle="#fff",A.fillRect(0,0,b.width,b.height);var S={ignoreMouse:!0,ignoreAnimation:!0,ignoreDimensions:!0},p=this;return e().then(function(O){return O.fromString(A,n,S)},function(){return Promise.reject(new Error("Could not load canvg."))}).then(function(O){return O.render(S)}).then(function(){p.addImage(b.toDataURL("image/jpeg",1),a,c,o,l,f,g)})}}(),Tt.API.putTotalPages=function(i){var e,n=0;parseInt(this.internal.getFont().id.substr(1),10)<15?(e=new RegExp(i,"g"),n=this.internal.getNumberOfPages()):(e=new RegExp(this.pdfEscape16(i,this.internal.getFont()),"g"),n=this.pdfEscape16(this.internal.getNumberOfPages()+"",this.internal.getFont()));for(var a=1;a<=this.internal.getNumberOfPages();a++)for(var c=0;c1){for(b=0;be||X){if(O>e){for(h=wc.apply(this,[a,c,e-(S+p),e]),b.push(h.shift()),b=[h.pop()];h.length;)A.push([h.shift()]);O=c.slice(a.length-(b[0]?b[0].length:0)).reduce(function(ot,ut){return ot+ut},0)}else b=[a];A.push(b),S=O+f,p=q}else b.push(a),S+=p+O,p=q}return g=f?function(ot,ut){return(ut?_:"")+ot.join(" ")}:function(ot){return ot.join(" ")},A.map(g)},_i.splitTextToSize=function(i,e,n){var a,c=(n=n||{}).fontSize||this.internal.getFontSize(),o=(function(b){if(b.widths&&b.kerning)return{widths:b.widths,kerning:b.kerning};var A=this.internal.getFont(b.fontName,b.fontStyle);return A.metadata.Unicode?{widths:A.metadata.Unicode.widths||{0:1},kerning:A.metadata.Unicode.kerning||{}}:{font:A.metadata,fontSize:this.internal.getFontSize(),charSpace:this.internal.getCharSpace()}}).call(this,n);a=Array.isArray(i)?i:String(i).split(/\r?\n/);var l=1*this.internal.scaleFactor*e/c;o.textIndent=n.textIndent?1*n.textIndent*this.internal.scaleFactor/c:0,o.lineIndent=n.lineIndent;var h,f,g=[];for(h=0,f=a.length;himport("./index.es-3acd4243.js"),["assets/index.es-3acd4243.js","assets/main-316b396b.js"])).catch(function(n){return Promise.reject(new Error("Could not load canvg: "+n))}).then(function(n){return n.default?n.default:n})}Tt.API.addSvgAsImage=function(n,a,c,o,l,h,f,g){if(isNaN(a)||isNaN(c))throw ve.error("jsPDF.addSvgAsImage: Invalid coordinates",arguments),new Error("Invalid coordinates passed to jsPDF.addSvgAsImage");if(isNaN(o)||isNaN(l))throw ve.error("jsPDF.addSvgAsImage: Invalid measurements",arguments),new Error("Invalid measurements (width and/or height) passed to jsPDF.addSvgAsImage");var b=document.createElement("canvas");b.width=o,b.height=l;var A=b.getContext("2d");A.fillStyle="#fff",A.fillRect(0,0,b.width,b.height);var S={ignoreMouse:!0,ignoreAnimation:!0,ignoreDimensions:!0},p=this;return e().then(function(O){return O.fromString(A,n,S)},function(){return Promise.reject(new Error("Could not load canvg."))}).then(function(O){return O.render(S)}).then(function(){p.addImage(b.toDataURL("image/jpeg",1),a,c,o,l,f,g)})}}(),Tt.API.putTotalPages=function(i){var e,n=0;parseInt(this.internal.getFont().id.substr(1),10)<15?(e=new RegExp(i,"g"),n=this.internal.getNumberOfPages()):(e=new RegExp(this.pdfEscape16(i,this.internal.getFont()),"g"),n=this.pdfEscape16(this.internal.getNumberOfPages()+"",this.internal.getFont()));for(var a=1;a<=this.internal.getNumberOfPages();a++)for(var c=0;c1){for(b=0;b{!D$(n)&&n.mark!=="brush"&&n.mark!=="rule"&&(I.push("genomic type is not encoded to either a x- or y- axis"),g=!1);const C=n.color;n.mark==="line"&&ut(C)&&C.type==="quantitative"&&(I.push("`line` mark cannot be used with `quantitative` value"),g=!1)}),{valid:g,errorMessages:I}}function D$(e){let g;return["x","y","xe","ye","x1","y1","x1e","y1e"].reverse().forEach(I=>{const i=e[I];ut(i)&&i.type==="genomic"&&(g=i)}),g}function r2e(e){let g;return["x","xe","y","ye","x1","y1","x1e","y1e"].reverse().forEach(I=>{const i=e[I];ut(i)&&i.type==="genomic"&&(g=I)}),g}const Etg=[{name:"gene",channels:[{name:"startPosition",type:"genomic",required:!0},{name:"endPosition",type:"genomic",required:!0},{name:"strandColor",type:"nominal",required:!0},{name:"strandRow",type:"nominal",required:!0},{name:"opacity",type:"value",required:!1},{name:"geneHeight",type:"value",required:!1},{name:"geneLabel",type:"nominal",required:!0},{name:"geneLabelColor",type:"nominal",required:!0},{name:"geneLabelFontSize",type:"value",required:!1},{name:"geneLabelStroke",type:"value",required:!1},{name:"geneLabelStrokeThickness",type:"value",required:!1},{name:"geneLabelOpacity",type:"value",required:!1},{name:"type",type:"nominal",required:!0}],mapping:[{dataTransform:[{type:"filter",base:"type",oneOf:["gene"]},{type:"filter",base:"strandColor",oneOf:["-"]}],mark:"triangleLeft",x:{base:"startPosition",type:"genomic"},size:{base:"geneHeight",value:12},row:{base:"strandRow",type:"nominal",domain:["+","-"]},color:{base:"strandColor",type:"nominal",domain:["+","-"],range:["blue","red"]},opacity:{base:"opacity",value:.4},style:{align:"right"}},{dataTransform:[{type:"filter",base:"type",oneOf:["gene"]},{type:"filter",base:"strandColor",oneOf:["+"]}],mark:"triangleRight",x:{base:"endPosition",type:"genomic"},size:{base:"geneHeight",value:12},row:{base:"strandRow",type:"nominal",domain:["+","-"]},color:{base:"strandColor",type:"nominal",domain:["+","-"],range:["blue","red"]},opacity:{base:"opacity",value:.4},style:{align:"left"}},{dataTransform:[{type:"filter",base:"type",oneOf:["exon"]}],mark:"rect",x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},size:{base:"geneHeight",value:12},row:{base:"strandRow",type:"nominal",domain:["+","-"]},color:{base:"strandColor",type:"nominal",domain:["+","-"],range:["blue","red"]},opacity:{base:"opacity",value:.4}},{dataTransform:[{type:"filter",base:"type",oneOf:["gene"]},{type:"filter",base:"strandColor",oneOf:["+"]}],mark:"rect",x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},row:{base:"strandRow",type:"nominal",domain:["+","-"]},color:{base:"strandColor",type:"nominal",domain:["+","-"],range:["blue","red"]},opacity:{base:"opacity",value:.4},size:{value:3}},{dataTransform:[{type:"filter",base:"type",oneOf:["gene"]},{type:"filter",base:"strandColor",oneOf:["-"]}],mark:"rect",x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},row:{base:"strandRow",type:"nominal",domain:["+","-"]},color:{base:"strandColor",type:"nominal",domain:["+","-"],range:["blue","red"]},opacity:{base:"opacity",value:.4},size:{value:3}},{dataTransform:[{type:"filter",base:"type",oneOf:["gene"]}],mark:"text",text:{base:"geneLabel",type:"nominal"},x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},row:{base:"strandRow",type:"nominal",domain:["+","-"]},color:{base:"geneLabelColor",type:"nominal",domain:["+","-"],range:["blue","red"]},opacity:{base:"opacity",value:1},size:{base:"geneLabelFontSize",value:18},stroke:{base:"geneLabelStroke",value:"white"},strokeWidth:{base:"geneLabelStrokeThickness",value:2},visibility:[{operation:"less-than",measure:"width",threshold:"|xe-x|",transitionPadding:10,target:"mark"}]}]},{name:"ideogram",channels:[{name:"startPosition",type:"genomic",required:!0},{name:"endPosition",type:"genomic",required:!0},{name:"chrHeight",type:"value",required:!1},{name:"name",type:"nominal",required:!0},{name:"stainBackgroundColor",type:"nominal",required:!0},{name:"stainLabelColor",type:"nominal",required:!0},{name:"stainStroke",type:"value",required:!1},{name:"stainStrokeWidth",type:"value",required:!1}],mapping:[{mark:"rect",dataTransform:[{type:"filter",base:"stainBackgroundColor",oneOf:["acen"],not:!0}],color:{base:"stainBackgroundColor",type:"nominal",domain:["gneg","gpos25","gpos50","gpos75","gpos100","gvar","acen"],range:["white","lightgray","gray","gray","black","#7B9CC8","#DC4542"]},size:{base:"chrHeight",value:18},x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},stroke:{base:"stainStroke",value:"gray"},strokeWidth:{base:"stainStrokeWidth",value:.3}},{mark:"triangleRight",dataTransform:[{type:"filter",base:"stainBackgroundColor",oneOf:["acen"]},{type:"filter",base:"name",include:"q"}],color:{base:"stainBackgroundColor",type:"nominal",domain:["gneg","gpos25","gpos50","gpos75","gpos100","gvar","acen"],range:["white","lightgray","gray","gray","black","#7B9CC8","#DC4542"]},size:{base:"chrHeight",value:18},x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},stroke:{base:"stainStroke",value:"gray"},strokeWidth:{base:"stainStrokeWidth",value:.3}},{mark:"triangleLeft",dataTransform:[{type:"filter",base:"stainBackgroundColor",oneOf:["acen"]},{type:"filter",base:"name",include:"p"}],color:{base:"stainBackgroundColor",type:"nominal",domain:["gneg","gpos25","gpos50","gpos75","gpos100","gvar","acen"],range:["white","lightgray","gray","gray","black","#7B9CC8","#DC4542"]},size:{base:"chrHeight",value:18},x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},stroke:{base:"stainStroke",value:"gray"},strokeWidth:{base:"stainStrokeWidth",value:.3}},{mark:"text",dataTransform:[{type:"filter",base:"stainLabelColor",oneOf:["acen"],not:!0}],color:{base:"stainLabelColor",type:"nominal",domain:["gneg","gpos25","gpos50","gpos75","gpos100","gvar"],range:["black","black","black","black","white","black"]},text:{base:"name",type:"nominal"},x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},visibility:[{operation:"less-than",measure:"width",threshold:"|xe-x|",transitionPadding:10,target:"mark"}]}]},{name:"sequence",channels:[{name:"startPosition",type:"genomic",required:!0},{name:"endPosition",type:"genomic",required:!0},{name:"barLength",type:"quantitative",required:!0},{name:"baseBackground",type:"nominal",required:!0},{name:"baseLabelColor",type:"nominal",required:!0},{name:"baseLabelFontSize",type:"value",required:!1}],mapping:[{mark:"bar",x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},y:{base:"barLength",type:"quantitative",axis:"none"},color:{base:"baseBackground",type:"nominal",domain:["A","T","G","C"]}},{dataTransform:[{type:"filter",base:"barLength",oneOf:[0],not:!0}],mark:"text",x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},color:{base:"baseLabelColor",type:"nominal",domain:["A","T","G","C"],range:["white"]},text:{base:"baseBackground",type:"nominal"},size:{base:"baseLabelFontSize",value:18},visibility:[{operation:"less-than",measure:"width",threshold:"|xe-x|",transitionPadding:30,target:"mark"},{operation:"LT",measure:"zoomLevel",threshold:10,target:"track"}]}]}];function Mtg(e,g){EX(e,(I,i,n)=>{var C,r;if(!b4e(I))return;const{template:o}=I,a=g.find(c=>c.name===o);if(!a){I._invalidTrack=!0,console.warn(`There is no track template named '${o}'`);return}let s=!0;if(a.channels.forEach(c=>{c.required&&(!I.encoding||!(c.name in I.encoding))&&(s=!1,console.warn(`A template spec ('${o}') does not contain a required channel, ${c.name}`))}),!s){I._invalidTrack=!0;return}const A=JSON.parse(JSON.stringify(I));"encoding"in A&&delete A.encoding;const l={...A,alignment:"overlay",tracks:[],width:(C=I.width)!=null?C:100,height:(r=I.height)!=null?r:100};a.mapping.forEach(c=>{const u={data:I.data,mark:c.mark},{dataTransform:d}=c;d&&d.map(m=>{const f=m.base;f&&I.encoding&&f in I.encoding&&"field"in I.encoding[f]&&(delete m.base,m.field=I.encoding[f].field)});const h=I.encoding;h?Object.keys(c).filter(m=>m!=="mark").forEach(m=>{const f=JSON.parse(JSON.stringify(c[m]));if("base"in f){const b=f.base;if(b in h){const p=JSON.parse(JSON.stringify(h[b]));delete f.base;const y=Object.assign(f,JSON.parse(JSON.stringify(p)));u[m]=y}else delete f.base,u[m]=f}else u[m]=f}):Object.keys(c).filter(m=>m!=="mark").forEach(m=>{const f=JSON.parse(JSON.stringify(c[m]));"base"in f&&delete f.base,u[m]=f}),l.tracks.push(u)}),n[i]=l})}const $se=["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],Zo={color:$se[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:$se,quantitativeSizeRange:[2,6]},ztg={base:"light",root:{background:"white",titleColor:"black",titleBackgroundColor:"transparent",titleFontSize:18,titleFontFamily:"Arial",titleAlign:"left",titleFontWeight:"bold",subtitleColor:"gray",subtitleBackgroundColor:"transparent",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleFontWeight:"normal",subtitleAlign:"left",showMousePosition:!0,mousePositionColor:"#000000"},track:{background:"transparent",alternatingBackground:"transparent",titleColor:"black",titleBackground:"white",titleFontSize:24,titleAlign:"left",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"#DBDBDB",tickColor:"black"},axis:{tickColor:"black",labelColor:"black",labelMargin:5,labelExcludeChrPrefix:!1,labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",baselineColor:"black",gridColor:"#E3E3E3",gridStrokeWidth:1,gridStrokeType:"solid",gridStrokeDash:[4,4]},markCommon:{...Zo},point:{...Zo,size:3},rect:{...Zo},triangle:{...Zo},area:{...Zo},line:{...Zo},bar:{...Zo},rule:{...Zo,strokeWidth:1},link:{...Zo,strokeWidth:1},text:{...Zo,textAnchor:"middle",textFontWeight:"normal"},brush:{...Zo,color:"gray",opacity:.3,stroke:"black",strokeWidth:1}},qse=["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],Ptg={color:qse[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:qse,quantitativeSizeRange:[2,6]},Go={...Ptg,stroke:"white"},Jtg={base:"dark",root:{background:"black",titleColor:"white",titleBackgroundColor:"transparent",titleFontSize:18,titleFontFamily:"Arial",titleAlign:"middle",titleFontWeight:"bold",subtitleColor:"lightgray",subtitleBackgroundColor:"transparent",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleAlign:"middle",subtitleFontWeight:"normal",showMousePosition:!0,mousePositionColor:"#FFFFFF"},track:{background:"transparent",alternatingBackground:"transparent",titleColor:"white",titleBackground:"black",titleFontSize:18,titleAlign:"left",outline:"white",outlineWidth:1},legend:{position:"right",background:"black",backgroundOpacity:.7,labelColor:"white",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"#DBDBDB",tickColor:"white"},axis:{tickColor:"white",labelMargin:5,labelExcludeChrPrefix:!1,labelColor:"white",labelFontSize:10,labelFontWeight:"normal",labelFontFamily:"Arial",baselineColor:"white",gridColor:"gray",gridStrokeWidth:1,gridStrokeType:"solid",gridStrokeDash:[4,4]},markCommon:{...Go},point:{...Go,size:3},rect:{...Go},triangle:{...Go},area:{...Go},line:{...Go},bar:{...Go},rule:{...Go,strokeWidth:1},link:{...Go,strokeWidth:1},text:{...Go,textAnchor:"middle",textFontWeight:"normal"},brush:{...Go,color:"lightgray",opacity:.3,stroke:"white",strokeWidth:1}},ele=["#D19000","#008F67","#005F96","#B86E97","#B55100","#4793BF","#C9C03"],vo={color:ele[0],size:1,stroke:"#3C3C3C",strokeWidth:0,opacity:1,nominalColorRange:ele,quantitativeSizeRange:[2,6]},Otg={base:"warm",root:{background:"#FFF8E8",titleColor:"#3C3C3C",subtitleColor:"gray",showMousePosition:!0,mousePositionColor:"#3C3C3C"},track:{titleColor:"#3C3C3C",titleBackground:"#FFF8E8",outline:"#3C3C3C",outlineWidth:1},legend:{background:"#FFF8E8",backgroundOpacity:.7,labelColor:"#3C3C3C",backgroundStroke:"#3C3C3C",tickColor:"3C3C3C"},axis:{tickColor:"#3C3C3C",labelColor:"#3C3C3C",baselineColor:"#3C3C3C",gridColor:"#E3E3E3",gridStrokeWidth:1},markCommon:{...vo},point:{...vo,size:3},rect:{...vo},triangle:{...vo},area:{...vo},line:{...vo},bar:{...vo},rule:{...vo,strokeWidth:1},link:{...vo,strokeWidth:1},text:{...vo,textAnchor:"middle",textFontWeight:"normal"},brush:{...vo,color:"lightgray",opacity:.3,stroke:"#3C3C3C",strokeWidth:1}},tle=["#F66A62","#05B230","#5692FF","#D764D6","#86E9D4","#6E6AD7","#FFFB00"],Bo={color:tle[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:tle,quantitativeSizeRange:[2,6]},_tg={base:"ggplot",root:{background:"white",titleColor:"black",titleFontSize:18,titleFontFamily:"Helvetica",titleAlign:"middle",titleFontWeight:"bold",titleBackgroundColor:"white",subtitleColor:"gray",subtitleFontSize:14,subtitleFontFamily:"Helvetica",subtitleAlign:"middle",subtitleFontWeight:"light",subtitleBackgroundColor:"white",showMousePosition:!0,mousePositionColor:"black"},track:{background:"#e8e8e8",alternatingBackground:"#d1d1d1",titleColor:"black",titleBackground:"white",outline:"black",outlineWidth:2},legend:{position:"right",background:"#e8e8e8",backgroundOpacity:1,labelColor:"black",backgroundStroke:"#e8e8e8",tickColor:"white"},axis:{tickColor:"white",labelColor:"black",baselineColor:"#e8e8e8",gridColor:"white",gridStrokeWidth:2},markCommon:{...Bo},point:{...Bo,size:3},rect:{...Bo},triangle:{...Bo},area:{...Bo},line:{...Bo},bar:{...Bo},rule:{...Bo,strokeWidth:1},link:{...Bo,strokeWidth:1},text:{...Bo,textAnchor:"middle",textFontWeight:"bold"},brush:{...Bo,color:"black",opacity:.3,stroke:"black",strokeWidth:1}},gle=["#37E649","#ED2D44","#AEAFEA","#EBAEAE","#CE7B3D","#8743E0","#5233F0"],So={color:gle[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:gle,quantitativeSizeRange:[2,6]},Ltg={base:"igv",root:{background:"white",titleColor:"white",titleAlign:"left",titleFontWeight:"bold",titleBackgroundColor:"#5f5f5f",subtitleColor:"#3b3b3b",subtitleAlign:"left",subtitleFontWeight:"bold",subtitleBackgroundColor:"#c4c4c4",showMousePosition:!0,mousePositionColor:"black"},track:{background:"white",alternatingBackground:"#e8e8e8",titleColor:"white",titleBackground:"#5F5F5F",outline:"#5F5F5F",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:1,labelColor:"black",backgroundStroke:"black",tickColor:"black"},axis:{tickColor:"black",labelColor:"black",baselineColor:"white",gridColor:"transparent",gridStrokeWidth:0},markCommon:{...So},point:{...So,size:3},rect:{...So},triangle:{...So},area:{...So},line:{...So},bar:{...So},rule:{...So,strokeWidth:1},link:{...So,strokeWidth:1},text:{...So,textAnchor:"middle",textFontWeight:"bold"},brush:{...So,color:"white",opacity:.3,stroke:"black",strokeWidth:1}},Ile=["#CD9B1D","#8A668B","#40E0D0","#FF6969","#666666","#FAC902","#FE0000","#CC96CD","#D9D9D9"],wo={color:Ile[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:Ile,quantitativeSizeRange:[2,6]},Utg={base:"ensembl",root:{background:"white",titleColor:"#494949",titleFontSize:24,titleFontFamily:"GGX88",titleAlign:"left",titleFontWeight:"bold",titleBackgroundColor:"white",subtitleColor:"white",subtitleFontSize:19,subtitleFontFamily:"GGX88",subtitleAlign:"left",subtitleFontWeight:"normal",subtitleBackgroundColor:"#7B8BAF",mousePositionColor:"#FE0000",showMousePosition:!0},track:{background:"white",alternatingBackground:"#fffdf7",titleColor:"black",titleBackground:"white",titleAlign:"left",outline:"#7B8BAF",outlineWidth:2},legend:{tickColor:"black",labelColor:"black",labelFontWeight:"normal",labelFontFamily:"GGX88",background:"white",backgroundOpacity:2,backgroundStroke:"lightgray"},axis:{tickColor:"black",labelColor:"black",labelFontFamily:"GGX88",baselineColor:"black",gridColor:"#7B8BAF",gridStrokeWidth:2},markCommon:{...wo},point:{...wo,size:3},rect:{...wo},triangle:{...wo},area:{...wo},line:{...wo},bar:{...wo},rule:{...wo,strokeWidth:1},link:{...wo,strokeWidth:1},text:{...wo,textAnchor:"middle",textFontWeight:"normal"},brush:{...wo,color:"gray",opacity:.3,stroke:"black",strokeWidth:1}},ile=["#3A62FE","#F85353","#3A62FE","#F85353","#DCA326","#03BF06","#BABABA"],Vo={color:ile[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:ile,quantitativeSizeRange:[2,6]},Qtg={base:"jbrowse",root:{background:"white",titleColor:"white",titleFontSize:20,titleFontFamily:"Roboto",titleAlign:"middle",titleFontWeight:"normal",titleBackgroundColor:"#0b243f",subtitleColor:"white",subtitleFontSize:18,subtitleFontFamily:"Roboto",subtitleAlign:"middle",subtitleFontWeight:"normal",subtitleBackgroundColor:"#732162",showMousePosition:!0,mousePositionColor:"#000000"},track:{background:"white",alternatingBackground:"white",titleAlign:"middle",titleColor:"white",titleBackground:"#0B243F",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"#DCA326",labelFontWeight:"bold",labelFontFamily:"Roboto",backgroundStroke:"#black",tickColor:"black"},axis:{tickColor:"black",labelColor:"#DCA326",labelFontWeight:"bold",labelFontFamily:"Roboto",baselineColor:"black",gridColor:"#c5d5d9",gridStrokeWidth:1},markCommon:{...Vo},point:{...Vo,size:3},rect:{...Vo},triangle:{...Vo},area:{...Vo},line:{...Vo},bar:{...Vo},rule:{...Vo,strokeWidth:1},link:{...Vo,strokeWidth:1},text:{...Vo,textAnchor:"middle",textFontWeight:"normal"},brush:{...Vo,color:"#c5d5d9",opacity:.3,stroke:"black",strokeWidth:1}},nle=["#3A5FCD","#FFA54E","#8FBC8F","#B6709B","#EE6A50","#CCB79E","#DADA8F","#00CDCC","#EED5D2","#CD8EDD","#9ACD31","#D1BEA8","#FFB6C0"],Ro={color:nle[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:nle,quantitativeSizeRange:[2,6]},jtg={base:"ucsc",root:{background:"white",titleColor:"white",titleFontSize:22,titleAlign:"middle",titleFontWeight:"bold",titleBackgroundColor:"#00457c",subtitleColor:"black",subtitleAlign:"middle",subtitleFontWeight:"bold",subtitleBackgroundColor:"white",showMousePosition:!0,mousePositionColor:"#FE0000"},track:{background:"white",alternatingBackground:"#e3f7fc",titleColor:"#3A5FCD",titleBackground:"white",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"black",labelFontWeight:"bold",backgroundStroke:"#DBDBDB",tickColor:"black"},axis:{tickColor:"black",labelColor:"#3A5FCD",labelFontWeight:"bold",baselineColor:"black",gridColor:"#E3E3E3",gridStrokeWidth:1},markCommon:{...Ro},point:{...Ro,size:3},rect:{...Ro},triangle:{...Ro},area:{...Ro},line:{...Ro},bar:{...Ro},rule:{...Ro,strokeWidth:1},link:{...Ro,strokeWidth:1},text:{...Ro,textAnchor:"middle",textFontWeight:"normal"},brush:{...Ro,color:"gray",opacity:.3,stroke:"black",strokeWidth:1}},Cle=["#6E12AC","#15C250","#E70FB1","#FF8E55","#A3B8F3","#DE5E59","#77AAAA","#F5CCCA"],Wo={color:Cle[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:Cle,quantitativeSizeRange:[2,6]},$tg={base:"washu",root:{background:"white",titleColor:"gray",titleAlign:"left",titleFontWeight:"normal",titleBackgroundColor:"white",subtitleColor:"lightgray",subtitleAlign:"left",subtitleFontWeight:"light",subtitleBackgroundColor:"white",showMousePosition:!0,mousePositionColor:"#000000"},track:{background:"white",titleColor:"gray",titleBackground:"white",titleAlign:"left",outline:"gray",outlineWidth:1},legend:{background:"white",backgroundOpacity:.5,labelColor:"gray",labelFontWeight:"light",backgroundStroke:"#DBDBDB",tickColor:"gray"},axis:{tickColor:"lightgray",labelColor:"gray",labelFontWeight:"light",baselineColor:"gray",gridColor:"transparent",gridStrokeWidth:0},markCommon:{...Wo},point:{...Wo,size:3},rect:{...Wo},triangle:{...Wo},area:{...Wo},line:{...Wo},bar:{...Wo},rule:{...Wo,strokeWidth:1},link:{...Wo,strokeWidth:1},text:{...Wo,textAnchor:"middle",textFontWeight:"normal"},brush:{...Wo,color:"gray",opacity:.3,stroke:"gray",strokeWidth:1}},rle=["#ED7D31","#4472C4","#FFC207","#76AE4F","#9E480E","#A5A5A5","#4472C4","#264378","#76AE4F","#5B9CD5"],Xo={color:rle[0],size:1,stroke:"#5A5A5A",strokeWidth:0,opacity:1,nominalColorRange:rle,quantitativeSizeRange:[2,6]},qtg={base:"excel",root:{background:"white",titleColor:"#5A5A5A",titleFontSize:30,titleFontFamily:"Calibri",titleAlign:"middle",titleFontWeight:"bold",titleBackgroundColor:"white",subtitleColor:"#5A5A5A",subtitleFontSize:22,subtitleFontFamily:"Calibri",subtitleAlign:"middle",subtitleFontWeight:"bold",subtitleBackgroundColor:"white",showMousePosition:!0,mousePositionColor:"#000000"},track:{background:"white",alternatingBackground:"#f5f5f5",titleColor:"#5A5A5A",titleBackground:"white",outline:"#5A5A5A",outlineWidth:1},legend:{position:"right",tickColor:"#5A5A5A",labelColor:"#5A5A5A",labelFontSize:12,labelFontWeight:"bold",labelFontFamily:"Calibri",background:"white",backgroundOpacity:.7,backgroundStroke:"#5A5A5A"},axis:{tickColor:"#5A5A5A",labelColor:"#5A5A5A",labelFontFamily:"Calibri",baselineColor:"#5A5A5A",gridColor:"#5A5A5A",gridStrokeWidth:1},markCommon:{...Xo},point:{...Xo,size:3},rect:{...Xo},triangle:{...Xo},area:{...Xo},line:{...Xo},bar:{...Xo},rule:{...Xo,strokeWidth:1},link:{...Xo,strokeWidth:1},text:{...Xo,textAnchor:"middle",textFontWeight:"normal"},brush:{...Xo,color:"#5A5A5A",opacity:.3,stroke:"#5A5A5A",strokeWidth:1}},ole=["#4185f4","#DB4437","#F4B400","#0D9D58","#AA30C3","#FF6E02","#CBC74C"],Ho={color:ole[0],size:2,stroke:"black",strokeWidth:.3,opacity:1,nominalColorRange:ole,quantitativeSizeRange:[2,6]},egg={base:"google",root:{background:"white",titleColor:"#454545",titleFontSize:20,titleFontFamily:"Arial",titleAlign:"left",titleFontWeight:"normal",titleBackgroundColor:"white",subtitleColor:"#7d7d7d",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleAlign:"left",subtitleFontWeight:"light",subtitleBackgroundColor:"white",showMousePosition:!0,mousePositionColor:"#000000"},track:{background:"white",alternatingBackground:"#f5f5f5",titleColor:"#e8e8e8",titleBackground:"white",titleFontSize:12,titleAlign:"left",outline:"black",outlineWidth:1},legend:{position:"right",background:"white",backgroundOpacity:1,labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"black",tickColor:"black"},axis:{labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",tickColor:"black",labelColor:"black",baselineColor:"black",gridColor:"black",gridStrokeWidth:1},markCommon:{...Ho},point:{...Ho,size:3},rect:{...Ho},triangle:{...Ho},area:{...Ho},line:{...Ho},bar:{...Ho},rule:{...Ho,strokeWidth:1},link:{...Ho,strokeWidth:1},text:{...Ho,textAnchor:"middle",textFontWeight:"normal"},brush:{...Ho,color:"#999999",opacity:.3,stroke:"black",strokeWidth:.7}},$O={light:ztg,dark:Jtg,warm:Otg,ggplot:_tg,igv:Ltg,ensembl:Utg,jbrowse:Qtg,ucsc:jtg,washu:$tg,excel:qtg,google:egg};function qO(e){return Object.keys($O).indexOf(e)!==-1}function mG(e){return qO(e)?$O[e]:$O.light}function F$(e,g){var I;function i(...n){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');return g(...n)}return i.config={...e,availableOptions:Object.keys((I=e.defaultOptions)!=null?I:{})},i}const tgg=200,ggg=6,Igg=2,o2e=7829367,igg=' ',ngg={type:"axis-track",datatype:["multivec","epilogos"],local:!1,orientation:"1d-horizontal",thumbnail:new DOMParser().parseFromString(igg,"text/xml").documentElement,defaultOptions:{innerRadius:340,outerRadius:310,startAngle:0,endAngle:360,width:700,height:700,layout:"linear",labelMargin:5,excludeChrPrefix:!1,labelPosition:"none",labelColor:"black",labelTextOpacity:.4,trackBorderWidth:0,trackBorderColor:"black",tickPositions:"even",fontSize:12,fontFamily:"sans-serif",fontWeight:"normal",color:"#808080",stroke:"#ffffff",backgroundColor:"transparent",showMousePosition:!1,tickColor:o2e}},Cgg=(e,g,I)=>{const{absToChr:i,colorToHex:n,pixiTextToSvg:C,svgLine:r,showMousePosition:o}=e.utils;function a(A,l){return Object.assign(new e.libraries.PIXI.Text(A,l),{hashValue:Math.random()})}class s extends e.tracks.PixiTrack{constructor(){super(g,I),rt(this,"allTexts"),rt(this,"searchField"),rt(this,"chromInfo"),rt(this,"dataConfig"),rt(this,"pTicksCircular"),rt(this,"pTicks"),rt(this,"gTicks"),rt(this,"tickTexts"),rt(this,"isShowGlobalMousePosition"),rt(this,"pixiTextConfig"),rt(this,"stroke"),rt(this,"tickWidth"),rt(this,"tickHeight"),rt(this,"tickTextSeparation"),rt(this,"tickColor"),rt(this,"animate"),rt(this,"hideMousePosition"),rt(this,"gBoundTicks"),rt(this,"leftBoundTick"),rt(this,"rightBoundTick"),rt(this,"is2d"),rt(this,"texts");const{dataConfig:l,animate:c,chromInfoPath:u,isShowGlobalMousePosition:d}=g;this.searchField=null,this.dataConfig=l,this.allTexts=[],this.pTicksCircular=new e.libraries.PIXI.Graphics,this.pTicks=new e.libraries.PIXI.Graphics,this.pMain.addChild(this.pTicks),this.pMain.addChild(this.pTicksCircular),this.gTicks={},this.tickTexts={},this.options=I,this.isShowGlobalMousePosition=d,this.pixiTextConfig=xs({size:+this.options.fontSize,fontFamily:this.options.fontFamily,fontWeight:this.options.fontWeight,color:this.options.color,stroke:this.options.stroke,strokeThickness:2}),this.stroke=n(this.pixiTextConfig.stroke),this.tickWidth=tgg,this.tickHeight=ggg,this.tickTextSeparation=Igg,this.tickColor=n(this.options.tickColor),this.animate=c,this.pubSubs=[],this.options.showMousePosition&&!this.hideMousePosition&&(this.hideMousePosition=o(this,this.is2d,this.isShowGlobalMousePosition()));let h=u;h||(h=`${l.server}/chrom-sizes/?id=${l.tilesetUid}`);const m=this.options.assembly,f={},b={...bI(m).size},p=[];Object.keys(bI(m).size).forEach(y=>{f[y]={chr:y,pos:bI(m).size[y]}}),Object.keys(bI(m).interval).forEach(y=>{p.push({chr:y,pos:bI(m).interval[y][0]})}),this.chromInfo={chrPositions:f,chromLengths:b,cumPositions:p},this.rerender(this.options,!0),this.draw(),this.animate()}initBoundsTicks(){this.pTicks&&(this.pMain.removeChild(this.pTicks),this.pTicks=null),this.gBoundTicks||(this.gBoundTicks=new e.libraries.PIXI.Graphics,this.leftBoundTick=a("",this.pixiTextConfig),this.rightBoundTick=a("",this.pixiTextConfig),this.gBoundTicks.addChild(this.leftBoundTick),this.gBoundTicks.addChild(this.rightBoundTick),this.pMain.addChild(this.gBoundTicks)),this.texts=[]}initChromLabels(){this.chromInfo&&(this.gBoundTicks&&(this.pMain.removeChild(this.gBoundTicks),this.gBoundTicks=void 0),this.pTicks||(this.pTicks=new e.libraries.PIXI.Graphics,this.pMain.addChild(this.pTicks)),this.texts=[],this.pTicks.removeChildren(),this.chromInfo.cumPositions.forEach(l=>{var c,u,d;const h=l.chr;this.gTicks[h]=new e.libraries.PIXI.Graphics,this.tickTexts[h]||(this.tickTexts[h]=[]);const m=this.options.excludeChrPrefix?h.replace("chr",""):h,f=a(m,this.pixiTextConfig);(c=this.pTicks)==null||c.addChild(f),(u=this.pTicks)==null||u.addChild(this.gTicks[h]),(d=this.texts)==null||d.push(f)}))}rerender(l,c){const u=JSON.stringify(l);!c&&u===this.prevOptions||(this.prevOptions=u,this.options=l,this.pixiTextConfig.fontSize=+this.options.fontSize?`${+this.options.fontSize}px`:this.pixiTextConfig.fontSize,this.pixiTextConfig.fill=this.options.color||this.pixiTextConfig.fill,this.pixiTextConfig.stroke=this.options.stroke||this.pixiTextConfig.stroke,this.stroke=n(this.pixiTextConfig.stroke),this.tickColor=this.options.tickColor?n(this.options.tickColor):o2e,this.options.tickPositions==="ends"&&this.options.layout!=="circular"?this.initBoundsTicks():this.initChromLabels(),super.rerender(l,c),this.options.showMousePosition&&!this.hideMousePosition&&(this.hideMousePosition=o(this,this.is2d,this.isShowGlobalMousePosition())),!this.options.showMousePosition&&this.hideMousePosition&&(this.hideMousePosition(),this.hideMousePosition=void 0))}formatTick(l){if(isNaN(l))return"null";const c=this._xScale.domain(),u=c[1]-c[0],d=_6e(l,u),h=n0e(","),m=C0e(`,.${d}`,u);let f=h;return this.options.tickFormat==="si"?f=m:this.options.tickFormat==="plain"?f=h:this.options.tickPositions==="ends"&&(f=m),f(l)}drawBoundsTicks(l,c){if(!this.gBoundTicks||!this.leftBoundTick||!this.rightBoundTick)return;const u=this.gBoundTicks;u.clear(),u.lineStyle(1,0);const d=this.options.reverseOrientation?0:this.dimensions[1],h=this.options.reverseOrientation?this.tickHeight:this.dimensions[1]-this.tickHeight;u.moveTo(1,d),u.lineTo(1,h),u.moveTo(this.dimensions[0]-1,d),u.lineTo(this.dimensions[0]-1,h),this.leftBoundTick.x=0,this.leftBoundTick.y=this.options.reverseOrientation?h+this.tickTextSeparation:h-this.tickTextSeparation,this.leftBoundTick.text=this.options.assembly==="unknown"?`${this.formatTick(l[1])}`:`${l[0]}: ${this.formatTick(l[1])}`,this.leftBoundTick.anchor.y=this.options.reverseOrientation?0:1,this.rightBoundTick.x=this.dimensions[0],this.rightBoundTick.text=this.options.assembly==="unknown"?`${this.formatTick(c[1])}`:`${c[0]}: ${this.formatTick(c[1])}`,this.rightBoundTick.y=this.options.reverseOrientation?h+this.tickTextSeparation:h-this.tickTextSeparation,this.rightBoundTick.anchor.y=this.options.reverseOrientation?0:1,this.rightBoundTick.anchor.x=1,this.flipText&&(this.leftBoundTick.scale.x=-1,this.leftBoundTick.anchor.x=1,this.rightBoundTick.scale.x=-1,this.rightBoundTick.anchor.x=0),this.leftBoundTick.tickLine=[1,this.dimensions[1],1,this.dimensions[1]-this.tickHeight],this.rightBoundTick.tickLine=[this.dimensions[0]-1,this.dimensions[1],this.dimensions[0]-1,this.dimensions[1]-this.tickHeight],this.tickTexts={},this.tickTexts.all=[this.leftBoundTick,this.rightBoundTick]}drawTicks(l){const c=this.gTicks[l.chr];c.visible=!0,c.clear();const u=+this.chromInfo.chromLengths[l.chr],d=Math.max(this._xScale(l.pos),0),h=Math.min(this._xScale(l.pos+u),this.dimensions[0]),m=(h-d)/this.tickWidth,b=eh().domain([Math.max(1,this._xScale.invert(0)-l.pos),Math.min(u,this._xScale.invert(this.dimensions[0])-l.pos)]).range([d,h]).ticks(m).filter(v=>Number.isInteger(v)),p=this.tickTexts[l.chr],y=this.tickHeight,Z=0;let B=y+this.tickTextSeparation;for(this.options.reverseOrientation&&(B=this.dimensions[1]-B);p.lengthb.length;){const v=p.pop();this.gTicks[l.chr].removeChild(v)}let G=0;for(;Gu){const R=V-u;V=u,w-=R}const S=[],X=b+G.height/2+3;for(let R=V;R>=w;R-=v/10){const H=Mt(R,u,X,u/2,d/2,h,m);S.push(new e.libraries.PIXI.Point(H.x,H.y))}return S.length===0?void 0:(l.updateText(),new e.libraries.PIXI.SimpleRope(l.texture,S))}draw(){if(this.allTexts=[],!this.texts)return;const l=i(this._xScale.domain()[0],this.chromInfo),c=i(this._xScale.domain()[1],this.chromInfo);if(!l||!c){console.warn("Empty chromInfo:",this.dataConfig,this.chromInfo);return}if(this.options.tickPositions==="ends"&&this.options.layout!=="circular"){if(!this.gBoundTicks)return;this.gBoundTicks.visible=!0,this.drawBoundsTicks(l,c);return}if(!this.pTicks)return;const u=this.options.layout==="circular";for(let h=0;h{this.tickTexts[h]&&this.tickTexts[h].forEach(m=>{m.visible=!1})}),this.pTicksCircular.removeChildren();for(let h=l[3];h<=c[3];h++){const m=this.chromInfo.cumPositions[h],f=m.pos+this.chromInfo.chromLengths[m.chr]/2,b=this._xScale(f),p=this.texts[h];p.anchor.x=.5,p.anchor.y=u?.5:this.options.reverseOrientation?0:1;let y;u?(y=this.addCurvedText(p,b),y&&this.pTicksCircular.addChild(y)):(p.x=b,p.y=this.dimensions[1]-d),p.updateTransform(),this.flipText&&(p.scale.x=-1);const Z=this.drawTicks(m);u?Z>0&&y&&this.pTicksCircular.removeChild(y):p.visible=Z<=0,this.allTexts.push({importance:p.hashValue,text:p,rope:y})}this.hideOverlaps(this.allTexts)}hideOverlaps(l){const c=new T6e;l.sort((u,d)=>d.importance-u.importance).forEach(({text:u,rope:d})=>{u.updateTransform();const h=u.getBounds(),m=this.options.labelMargin,f={minX:h.x-m,minY:h.y-m,maxX:h.x+h.width+m*2,maxY:h.y+h.height+m*2};m<0||!c.collides(f)?c.insert(f):(u.visible=!1,this.options.layout==="circular"&&d&&this.pTicksCircular.removeChild(d))})}setPosition(l){super.setPosition(l),[this.pMain.position.x,this.pMain.position.y]=this.position}zoomed(l,c){[...l.domain(),...c.domain()].filter(d=>isNaN(d)).length===0&&(this.xScale(l),this.yScale(c),this.draw())}exportSVG(){let l=null,c=null;super.exportSVG?[c,l]=super.exportSVG():(c=document.createElement("g"),l=c),c.setAttribute("class","chromosome-labels");const u=document.createElement("g");return l.appendChild(u),u.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),this.allTexts.filter(d=>d.text.visible).forEach(d=>{const h=C(d.text);u.appendChild(h)}),Object.values(this.tickTexts).forEach(d=>{d.filter(h=>h.visible).forEach(h=>{if(!h.tickLine)return;let m=C(h);u.appendChild(m),m=r(h.x,this.options.reverseOrientation?0:this.dimensions[1],h.x,this.options.reverseOrientation?this.tickHeight:this.dimensions[1]-this.tickHeight,1,this.tickColor);const f=document.createElement("line");f.setAttribute("x1",String(h.tickLine[0])),f.setAttribute("y1",String(h.tickLine[1])),f.setAttribute("x2",String(h.tickLine[2])),f.setAttribute("y2",String(h.tickLine[3])),f.setAttribute("style","stroke: grey"),u.appendChild(m),u.appendChild(f)})}),[c,l]}}return new s},ale=F$(ngg,Cgg);function e_(e,...g){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');class I extends e.tracks.SVGTrack{constructor(n){var C,r;super(...n),rt(this,"circularBrushData"),rt(this,"prevExtent");const[o,a]=n,{registerViewportChanged:s,removeViewportChanged:A,setDomainsCallback:l}=o;this.uid=ln(),this.options=a,this.hasFromView=!o.projectionXDomain,this.removeViewportChanged=A,this.setDomainsCallback=l,this.viewportXDomain=this.hasFromView?null:o.projectionXDomain,this.viewportYDomain=this.hasFromView?null:[0,0],this.prevExtent=[0,0],this.RR=.02;const c=[0,Math.PI*1.7];this.circularBrushData=this.getBrushData(c),this.brush=iqe().innerRadius((C=this.options.innerRadius)!=null?C:100).outerRadius((r=this.options.outerRadius)!=null?r:200),this.gBrush=this.gMain.append("g").attr("id",`brush-${this.uid}`).selectAll(".brush").data(this.circularBrushData).enter().append("path").attr("class","brush").attr("d",this.brush).attr("fill",this.options.projectionFillColor).attr("stroke",this.options.projectionStrokeColor).attr("fill-opacity",u=>u.type==="brush"?this.options.projectionFillOpacity:0).attr("stroke-opacity",u=>u.type==="brush"?this.options.projectionStrokeOpacity:0).attr("stroke-width",this.options.strokeWidth).style("pointer-events","all").style("cursor",u=>u.cursor).call(this.dragged()),s(this.uid,this.viewportChanged.bind(this)),this.draw()}getBrushData(n){return[{type:"brush",startAngle:n[0],endAngle:n[1],cursor:"grab"},{type:"start",startAngle:n[0],endAngle:n[0]+this.RR,cursor:"move"},{type:"end",startAngle:n[1]-this.RR,endAngle:n[1],cursor:"move"}]}cropExtent(n){let[C,r]=n,o=0;for(;(C>Math.PI*2||r>Math.PI*2||C<0||r<0)&&!(o++>10);)C>Math.PI*2||r>Math.PI*2?(C-=Math.PI*2,r-=Math.PI*2):(C<0||r<0)&&(C+=Math.PI*2,r+=Math.PI*2);return[C,r].sort((a,s)=>a-s)}updateBrush(n){let[C,r]=n;if(C<=gn&&r<=gn||C>=Math.PI*2-gn&&r>=Math.PI*2-gn){this.gBrush.attr("visibility","hidden");return}CMath.PI*2-gn&&(C=Math.PI*2-gn),rMath.PI*2-gn&&(r=Math.PI*2-gn),this.circularBrushData=this.getBrushData(n),this.gBrush.data(this.circularBrushData).attr("d",this.brush).attr("visibility","visible")}dragged(){const n=r=>{this.startEvent=r.sourceEvent,this.prevExtent=[this.circularBrushData[0].startAngle,this.circularBrushData[0].endAngle]},C=(r,o)=>{const[a,s]=this.position,[A,l]=this.dimensions,c=r.sourceEvent,u=this.startEvent.layerX-a,d=this.startEvent.layerY-s,h=c.layerX-a,m=c.layerY-s,f=Math.atan2(u-A/2,d-l/2)-Math.atan2(h-A/2,m-l/2);let[b,p]=this.prevExtent;if(o.type==="brush"){if(b=b+f,p=p+f,bV?(p+=w,b+=w):(b-=V,p-=V)}}else o.type==="start"?b=b+f:o.type==="end"&&(p=p+f);if([b,p]=this.cropExtent([b,p]),!this._xScale||!this._yScale)return;const y=(this.options.endAngle-this.options.startAngle)/360,Z=b-this.options.startAngle/360*Math.PI*2,B=p-this.options.startAngle/360*Math.PI*2,G=[this._xScale.invert(A-A*B/(Math.PI*2*y)),this._xScale.invert(A-A*Z/(Math.PI*2*y))],v=this.viewportYDomain;this.hasFromView||(this.viewportXDomain=G),this.setDomainsCallback(G,v),this.updateBrush([b,p])};return e.libraries.d3Drag.drag().on("start",n).on("drag",C)}draw(){if(!this._xScale||!this.yScale||!this.viewportXDomain||!this.viewportYDomain)return;const n=this._xScale(this.viewportXDomain[0]),C=this._xScale(this.viewportXDomain[1]),[r]=this.dimensions;let o=jg(n,r,this.options.startAngle,this.options.endAngle)+Math.PI/2,a=jg(C,r,this.options.startAngle,this.options.endAngle)+Math.PI/2;[a,o]=this.cropExtent([a,o]),this.updateBrush([a,o])}viewportChanged(n,C){const r=n.domain(),o=C.domain();this.viewportXDomain=r,this.viewportYDomain=o,this.draw()}remove(){this.removeViewportChanged(this.uid),super.remove()}rerender(){}zoomed(n,C){this.xScale(n),this.yScale(C),this.draw()}setPosition(n){super.setPosition(n),this.draw()}setDimensions(n){super.setDimensions(n),this.gBrush.attr("transform",`translate(${n[0]/2},${n[1]/2})`),this.draw()}}return new I(g)}const rgg=' ';e_.config={type:"brush-track",datatype:["projection"],local:!1,projection:!0,orientation:"2d",thumbnail:new DOMParser().parseFromString(rgg,"text/xml").documentElement,availableOptions:["innerRadius","outerRadius","startAngle","endAngle","axisPositionHorizontal","projectionFillColor","projectionStrokeColor","projectionFillOpacity","projectionStrokeOpacity","strokeWidth"],defaultOptions:{innerRadius:100,outerRadius:200,startAngle:0,endAngle:360,axisPositionHorizontal:"left",projectionFillColor:"#777",projectionStrokeColor:"#777",projectionFillOpacity:.3,projectionStrokeOpacity:.7,strokeWidth:1}};const Ale=3,ogg={color:"#777",stroke:"#777",strokeWidth:1,strokeOpacity:.7,opacity:.3};class agg{constructor(g,I,i={}){rt(this,"brushSelection"),rt(this,"style"),rt(this,"range"),rt(this,"data"),rt(this,"startEvent"),rt(this,"prevExtent"),rt(this,"offset"),rt(this,"size"),rt(this,"externals"),rt(this,"emitter"),this.emitter=nqe(),this.range=null,this.prevExtent=[0,0],this.data=this.rangeToData(0,0),this.offset=[0,0],this.size=0,this.externals={d3Selection:I.d3Selection,d3Drag:I.d3Drag},this.style=Object.assign({},ogg,i),this.brushSelection=g.selectAll(".genomic-range-brush").data(this.data).enter().append("rect").attr("class","genomic-range-brush").call(this.onDrag())}getRange(){return this.range}setSize(g){return this.size=g,this}setOffset(g,I){return this.offset=[g,I],this}updateRange(g){return g?(this.range=[Math.min(...g),Math.max(...g)],this.data=this.rangeToData(...this.range)):this.range=null,this}drawBrush(g=!1){const[I,i]=this.offset,n=this.size,C=r=>Math.abs(r.end-r.start);return this.brushSelection.data(this.data).attr("transform",r=>`translate(${I+r.start}, ${i+1})`).attr("width",r=>`${C(r)}px`).attr("height",`${n-2}px`).attr("fill",this.style.color).attr("stroke",this.style.stroke).attr("stroke-width",`${this.style.strokeWidth}px`).attr("fill-opacity",r=>r.type==="body"?this.style.opacity:0).attr("stroke-opacity",r=>r.type==="body"?this.style.strokeOpacity:0).attr("cursor",r=>r.cursor),this.emitter.emit("brush",this.getRange(),g),this}enable(){return this.brushSelection.attr("pointer-events","all"),this}disable(){return this.brushSelection.attr("pointer-events","none"),this}visible(){return this.brushSelection.attr("visibility","visible"),this}hidden(){return this.brushSelection.attr("visibility","hidden"),this}clear(){return this.updateRange(null).drawBrush().hidden().disable(),this}remove(){return this.brushSelection.remove(),this}rangeToData(g,I){return[{type:"body",cursor:"grab",start:g,end:I},{type:"start",cursor:"ew-resize",start:g-Ale,end:g},{type:"end",cursor:"ew-resize",start:I,end:I+Ale}]}onDrag(){const g=i=>{this.startEvent=i.sourceEvent,this.prevExtent=this.range},I=(i,n)=>{var C;const r=i.sourceEvent.layerX-this.startEvent.layerX;let[o,a]=(C=this.prevExtent)!=null?C:[0,0];n.type==="body"?(o+=r,a+=r):n.type==="start"?o+=r:n.type==="end"&&(a+=r),this.updateRange([o,a]).drawBrush()};return this.externals.d3Drag.drag().on("start",g).on("drag",I)}on(g,I){this.emitter.on(g,I)}}const Agg=([e,g],[I,i],[n,C],[r,o])=>{const a=Math.sqrt((e-I)**2+(g-i)**2);if(aMath.sqrt((e-I)**2+(g-i)**2)e<=I&&I<=g,lgg=(e,g,I=5)=>t_(e,g-I)&&t_(e,g+I),cgg=(e,g)=>g.filter((I,i)=>i%2===0).every(I=>t_(e,I)),ugg=([e,g],I,i=5)=>{let n,C,r,o,a=!1;for(let s=0;s0?h=Math.sqrt((g-o)**2+(e-r)**2):d<0?h=Math.sqrt((g-C)**2+(e-n)**2):h=Math.abs(A[0]*c[1]-A[1]*c[0])/Math.sqrt(A[0]**2+A[1]**2),h{let i,n,C,r,o=!1;for(let a=0,s=I.length-2;ag!=r>g&&e<(C-i)*(g-n)/(r-n)+i&&(o=!o),s=a;return o};class hgg{constructor(){rt(this,"data"),this.data=[]}size(){return this.data.length}addPolygonBasedEvent(g,I){this.data.push({uid:ln(),type:"polygon",value:g,polygon:I})}addPointBasedEvent(g,I){this.data.push({uid:ln(),type:"point",value:g,polygon:I})}addLineBasedEvent(g,I){this.data.push({uid:ln(),type:"line",value:g,polygon:I})}clear(){this.data=[]}find(g,I,i=!1){const n=Array.from(this.data);return i&&n.reverse(),n.find(C=>this.isMouseWithin(C,g,I))}findAll(g,I,i=!1){const n=Array.from(this.data);return i&&n.reverse(),n.filter(C=>this.isMouseWithin(C,g,I))}getSiblings(g,I){const i=[],n=Array.from(new Set(g.map(C=>C.uid)));return g.forEach(C=>{const r=C.value[I];r&&i.push(...this.data.filter(o=>o.value[I]===r&&n.indexOf(o.uid)===-1))}),i}isMouseWithin(g,I,i){switch(g.type){case"point":return sgg([I,i],g.polygon);case"line":return ugg([I,i],g.polygon);case"polygon":default:return dgg([I,i],g.polygon)}}findAllWithinRange(g,I,i=!1){const n=Array.from(this.data);return i&&n.reverse(),n.filter(C=>this.isWithinRange(C,g,I))}isWithinRange(g,I,i){switch(g.type){case"point":return lgg([I,i],g.polygon[0],g.polygon[2]);case"line":case"polygon":default:return cgg([I,i],g.polygon)}}}const a2e="KCgpID0+IHsKICB2YXIgX19jcmVhdGUgPSBPYmplY3QuY3JlYXRlOwogIHZhciBfX2RlZlByb3AgPSBPYmplY3QuZGVmaW5lUHJvcGVydHk7CiAgdmFyIF9fZ2V0T3duUHJvc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IDE7CiAgICAgICAgcyA+Pj0gLW5CaXRzOwogICAgICAgIG5CaXRzICs9IGVMZW47CiAgICAgICAgZm9yICg7IG5CaXRzID4gMDsgZSA9IGUgKiAyNTYgKyBidWZmZXJbb2Zmc2V0ICsgaV0sIGkgKz0gZCwgbkJpdHMgLT0gOCkgewogICAgICAgIH0KICAgICAgICBtID0gZSAmICgxIDw8IC1uQml0cykgLSAxOwogICAgICAgIGUgPj49IC1uQml0czsKICAgICAgICBuQml0cyArPSBtTGVuOwogICAgICAgIGZvciAoOyBuQml0cyA+IDA7IG0gPSBtICogMjU2ICsgYnVmZmVyW29mZnNldCArIGldLCBpICs9IGQsIG5CaXRzIC09IDgpIHsKICAgICAgICB9CiAgICAgICAgaWYgKGUgPT09IDApIHsKICAgICAgICAgIGUgPSAxIC0gZUJpYXM7CiAgICAgICAgfSBlbHNlIGlmIChlID09PSBlTWF4KSB7CiAgICAgICAgICByZXR1cm4gbSA/IE5hTiA6IChzID8gLTEgOiAxKSAqIEluZmluaXR5OwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBtID0gbSArIE1hdGgucG93KDIsIG1MZW4pOwogICAgICAgICAgZSA9IGUgLSBlQmlhczsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIChzID8gLTEgOiAxKSAqIG0gKiBNYXRoLnBvdygyLCBlIC0gbUxlbik7CiAgICAgIH07CiAgICAgIGV4cG9ydHMud3JpdGUgPSBmdW5jdGlvbihidWZmZXIsIHZhbHVlLCBvZmZzZXQsIGlzTEUsIG1MZW4sIG5CeXRlcykgewogICAgICAgIHZhciBlLCBtLCBjOwogICAgICAgIHZhciBlTGVuID0gbkJ5dGVzICogOCAtIG1MZW4gLSAxOwogICAgICAgIHZhciBlTWF4ID0gKDEgPDwgZUxlbikgLSAxOwogICAgICAgIHZhciBlQmlhcyA9IGVNYXggPj4gMTsKICAgICAgICB2YXIgcnQgPSBtTGVuID09PSAyMyA/IE1hdGgucG93KDIsIC0yNCkgLSBNYXRoLnBvdygyLCAtNzcpIDogMDsKICAgICAgICB2YXIgaSA9IGlzTEUgPyAwIDogbkJ5dGVzIC0gMTsKICAgICAgICB2YXIgZCA9IGlzTEUgPyAxIDogLTE7CiAgICAgICAgdmFyIHMgPSB2YWx1ZSA8IDAgfHwgdmFsdWUgPT09IDAgJiYgMSAvIHZhbHVlIDwgMCA/IDEgOiAwOwogICAgICAgIHZhbHVlID0gTWF0aC5hYnModmFsdWUpOwogICAgICAgIGlmIChpc05hTih2YWx1ZSkgfHwgdmFsdWUgPT09IEluZmluaXR5KSB7CiAgICAgICAgICBtID0gaXNOYU4odmFsdWUpID8gMSA6IDA7CiAgICAgICAgICBlID0gZU1heDsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZSA9IE1hdGguZmxvb3IoTWF0aC5sb2codmFsdWUpIC8gTWF0aC5MTjIpOwogICAgICAgICAgaWYgKHZhbHVlICogKGMgPSBNYXRoLnBvdygyLCAtZSkpIDwgMSkgewogICAgICAgICAgICBlLS07CiAgICAgICAgICAgIGMgKj0gMjsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChlICsgZUJpYXMgPj0gMSkgewogICAgICAgICAgICB2YWx1ZSArPSBydCAvIGM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB2YWx1ZSArPSBydCAqIE1hdGgucG93KDIsIDEgLSBlQmlhcyk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodmFsdWUgKiBjID49IDIpIHsKICAgICAgICAgICAgZSsrOwogICAgICAgICAgICBjIC89IDI7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoZSArIGVCaWFzID49IGVNYXgpIHsKICAgICAgICAgICAgbSA9IDA7CiAgICAgICAgICAgIGUgPSBlTWF4OwogICAgICAgICAgfSBlbHNlIGlmIChlICsgZUJpYXMgPj0gMSkgewogICAgICAgICAgICBtID0gKHZhbHVlICogYyAtIDEpICogTWF0aC5wb3coMiwgbUxlbik7CiAgICAgICAgICAgIGUgPSBlICsgZUJpYXM7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gICAgICAgICBPYmplY3Quc2V0UHJvdG90eXBlT2YoYXJyLCBwcm90byk7CiAgICAgICAgICByZXR1cm4gYXJyLmZvbygpID09PSA0MjsKICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICB9CiAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShCdWZmZXI4LnByb3RvdHlwZSwgInBhcmVudCIsIHsKICAgICAgICBlbnVtZXJhYmxlOiB0cnVlLAogICAgICAgIGdldDogZnVuY3Rpb24oKSB7CiAgICAgICAgICBpZiAoIUJ1ZmZlcjguaXNCdWZmZXIodGhpcykpCiAgICAgICAgICAgIHJldHVybiB2b2lkIDA7CiAgICAgICAgICByZXR1cm4gdGhpcy5idWZmZXI7CiAgICAgICAgfQogICAgICB9KTsKICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KEJ1ZmZlcjgucHJvdG90eXBlLCAib2Zmc2V0IiwgewogICAgICAgIGVudW1lcmFibGU6IHRydWUsCiAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHsKICAgICAgICAgIGlmICghQnVmZmVyOC5pc0J1ZmZlcih0aGlzKSkKICAgICAgICAgICAgcmV0dXJuIHZvaWQgMDsKICAgICAgICAgIHJldHVybiB0aGlzLmJ5dGVPZmZzZXQ7CiAgICAgICAgfQogICAgICB9KTsKICAgICAgZnVuY3Rpb24gY3JlYXRlQnVmZmVyKGxlbmd0aCkgewogICAgICAgIGlmIChsZW5ndGggPiBLX01BWF9MRU5HVEgpIHsKICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCdUaGUgdmFsdWUgIicgKyBsZW5ndGggKyAnIiBpcyBpbnZhbGlkIGZvciBvcHRpb24gInNpemUiJyk7CiAgICAgICAgfQogICAgICAgIGNvbnN0IGJ1ZiA9IG5ldyBVaW50OEFycmF5KGxlbmd0aCk7CiAgICAgICAgT2JqZWN0LnNldFByb3RvdHlwZU9mKGJ1Ziwg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ICAgICAgICBidWYgPSBuZXcgVWludDhBcnJheShhcnJheSwgYnl0ZU9mZnNldCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGJ1ZiA9IG5ldyBVaW50OEFycmF5KGFycmF5LCBieXRlT2Zmc2V0LCBsZW5ndGgpOwogICAgICAgIH0KICAgICAgICBPYmplY3Quc2V0UHJvdG90eXBlT2YoYnVmLCBCdWZmZXI4LnByb3RvdHlwZSk7CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfQogICAgICBmdW5jdGlvbiBmcm9tT2JqZWN0KG9iaikgewogICAgICAgIGlmIChCdWZmZXI4LmlzQnVmZmVyKG9iaikpIHsKICAgICAgICAgIGNvbnN0IGxlbiA9IGNoZWNrZWQob2JqLmxlbmd0aCkgfCAwOwogICAgICAgICAgY29uc3QgYnVmID0gY3JlYXRlQnVmZmVyKGxlbik7CiAgICAgICAgICBpZiAoYnVmLmxlbmd0aCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gYnVmOwogICAgICAgICAgfQogICAgICAgICAgb2JqLmNvcHkoYnVmLCAwLCAwLCBsZW4pOwogICAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai5sZW5ndGggIT09IHZvaWQgMCkgewogICAgICAgICAgaWYgKHR5cGVvZiBvYmoubGVuZ3RoICE9PSAibnVtYmVyIiB8fCBudW1iZXJJc05hTihvYmoubGVuZ3RoKSkgewogICAgICAgICAgICByZXR1cm4gY3JlYXRlQnVmZmVyKDApOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqKTsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai50eXBlID09PSAiQnVmZmVyIiAmJiBBcnJheS5pc0FycmF5KG9iai5kYXRhKSkgewogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqLmRhdGEpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBjaGVja2V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VGhlICJidWYxIiwgImJ1ZjIiIGFyZ3VtZW50cyBtdXN0IGJlIG9uZSBvZiB0eXBlIEJ1ZmZlciBvciBVaW50OEFycmF5Jyk7CiAgICAgICAgfQogICAgICAgIGlmIChhID09PSBiKQogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgbGV0IHggPSBhLmxlbmd0aDsKICAgICAgICBsZXQgeSA9IGIubGVuZ3RoOwogICAgICAgIGZvciAobGV0IGkgPSAwLCBsZW4gPSBNYXRoLm1pbih4LCB5KTsgaSA8IGxlbjsgKytpKSB7CiAgICAgICAgICBpZiAoYVtpXSAhPT0gYltpXSkgewogICAgICAgICAgICB4ID0gYVtpXTsKICAgICAgICAgICAgeSA9IGJbaV07CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoeCA8IHkpCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHkgPCB4KQogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgcmV0dXJuIDA7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjguaXNFbmNvZGluZyA9IGZ1bmN0aW9uIGlzRW5jb2RpbmcoZW5jb2RpbmcpIHsKICAgICAgICBzd2l0Y2ggKFN0cmluZyhlbmNvZGluZykudG9Mb3dlckNhc2UoKSkgewogICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgY2FzZSAidXRmLTgiOgogICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgY2FzZSAibGF0aW4xIjoKICAgICAgICAgIGNhc2UgImJpbmFyeSI6CiAgICAgICAgICBjYXNlICJiYXNlNjQiOgogICAgICAgICAgY2FzZSAidWNzMiI6CiAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgIGNhc2UgInV0Zi0xNmxlIjoKICAgICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICB9OwogICAgICBCdWZmZXI4LmNvbmNhdCA9IGZ1bmN0aW9uIGNvbmNhdChsaXN0LCBsZW5ndGgpIHsKICAgICAgICBpZiAoIUFycmF5LmlzQXJyYXkobGlzdCkpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJyJsaXN0IiBhcmd1bWVudCBtdXN0IGJlIGFuIEFycmF5IG9mIEJ1ZmZlcnMnKTsKICAgICAgICB9CiAgICAgICAgaWYgKGxpc3QubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gQnVmZmVyOC5hbGxvYygwKTsKICAgICAgICB9CiAgICAgICAgbGV0IGk7CiAgICAgICAgaWYgKGxlbmd0aCA9PT0gdm9pZCAwKSB7CiAgICAgICAgICBsZW5ndGggPSAwOwogICAgICAgICAgZm9yIChpID0gMDsgaSA8IGxpc3QubGVuZ3RoOyArK2kpIHsKICAgICAgICAgICAgbGVuZ3RoICs9IGxpc3RbaV0ubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIgPSBCdWZmZXI4LmFsbG9jVW5zYWZlKGxlbmd0aCk7CiAgICAgICAgbGV0IHBvcyA9IDA7CiAgICAgICAgZm9yIChpID0gMDsgaSA8IGxpc3QubGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGxldCBidWYgPSBsaXN0W2ldOwogICAgICAgICAgaWYgKGlzSW5zdGFuY2UoYnVmLCBVaW50OEFycmF5KSkgewogICAgICAgICAgICBpZiAocG9zICsgYnVmLmxlbmd0aCA+IGJ1ZmZlci5sZW5ndGgpIHsKICAgICAgICAgICAgICBpZiAoIUJ1ZmZlcjguaXNCdWZmZXIoYnVmKSkKICAgICAgICAgICAgICAgIGJ1ZiA9IEJ1ZmZlcjguZnJvbShidWYpOwogICAgICAgICAgICAgIGJ1Zi5jb3B5KGJ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BzdHJpbmcubGVuZ3RoOwogICAgICAgIGNvbnN0IG11c3RNYXRjaCA9IGFyZ3VtZW50cy5sZW5ndGggPiAyICYmIGFyZ3VtZW50c1syXSA9PT0gdHJ1ZTsKICAgICAgICBpZiAoIW11c3RNYXRjaCAmJiBsZW4gPT09IDApCiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICBsZXQgbG93ZXJlZENhc2UgPSBmYWxzZTsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsZW47CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhUb0J5dGVzKHN0cmluZykubGVuZ3RoOwogICAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gKiAyOwogICAgICAgICAgICBjYXNlICJoZXgiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gPj4+IDE7CiAgICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICAgICAgcmV0dXJuIGJhc2U2NFRvQnl0ZXMoc3RyaW5nKS5sZW5ndGg7CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgaWYgKGxvd2VyZWRDYXNlKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gbXVzdE1hdGNoID8gLTEgOiB1dGY4VG9CeXRlcyhzdHJpbmcpLmxlbmd0aDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgZW5jb2RpbmcgPSAoIiIgKyBlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgICAgICBsb3dlcmVkQ2FzZSA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIEJ1ZmZlcjguYnl0ZUxlbmd0aCA9IGJ5dGVMZW5ndGg7CiAgICAgIGZ1bmN0aW9uIHNsb3dUb1N0cmluZyhlbmNvZGluZywgc3RhcnQsIGVuZCkgewogICAgICAgIGxldCBsb3dlcmVkQ2FzZSA9IGZhbHNlOwogICAgICAgIGlmIChzdGFydCA9PT0gdm9pZCAwIHx8IHN0YXJ0IDwgMCkgewogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPiB0aGlzLmxlbmd0aCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kID09PSB2b2lkIDAgfHwgZW5kID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kIDw9IDApIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgZW5kID4+Pj0gMDsKICAgICAgICBzdGFydCA+Pj49IDA7CiAgICAgICAgaWYgKGVuZCA8PSBzdGFydCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoIWVuY29kaW5nKQogICAgICAgICAgZW5jb2RpbmcgPSAidXRmOCI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgICAgICByZXR1cm4gaGV4U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICAgIHJldHVybiBhc2NpaVNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsYXRpbjFTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjE2bGVTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gKGVuY29kaW5nICsgIiIpLnRvTG93ZXJDYXNlKCk7CiAgICAgICAgICAgICAgbG93ZXJlZENhc2UgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBCdWZmZXI4LnByb3RvdHlwZS5faXNCdWZmZXIgPSB0cnVlOwogICAgICBmdW5jdGlvbiBzd2FwKGIsIG4sIG0pIHsKICAgICAgICBjb25zdCBpID0gYltuXTsKICAgICAgICBiW25dID0gYlttXTsKICAgICAgICBiW21dID0gaTsKICAgICAgfQogICAgICBCdWZmZXI4LnByb3RvdHlwZS5zd2FwMTYgPSBmdW5j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9yIChsZXQgaSA9IDA7IGkgPCBsZW47IGkgKz0gOCkgewogICAgICAgICAgc3dhcCh0aGlzLCBpLCBpICsgNyk7CiAgICAgICAgICBzd2FwKHRoaXMsIGkgKyAxLCBpICsgNik7CiAgICAgICAgICBzd2FwKHRoaXMsIGkgKyAyLCBpICsgNSk7CiAgICAgICAgICBzd2FwKHRoaXMsIGkgKyAzLCBpICsgNCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0aGlzOwogICAgICB9OwogICAgICBCdWZmZXI4LnByb3RvdHlwZS50b1N0cmluZyA9IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgIGNvbnN0IGxlbmd0aCA9IHRoaXMubGVuZ3RoOwogICAgICAgIGlmIChsZW5ndGggPT09IDApCiAgICAgICAgICByZXR1cm4gIiI7CiAgICAgICAgaWYgKGFyZ3VtZW50cy5sZW5ndGggPT09IDApCiAgICAgICAgICByZXR1cm4gdXRmOFNsaWNlKHRoaXMsIDAsIGxlbmd0aCk7CiAgICAgICAgcmV0dXJuIHNsb3dUb1N0cmluZy5hcHBseSh0aGlzLCBhcmd1bWVudHMpOwogICAgICB9OwogICAgICBCdWZmZXI4LnByb3RvdHlwZS50b0xvY2FsZVN0cmluZyA9IEJ1ZmZlcjgucHJvdG90eXBlLnRvU3RyaW5nOwogICAgICBCdWZmZXI4LnByb3RvdHlwZS5lcXVhbHMgPSBmdW5jdGlvbiBlcXVhbHMoYikgewogICAgICAgIGlmICghQnVmZmVyOC5pc0J1ZmZlcihiKSkKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoIkFyZ3VtZW50IG11c3QgYmUgYSBCdWZmZXIiKTsKICAgICAgICBpZiAodGhpcyA9PT0gYikKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIHJldHVybiBCdWZmZXI4LmNvbXBhcmUodGhpcywgYikgPT09IDA7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjgucHJvdG90eXBlLmluc3BlY3QgPSBmdW5j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Agc3RhcnQgPSAwOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kID09PSB2b2lkIDApIHsKICAgICAgICAgIGVuZCA9IHRhcmdldCA/IHRhcmdldC5sZW5ndGggOiAwOwogICAgICAgIH0KICAgICAgICBpZiAodGhpc1N0YXJ0ID09PSB2b2lkIDApIHsKICAgICAgICAgIHRoaXNTdGFydCA9IDA7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzRW5kID09PSB2b2lkIDApIHsKICAgICAgICAgIHRoaXNFbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0IDwgMCB8fCBlbmQgPiB0YXJnZXQubGVuZ3RoIHx8IHRoaXNTdGFydCA8IDAgfHwgdGhpc0VuZCA+IHRoaXMubGVuZ3RoKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigib3V0IG9mIHJhbmdlIGluZGV4Iik7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzU3RhcnQgPj0gdGhpc0VuZCAmJiBzdGFydCA+PSBlbmQpIHsKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICBpZiAodGhpc1N0YXJ0ID49IHRoaXNFbmQpIHsKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0ID49IGVuZCkgewogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgfQogICAgICAgIHN0YXJ0ID4+Pj0gMDsKICAgICAgICBlbmQgPj4+PSAwOwogICAgICAgIHRoaXNTdGFydCA+Pj49IDA7CiAgICAgICAgdGhpc0VuZCA+Pj49IDA7CiAgICAgICAgaWYgKHRoaXMgPT09IHRhcmdldCkKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIGxldCB4ID0gdGhpc0VuZCAtIHRoaXNTdGFydDsKICAgICAgICBsZXQgeSA9IGVuZCAtIHN0YXJ0OwogICAgICAgIGNvbnN0IGxlbiA9IE1hdGgubWluKHgsIH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RlT2Zmc2V0OwogICAgICAgIGlmIChudW1iZXJJc05hTihieXRlT2Zmc2V0KSkgewogICAgICAgICAgYnl0ZU9mZnNldCA9IGRpciA/IDAgOiBidWZmZXIubGVuZ3RoIC0gMTsKICAgICAgICB9CiAgICAgICAgaWYgKGJ5dGVPZmZzZXQgPCAwKQogICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggKyBieXRlT2Zmc2V0OwogICAgICAgIGlmIChieXRlT2Zmc2V0ID49IGJ1ZmZlci5sZW5ndGgpIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgIGVsc2UKICAgICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggLSAxOwogICAgICAgIH0gZWxzZSBpZiAoYnl0ZU9mZnNldCA8IDApIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIGJ5dGVPZmZzZXQgPSAwOwogICAgICAgICAgZWxzZQogICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAic3RyaW5nIikgewogICAgICAgICAgdmFsID0gQnVmZmVyOC5mcm9tKHZhbCwgZW5jb2RpbmcpOwogICAgICAgIH0KICAgICAgICBpZiAoQnVmZmVyOC5pc0J1ZmZlcih2YWwpKSB7CiAgICAgICAgICBpZiAodmFsLmxlbmd0aCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gYXJyYXlJbmRleE9mKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKTsKICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiB2YWwgPT09ICJudW1iZXIiKSB7CiAgICAgICAgICB2YWwgPSB2YWwgJiAyNTU7CiAgICAgICAgICBpZiAodHlwZW9mIFVpbnQ4QXJyYXkucHJvdG90eXBlLmluZGV4T2YgPT09ICJmdW5jdGlvbiIpIHsKICAgICAgICAgICAgaWYgKGRpcikgewogICAgICAgICAgICAgIHJldHVybiBVaW50OEFycmF5LnByb3RvdHlwZS5pbmRleE9mLmNhbGwoYnVmZmVyLCB2YWwsIGJ5dGVPZmZzZXQpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHJldHVybiBVaW50OEFycmF5LnByb3RvdHlwZS5sYXN0SW5kZXhPZi5jYWxsKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGFycmF5SW5kZXhPZihidWZmZXIsIFt2YWxdLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKTsKICAgICAgICB9CiAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigidmFsIG11c3QgYmUgc3RyaW5nLCBudW1iZXIgb3IgQnVmZmVyIik7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXJyYXlJbmRleE9mKGFyciwgdmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKSB7CiAgICAgICAgbGV0IGluZGV4U2l6ZSA9IDE7CiAgICAgICAgbGV0IGFyckxlbmd0aCA9IGFyci5sZW5ndGg7CiAgICAgICAgbGV0IHZhbExlbmd0aCA9IHZhbC5sZW5ndGg7CiAgICAgICAgaWYgKGVuY29kaW5nICE9PSB2b2lkIDApIHsKICAgICAgICAgIGVuY29kaW5nID0gU3RyaW5nKGVuY29kaW5nKS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgaWYgKGVuY29kaW5nID09PSAidWNzMiIgfHwgZW5jb2RpbmcgPT09ICJ1Y3MtMiIgfHwgZW5jb2RpbmcgPT09ICJ1dGYxNmxlIiB8fCBlbmNvZGluZyA9PT0gInV0Zi0xNmxlIikgewogICAgICAgICAgICBpZiAoYXJyLmxlbmd0aCA8IDIgfHwgdmFsLmxlbmd0aCA8IDIpIHsKICAgICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaW5kZXhTaXplID0gMjsKICAgICAgICAgICAgYXJyTGVuZ3RoIC89IDI7CiAgICAgICAgICAgIHZhbExlbmd0aCAvPSAyOwogICAgICAgICAgICBieXRlT2Zmc2V0IC89IDI7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHJlYWQoYnVmLCBpMikgewogICAgICAgICAgaWYgKGluZGV4U2l6ZSA9PT0gMSkgewogICAgICAgICAgICByZXR1cm4gYnVmW2kyXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHJldHVybiBidWYucmVhZFVJbnQxNkJFKGkyICogaW5kZXhTaXplKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgbGV0IGk7CiAgICAgICAgaWYgKGRpcikgewogICAgICAgICAgbGV0IGZvdW5kSW5kZXggPSAtMTsKICAgICAgICAgIGZvciAoaSA9IGJ5dGVPZmZzZXQ7IGkgPCBhcnJMZW5ndGg7IGkrKykgewogICAgICAgICAgICBpZiAocmVhZChhcnIsIGkpID09PSByZWFkKHZhbCwgZm91bmRJbmRleCA9PT0gLTEgPyAwIDogaSAtIGZvdW5kSW5kZXgpKSB7CiAgICAgICAgICAgICAgaWYgKGZvdW5kSW5kZXggPT09IC0xKQogICAgICAgICAgICAgICAgZm91bmRJbmRleCA9IGk7CiAgICAgICAgICAgICAgaWYgKGkgLSBmb3VuZEluZGV4ICsgMSA9PT0gdmFsTGVuZ3RoKQogICAgICAgICAgICAgICAgcmV0dXJuIGZvdW5kSW5kZXggKiBpbmRleFNpemU7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgaWYgKGZvdW5kSW5kZXggIT09IC0xKQogICAgICAgICAgICAgICAgaSAtPSBpIC0gZm91bmRJbmRleDsKICAgICAgICAgICAgICBmb3VuZEluZGV4ID0gLTE7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKGJ5dGVPZmZzZXQgKyB2YWxMZW5ndGggPiBhcnJMZW5ndGgpCiAgICAgICAgICAgIGJ5dGVPZmZzZXQgPSBhcnJMZW5ndGggLSB2YWxMZW5ndGg7CiAgICAgICAgICBmb3IgKGkgPSBieXRlT2Zmc2V0OyBpID49IDA7IGktLSkgewogICAgICAgICAgICBsZXQgZm91bmQgPSB0cnVlOwogICAgICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IHZhbExlbmd0aDsgaisrKSB7CiAgICAgICAgICAgICAgaWYgKHJlYWQoYXJyLCBpICsgaikgIT09IHJlYWQodmFsLCBqKSkgewogICAgICAgICAgICAgICAgZm91bmQgPSBmYWxzZTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoZm91bmQpCiAgICAgICAgICAgICAgcmV0dXJuIGk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiAtMTsKICAgICAgfQogICAgICBCdWZmZXI4LnByb3RvdHlwZS5pbmNsdWRlcyA9IGZ1bmN0aW9uIGluY2x1ZGVzKHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcpIHsKICAgICAgICByZXR1cm4gdGhpcy5pbmRleE9mKHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcpICE9PSAtMTsKICAgICAgfTsKICAgICAgQnVmZmVyOC5wcm90b3R5cGUuaW5kZXhPZiA9IGZ1bmN0aW9uIGluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiBiaWRpcmVjdGlvbmFsSW5kZXhPZih0aGlzLCB2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nLCB0cnVlKTsKICAgICAgfTsKICAgICAgQnVmZmVyOC5wcm90b3R5cGUubGFzdEluZGV4T2YgPSBmdW5jdGlvbiBsYXN0SW5kZXhPZih2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nKSB7CiAgICAgICAgcmV0dXJuIGJpZGlyZWN0aW9uYWxJbmRleE9mKHRoaXMsIHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGZhbHNlKTsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gaGV4V3JpdGUoYnVmLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKSB7CiAgICAgICAgb2Zmc2V0ID0gTnVtYmVyKG9mZnNldCkgfHwgMDsKICAgICAgICBjb25zdCByZW1haW5pbmcgPSBidWYubGVuZ3RoIC0gb2Zmc2V0OwogICAgICAgIGlmICghbGVuZ3RoKSB7CiAgICAgICAgICBsZW5ndGggPSByZW1haW5pbmc7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGxlbmd0aCA9IE51bWJlcihsZW5ndGgpOwogICAgICAgICAgaWYgKGxlbmd0aCA+IHJlbWFpbmluZykgewogICAgICAgICAgICBsZW5ndGggPSByZW1haW5pbmc7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvbnN0IHN0ckxlbiA9IHN0cmluZy5sZW5ndGg7CiAgICAgICAgaWYgKGxlbmd0aCA+IHN0ckxlbiAvIDIpIHsKICAgICAgICAgIGxlbmd0aCA9IHN0ckxlbiAvIDI7CiAgICAgICAgfQogICAgICAgIGxldCBpOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsZW5ndGg7ICsraSkgewogICAgICAgICAgY29uc3QgcGFyc2VkID0gcGFyc2VJbnQoc3RyaW5nLnN1YnN0cihpICogMiwgMiksIDE2KTsKICAgICAgICAgIGlmIChudW1iZXJJc05hTihwYXJzZWQpKQogICAgICAgICAgICByZXR1cm4gaTsKICAgICAgICAgIGJ1ZltvZmZzZXQgKyBpXSA9IHBhcnNlZDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdXRmOFdyaXRlKGJ1Ziwgc3RyaW5nLCBvZ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AgICAgICAgZW5jb2RpbmcgPSAidXRmOCI7CiAgICAgICAgbGV0IGxvd2VyZWRDYXNlID0gZmFsc2U7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBzd2l0Y2ggKGVuY29kaW5nKSB7CiAgICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICAgICAgcmV0dXJuIGhleFdyaXRlKHRoaXMsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpOwogICAgICAgICAgICBjYXNlICJ1dGY4IjoKICAgICAgICAgICAgY2FzZSAidXRmLTgiOgogICAgICAgICAgICAgIHJldHVybiB1dGY4V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgICAgY2FzZSAibGF0aW4xIjoKICAgICAgICAgICAgY2FzZSAiYmluYXJ5IjoKICAgICAgICAgICAgICByZXR1cm4gYXNjaWlXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHVjczJXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gK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CiAgICAgICAgICBpZiAoaSArIGJ5dGVzUGVyU2VxdWVuY2UgPD0gZW5kKSB7CiAgICAgICAgICAgIGxldCBzZWNvbmRCeXRlLCB0aGlyZEJ5dGUsIGZvdXJ0aEJ5dGUsIHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgIHN3aXRjaCAoYnl0ZXNQZXJTZXF1ZW5jZSkgewogICAgICAgICAgICAgIGNhc2UgMToKICAgICAgICAgICAgICAgIGlmIChmaXJzdEJ5dGUgPCAxMjgpIHsKICAgICAgICAgICAgICAgICAgY29kZVBvaW50ID0gZmlyc3RCeXRlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgc2Vjb25kQnl0ZSA9IGJ1ZltpICsgMV07CiAgICAgICAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAzMSkgPDwgNiB8IHNlY29uZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAxMjcpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIDM6CiAgICAgICAgICAgICAgICBzZWNvbmRCeXRlID0gYnVmW2kgKyAxXTsKICAgICAgICAgICAgICAgIHRoaXJkQnl0ZSA9IGJ1ZltpICsgMl07CiAgICAgICAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKHRoaXJkQnl0ZSAmIDE5MikgPT09IDEyOCkgewogICAgICAgICAgICAgICAgICB0ZW1wQ29kZVBvaW50ID0gKGZpcnN0Qnl0ZSAmIDE1KSA8PCAxMiB8IChzZWNvbmRCeXRlICYgNjMpIDw8IDYgfCB0aGlyZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAyMDQ3ICYmICh0ZW1wQ29kZVBvaW50IDwgNTUyOTYgfHwgdGVtcENvZGVQb2ludCA+IDU3MzQzKSkgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgICAgIHNlY29uZEJ5dGUgPSBidWZbaSArIDFdOwogICAgICAgICAgICAgICAgdGhpcmRCeXRlID0gYnVmW2kgKyAyXTsKICAgICAgICAgICAgICAgIGZvdXJ0aEJ5dGUgPSBidWZbaSArIDNdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmICh0aGlyZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKGZvdXJ0aEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAxNSkgPDwgMTggfCAoc2Vjb25kQnl0ZSAmIDYzKSA8PCAxMiB8ICh0aGlyZEJ5dGUgJiA2MykgPDwgNiB8IGZvdXJ0aEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiA2NTUzNSAmJiB0ZW1wQ29kZVBvaW50IDwgMTExNDExMikgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKGNvZGVQb2ludCA9PT0gbnVsbCkgewogICAgICAgICAgICBjb2RlUG9pbnQgPSA2NTUzMzsKICAgICAgICAgICAgYnl0ZXNQZXJTZXF1ZW5jZSA9IDE7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA+IDY1NTM1KSB7CiAgICAgICAgICAgIGNvZGVQb2ludCAtPSA2NTUzNjsKICAgICAgICAgICAgcmVzLnB1c2goY29kZVBvaW50ID4+PiAxMCAmIDEwMjMgfCA1NTI5Nik7CiAgICAgICAgICAgIGNvZGVQb2ludCA9IDU2MzIwIHwgY29kZVBvaW50ICYgMTAyMzsKICAgICAgICAgIH0KICAgICAgICAgIHJlcy5wdXNoKGNvZGVQb2ludCk7CiAgICAgICAgICBpICs9IGJ5dGVzUGVyU2VxdWVuY2U7CiAgICAgICAgfQogICAgICAgIHJldHVybiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkocmVzKTsKICAgICAgfQogICAgICB2YXIgTUFYX0FSR1VNRU5UU19MRU5HVEggPSA0MDk2OwogICAgICBmdW5jdGlvbiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkoY29kZVBvaW50cykgewogICAgICAgIGNvbnN0IGxlbiA9IGNvZGVQb2ludHMubGVuZ3RoOwogICAgICAgIGlmIChsZW4gPD0gTUFYX0FSR1VNRU5UU19MRU5HVEgpIHsKICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cyk7CiAgICAgICAgfQogICAgICAgIGxldCByZXMgPSAiIjsKICAgICAgICBsZXQgaSA9IDA7CiAgICAgICAgd2hpbGUgKGkgPCBsZW4pIHsKICAgICAgICAgIHJlcyArPSBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cy5zbGljZShpLCBpICs9IE1BWF9BUkdVTUVOVFNfTEVOR1RIKSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXNjaWlTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldICYgMTI3KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBsYXRpbjFTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBoZXhTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBjb25zdCBsZW4gPSBidWYubGVuZ3RoOwogICAgICAgIGlmICghc3RhcnQgfHwgc3RhcnQgPCAwKQogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIGlmICghZW5kIHx8IGVuZCA8IDAgfHwgZW5kID4gbGVuKQogICAgICAgICAgZW5kID0gbGVuOwogICAgICAgIGxldCBvdXQgPSAiIjsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgb3V0ICs9IGhleFNsaWNlTG9va3VwVGFibGVbYnVmW2ldXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG91dDsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGYxNmxlU2xpY2UoYnVmLCBzdGFydCwgZW5kKS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AgICB9IGVsc2UgewogICAgICAgICAgVWludDhBcnJheS5wcm90b3R5cGUuc2V0LmNhbGwodGFyZ2V0LCB0aGlzLnN1YmFycmF5KHN0YXJ0LCBlbmQpLCB0YXJnZXRTdGFydCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBsZW47CiAgICAgIH07CiAgICAgIEJ1ZmZlcjgucHJvdG90eXBlLmZpbGwgPSBmdW5jdGlvbiBmaWxsKHZhbCwgc3RhcnQsIGVuZCwgZW5jb2RpbmcpIHsKICAgICAgICBpZiAodHlwZW9mIHZhbCA9PT0gInN0cmluZyIpIHsKICAgICAgICAgIGlmICh0eXBlb2Ygc3RhcnQgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIGVuY29kaW5nID0gc3RhcnQ7CiAgICAgICAgICAgIHN0YXJ0ID0gMDsKICAgICAgICAgICAgZW5kID0gdGhpcy5sZW5ndGg7CiAgICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBlbmQgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIGVuY29kaW5nID0gZW5kOwogICAgICAgICAgICBlbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChlbmNvZGluZyAhPT0gdm9pZCAwICYmIHR5cGVvZiBlbmNvZGluZyAhPT0gInN0cmluZyIpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiZW5jb2RpbmcgbXVzdCBiZSBhIHN0cmluZyIpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHR5cGVvZiBlbmNvZGluZyA9PT0gInN0cmluZyIgJiYgIUJ1ZmZlcjguaXNFbmNvZGluZyhlbmNvZGluZykpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiVW5rbm93biBlbmNvZGluZzogIiArIGVuY29kaW5nKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh2YWwubGVuZ3RoID09PSAxKSB7CiAgICAgICAgICAgIGNvbnN0IGNvZGUgPSB2YWwuY2hhckNvZGVBdCgwKTsKICAgICAgICAgICAgaWYgKGVuY29kaW5nID09PSAidXRmOCIgJiYgY29kZSA8IDEyOCB8fCBlbmNvZGluZyA9PT0gImxhdGluMSIpIHsKICAgICAgICAgICAgICB2YWwgPSBjb2RlOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgdmFsID0gdmFsICYgMjU1OwogICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHZhbCA9PT0gImJvb2xlYW4iKSB7CiAgICAgICAgICB2YWwgPSBOdW1iZXIodmFsKTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0IDwgMCB8fCB0aGlzLmxlbmd0aCA8IHN0YXJ0IHx8IHRoaXMubGVuZ3RoIDwgZW5kKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiT3V0IG9mIHJhbmdlIGluZGV4Iik7CiAgICAgICAgfQogICAgICAgIGlmIChlbmQgPD0gc3RhcnQpIHsKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIH0KICAgICAgICBzdGFydCA9IHN0YXJ0ID4+PiAwOwogICAgICAgIGVuZCA9IGVuZCA9PT0gdm9pZCAwID8gdGhpcy5sZW5ndGggOiBlbmQgPj4+IDA7CiAgICAgICAgaWYgKCF2YWwpCiAgICAgICAgICB2YWwgPSAwOwogICAgICAgIGxldCBpOwogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgZm9yIChpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgICB0aGlzW2ldID0gdmFsOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBjb25zdCBieXRlcyA9IEJ1ZmZlcjguaXNCdWZmZXIodmFsKSA/IHZhbCA6IEJ1ZmZlcjguZnJvbSh2YWwsIGVuY29kaW5nKTsKICAgICAgICAgIGNvbnN0IGxlbiA9IGJ5dGVzLmxlbmd0aDsKICAgICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignVGhlIHZhbHVlICInICsgdmFsICsgJyIgaXMgaW52YWxpZCBmb3IgYXJndW1lbnQgInZhbHVlIicpOwogICAgICAgICAgfQogICAgICAgICAgZm9yIChpID0gMDsgaSA8IGVuZCAtIHN0YXJ0OyArK2kpIHsKICAgICAgICAgICAgdGhpc1tpICsgc3RhcnRdID0gYnl0ZXNbaSAlIGxlbl07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiB0aGlzOwogICAgICB9OwogICAgICB2YXIgZXJyb3JzID0ge307CiAgICAgIGZ1bmN0aW9uIEUoc3ltLCBnZXRNZXNzYWdlLCBCYXNlKSB7CiAgICAgICAgZXJyb3JzW3N5bV0gPSBjbGFzcyBOb2RlRXJyb3IgZXh0ZW5kcyBCYXNlIHsKICAgICAgICAgIGNvbnN0cnVjdG9yKCkgewogICAgICAgICAgICBzdXBlcigpOwogICAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgIm1lc3NhZ2UiLCB7CiAgICAgICAgICAgICAgdmFsdWU6IGdldE1lc3NhZ2UuYXBwbHkodGhpcywgYXJndW1lbnRzKSwKICAgICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIHRoaXMubmFtZSA9IGAke3RoaXMubmFtZX0gWyR7c3ltfV1gOwogICAgICAgICAgICB0aGlzLnN0YWNrOwogICAgICAgICAgICBkZWxldGUgdGhpcy5uYW1lOwogICAgICAgICAgfQogICAgICAgICAgZ2V0IGNvZGUoKSB7CiAgICAgICAgICAgIHJldHVybiBzeW07CiAgICAgICAgICB9CiAgICAgICAgICBzZXQgY29kZSh2YWx1ZSkgewogICAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgImNvZGUiLCB7CiAgICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlLAogICAgICAgICAgICAgIGVudW1lcmFibGU6IHRydWUsCiAgICAgICAgICAgICAgdmFsdWUsCiAgICAgICAgICAgICAgd3JpdGFibGU6IHRydWUKICAgICAgICAgICAgfSk7CiAgICAgICAgICB9CiAgICAgICAgICB0b1N0cmluZygpIHsKICAgICAgICAgICAgcmV0dXJuIGAke3RoaXMubmFtZX0gWyR7c3ltfV06ICR7dGhpcy5tZXNzYWdlfWA7CiAgICAgICAgICB9CiAgICAgICAgfTsKICAgICAgfQogICAgICBFKCJFUlJfQlVGRkVSX09VVF9PRl9CT1VORFMiLCBmdW5jdGlvbihuYW1lKSB7CiAgICAgICAgaWYgKG5hbWUpIHsKICAgICAgICAgIHJldHVybiBgJHtuYW1lfSBpcyBvdXRzaWRlIG9mIGJ1ZmZlciBib3VuZHNgOwogICAgICAgIH0KICAgICAgICByZXR1cm4gIkF0dGVtcHQgdG8gYWNjZXNzIG1lbW9yeSBvdXRzaWRlIGJ1ZmZlciBib3VuZHMiOwogICAgICB9LCBSYW5nZUVycm9yKTsKICAgICAgRSgiRVJSX0lOVkFMSURfQVJHX1RZUEUiLCBmdW5jdGlvbihuYW1lLCBhY3R1YWwpIHsKICAgICAgICByZXR1cm4gYFRoZSAiJHtuYW1lfSIgYXJndW1lbnQgbXVzdCBiZSBvZiB0eXBlIG51bWJlci4gUmVjZWl2ZWQgdHlwZSAke3R5cGVvZiBhY3R1YWx9YDsKICAgICAgfSwgVHlwZUVycm9yKTsKICAgICAgRSgiRVJSX09VVF9PRl9SQU5HRSIsIGZ1bmN0aW9uKHN0ciwgcmFuZ2UsIGlucHV0KSB7CiAgICAgICAgbGV0IG1zZyA9IGBUaGUgdmFsdWUgb2YgIiR7c3RyfSIgaXMgb3V0IG9mIHJhbmdlLmA7CiAgICAgICAgbGV0IHJlY2Vpd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TsKICAgICAgICBzdHIgPSBzdHIudHJpbSgpLnJlcGxhY2UoSU5WQUxJRF9CQVNFNjRfUkUsICIiKTsKICAgICAgICBpZiAoc3RyLmxlbmd0aCA8IDIpCiAgICAgICAgICByZXR1cm4gIiI7CiAgICAgICAgd2hpbGUgKHN0ci5sZW5ndGggJSA0ICE9PSAwKSB7CiAgICAgICAgICBzdHIgPSBzdHIgKyAiPSI7CiAgICAgICAgfQogICAgICAgIHJldHVybiBzdHI7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdXRmOFRvQnl0ZXMoc3RyaW5nLCB1bml0cykgewogICAgICAgIHVuaXRzID0gdW5pdHMgfHwgSW5maW5pdHk7CiAgICAgICAgbGV0IGNvZGVQb2ludDsKICAgICAgICBjb25zdCBsZW5ndGggPSBzdHJpbmcubGVuZ3RoOwogICAgICAgIGxldCBsZWFkU3Vycm9nYXRlID0gbnVsbDsKICAgICAgICBjb25zdCBieXRlcyA9IFtdOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGNvZGVQb2ludCA9IHN0cmluZy5jaGFyQ29kZUF0KGkpOwogICAgICAgICAgaWYgKGNvZGVQb2ludCA+IDU1Mjk1ICYmIGNvZGVQb2ludCA8IDU3MzQ0KSB7CiAgICAgICAgICAgIGlmICghbGVhZFN1cnJvZ2F0ZSkgewogICAgICAgICAgICAgIGlmIChjb2RlUG9pbnQgPiA1NjMxOSkgewogICAgICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChpICsgMSA9PT0gbGVuZ3RoKSB7CiAgICAgICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgbGVhZFN1cnJvZ2F0ZSA9IGNvZGVQb2ludDsKICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoY29kZVBvaW50IDwgNTYzMjApIHsKICAgICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgICAgIGxlYWRTdXJyb2dhdGUgPSBjb2RlUG9pbnQ7CiAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY29kZVBvaW50ID0gKGxlYWRTdXJyb2dhdGUgLSA1NTI5NiA8PCAxMCB8IGNvZGVQb2ludCAtIDU2MzIwKSArIDY1NTM2OwogICAgICAgICAgfSBlbHNlIGlmIChsZWFkU3Vycm9nYXRlKSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgfQogICAgICAgICAgbGVhZFN1cnJvZ2F0ZSA9IG51bGw7CiAgICAgICAgICBpZiAoY29kZVBvaW50IDwgMTI4KSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMSkgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA8IDIwNDgpIHsKICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAyKSA8IDApCiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGJ5dGVzLnB1c2goY29kZVBvaW50ID4+IDYgfCAxOTIsIGNvZGVQb2ludCAmIDYzIHwgMTI4KTsKICAgICAgICAgIH0gZWxzZSBpZiA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VybiBPYmplY3QuYXNzaWduKEVycm9yKG1lc3NhZ2UubWVzc2FnZSksIHsKICAgICAgICAgICAgbmFtZTogbWVzc2FnZS5uYW1lLAogICAgICAgICAgICBzdGFjazogbWVzc2FnZS5zdGFjawogICAgICAgICAgfSk7CiAgICAgICAgfSwKICAgICAgICBzZXJpYWxpemUoZXJyb3IpIHsKICAgICAgICAgIHJldHVybiB7CiAgICAgICAgICAgIF9fZXJyb3JfbWFya2VyOiAiJCRlcnJvciIsCiAgICAgICAgICAgIG1lc3NhZ2U6IGVycm9yLm1lc3NhZ2UsCiAgICAgICAgICAgIG5hbWU6IGVycm9yLm5hbWUsCiAgICAgICAgICAgIHN0YWNrOiBlcnJvci5zdGFjawogICAgICAgICAgfTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIHZhciBpc1NlcmlhbGl6ZWRFcnJvciA9ICh0aGluZykgPT4gdGhpbmcgJiYgdHlwZW9mIHRoaW5nID09PSAib2JqZWN0IiAmJiAiX19lcnJvcl9tYXJrZXIiIGluIHRoaW5nICYmIHRoaW5nLl9fZXJyb3JfbWFya2VyID09PSAiJCRlcnJvciI7CiAgICAgIGV4cG9ydHMuRGVmYXVsdFNlcmlhbGl6ZXIgPSB7CiAgICAgICAgZGVzZXJpYWxpemUobWVzc2FnZSkgewogICAgICAgICAgaWYgKGlzU2VyaWFsaXplZEVycm9yKG1lc3NhZ2UpKSB7CiAgICAgICAgICAgIHJldHVybiBEZWZhdWx0RXJyb3JTZXJpYWxpemVyLmRlc2VyaWFsaXplKG1lc3NhZ2UpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmV0dXJuIG1lc3NhZ2U7CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBzZXJpYWxpemUoaW5wdXQpIHsKICAgICAgICAgIGlmIChpbnB1dCBpbnN0YW5jZW9mIEVycm9yKSB7CiAgICAgICAgICAgIHJldHVybiBEZWZhdWx0RXJyb3JTZXJpYWxpemVyLnNlcmlhbGl6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AgICAgIHJldHVybiB2YWx1ZSBpbnN0YW5jZW9mIFAgPyB2YWx1ZSA6IG5ldyBQKGZ1bmN0aW9uKHJlc29sdmUpIHsKICAgICAgICAgICAgcmVzb2x2ZSh2YWx1ZSk7CiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG5ldyAoUCB8fCAoUCA9IFByb21pc2UpKShmdW5jdGlvbihyZXNvbHZlLCByZWplY3QpIHsKICAgICAgICAgIGZ1bmN0aW9uIGZ1bGZpbGxlZCh2YWx1ZSkgewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIHN0ZXAoZ2VuZXJhdG9yLm5leHQodmFsdWUpKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIHJlamVjdChlKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gcmVqZWN0ZWQodmFsdWUpIHsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBzdGVwKGdlbmVyYXRvclsidGhyb3ciXSh2YWx1ZSkpOwogICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgcmVqZWN0KGUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBzdGVwKHJlc3VsdCkgewogICAgICAgICAgICByZXN1bHQuZG9uZSA/IHJlc29sdmUocmVzdWx0LnZhbHVlKSA6IGFkb3B0KHJlc3VsdC52YWx1ZSkudGhlbihmdWxmaWxsZWQsIHJlamVjdGVkKTsKICAgICAgICAgIH0KICAgICAgICAgIHN0ZXAoKGdlbmVyYXRvciA9IGdlbmVyYXRvci5hcHBseSh0aGlzQXJnLCBfYXJndW1lbnRzIHx8IFtdKSkubmV4dCgpKTsKICAgICAgICB9KTsKICAgICAgfTsKICAgICAgdmFyIF9faW1wb3J0RGVmYXVsdCA9IGV4cG9ydHMgJiYgZXhwb3J0cy5fX2ltcG9ydERlZmF1bHQgfHwg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obmV3IFdlYkFzc2VtYmx5Lk1vZHVsZShuZXcgVWludDhBcnJheShbCiAgICAgICAgICAwLAogICAgICAgICAgOTcsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxLAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEzLAogICAgICAgICAgMiwKICAgICAgICAgIDk2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICA5NiwKICAgICAgICAgIDQsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMywKICAgICAgICAgIDcsCiAgICAgICAgICA2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgNiwKICAgICAgICAgIDYsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMSwKICAgICAgICAgIDY1LAogICAgICAgICAgMCwKICAgICAgICAgIDExLAogICAgICAgICAgNywKICAgICAgICAgIDUwLAogICAgICAgICAgNiwKICAgICAgICAgIDMsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxMTcsCiAgICAgICAgICAxMDgsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDUsCiAgICAgICAgICAxMDAsCiAgICAgICAgICAxMDUsCiAgICAgICAgICAxMTgsCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNSwKICAgICAgICAgIDAsCiAgICAgICAgICAyLAogICAgICAgICAgNSwKICAgICAgICAgIDEwMCwKICAgICAgICAgIDEwNSwKICAgICAgICAgIDExOCwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE3LAogICAgICAgICAgMCwKICAgICAgICAgIDMsCiAgICAgICAgICA1LAogICAgICAgICAgMTE0LAogICAgICAgICAgMTAxLAogICAgICAgICAgMTA5LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAwLAogICAgICAgICAgNCwKICAgICAgICAgIDUsCiAgICAgICAgICAxMTQsCiAgICAgICAgICAxMDEsCiAgICAgICAgICAxMDksCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNywKICAgICAgICAgIDAsCiAgICAgICAgICA1LAogICAgICAgICAgOCwKICAgICAgICAgIDEwMywKICAgICAgICAgIDEwMSwKICAgICAgICAgIDExNiwKICAgICAgICAgIDk1LAogICAgICAgICAgMTA0LAogICAgICAgICAgMTA1LAogICAgICAgICAgMTAzLAogICAgICAgICAgMTA0LAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAxMCwKICAgICAgICAgIDE5MSwKICAgICAgICAgIDEsCiAgICAgICAgICA2LAogICAgICAgICAgNCwKICAgICAgICAgIDAsCiAgICAgICAgICAzNSwKICAgICAgICAgIDAsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNywKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOSwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEzMCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMQogICAgICAgIF0pKSwge30pLmV4cG9ydHM7CiAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgfQogICAgICBmdW5jdGlvbiBMb25nNChsb3csIGhpZ2gsIHVuc2lnbmVkKSB7CiAgICAgICAgdGhpcy5sb3cgPSBsb3cgfCAwOwogICAgICAgIHRoaXMuaGlnaCA9IGhpZ2ggfCAwOwogICAgICAgIHRoaXMudW5zaWduZWQgPSAhIXVuc2lnbmVkOwogICAgICB9CiAgICAgIExvbmc0LnByb3RvdHlwZS5fX2lzTG9uZ19fOwogICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoTG9uZzQucHJvdG90eXBlLCAiX19pc0xvbmdfXyIsIHsgdmFsdWU6IHRydWUgfSk7CiAgICAgIGZ1bmN0aW9uIGlzTG9uZyhvYmopIHsKICAgICAgICByZXR1cm4gKG9iaiAmJiBvYmpbIl9faXNMb25nX18iXSkgPT09IHRydWU7CiAgICAgIH0KICAgICAgTG9uZzQuaXNMb25nID0gaXNMb25nOwogICAgICB2YXIgSU5UX0NBQ0hFID0ge307CiAgICAgIHZhciBVSU5UX0NBQ0hFID0ge307CiAgICAgIGZ1bmN0aW9uIGZyb21JbnQodmFsdWUsIHVuc2lnbmVkKSB7CiAgICAgICAgdmFyIG9iaiwgY2FjaGVkT2JqLCBjYWNoZTsKICAgICAgICBpZiAodW5zaWduZWQpIHsKICAgICAgICAgIHZhbHVlID4+Pj0gMDsKICAgICAgICAgIGlmIChjYWNoZSA9IDAgPD0gdmFsdWUgJiYgdmFsdWUgPCAyNTYpIHsKICAgICAgICAgICAgY2FjaGVkT2JqID0gVUlOVF9DQUNIRVt2YWx1ZV07CiAgICAgICAgICAgIGlmIChjYWNoZWRPYmopCiAgICAgICAgICAgICAgcmV0dXJuIGNhY2hlZE9iajsKICAgICAgICAgIH0KICAgICAgICAgIG9iaiA9IGZyb21CaXRzKHZhbHVlLCAodmFsdWUgfCAwKSA8IDAgPyAtMSA6IDAsIHRydWUpOwogICAgICAgICAgaWYgKGNhY2hlKQogICAgICAgICAgICBVSU5UX0NBQ0hFW3ZhbHVlXSA9IG9iajsKICAgICAgICAgIHJldHVybiBvYmo7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHZhbHVlIHw9IDA7CiAgICAgICAgICBpZiAoY2FjaGUgPSAtMTI4IDw9IHZhbHVlICYmIHZhbHVlIDwgMTI4KSB7CiAgICAgICAgICAgIGNhY2hlZE9iaiA9IElOVF9DQUNIRVt2YWx1ZV07CiAgICAgICAgICAgIGlmIChjYWNoZWRPYmopCiAgICAgICAgICAgICAgcmV0dXJuIGNhY2hlZE9iajsKICAgICAgICAgIH0KICAgICAgICAgIG9iaiA9IGZyb21CaXRzKHZhbHVlLCB2YWx1ZSA8IDAgPyAtMSA6IDAsIGZhbHNlKTsKICAgICAgICAgIGlmIChjYWNoZSkKICAgICAgICAgICAgSU5UX0NBQ0hFW3ZhbHVlXSA9IG9iajsKICAgICAgICAgIHJldHVybiBvYmo7CiAgICAgICAgfQogICAgICB9CiAgICAgIExvbmc0LmZyb21JbnQgPSBmcm9tSW50OwogICAgICBmdW5jdGlvbiBmcm9tTnVtYmVyKHZhbHVlLCB1bnNpZ25lZCkgewogICAgICAgIGlmIChpc05hTih2YWx1ZSkpCiAgICAgICAgICByZXR1cm4gdW5zaWduZWQgPyBVWkVSTyA6IFpFUk87CiAgICAgICAgaWYgKHVuc2lnbmVkKSB7CiAgICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAodmFsdWUgPj0gVFdPX1BXUl82NF9EQkwpCiAgICAgICAgICAgIHJldHVybiBNQVhfVU5TSUdORURfVkFMVUU7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGlmICh2YWx1ZSA8PSAtVFdPX1BXUl82M19EQkwpCiAgICAgICAgICAgIHJldHVybiBNSU5fVkFMVUU7CiAgICAgICAgICBpZiAodmFsdWUgKyAxID49IFRXT19QV1JfNjNfREJMKQogICAgICAgICAgICByZXR1cm4gTUFYX1ZBTFVFOwogICAgICAgIH0KICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgcmV0dXJuIGZyb21OdW1iZXIoLXZhbHVlLCB1bnNpZ25lZCkubmVnKCk7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHZhbHVlICUgVFdPX1BXUl8zMl9EQkwgfCAwLCB2YWx1ZSAvIFRXT19QV1JfMzJfREJMIHwgMCwgdW5zaWduZWQpOwogICAgICB9CiAgICAgIExvbmc0LmZyb21OdW1iZXIgPSBmcm9tTnVtYmVyOwogICAgICBmdW5jdGlvbiBmcm9tQml0cyhsb3dCaXRzLCBoaWdoQml0cywgdW5zaWduZWQpIHsKICAgICAgICByZXR1cm4gbmV3IExvbmc0KGxvd0JpdHMsIGhpZ2hCaXRzLCB1bnNpZ25lZCk7CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbUJpdHMgPSBmcm9tQml0czsKICAgICAgdmFyIHBvd19kYmwgPSBNYXRoLnBvdzsKICAgICAgZnVuY3Rpb24gZnJvbVN0cmluZyhzdHIsIHVuc2lnbmVkLCByYWRpeCkgewogICAgICAgIGlmIChzdHIubGVuZ3RoID09PSAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImVtcHR5IHN0cmluZyIpOwogICAgICAgIGlmIChzdHIgPT09ICJOYU4iIHx8IHN0ciA9PT0gIkluZmluaXR5IiB8fCBzdHIgPT09ICIrSW5maW5pdHkiIHx8IHN0ciA9PT0gIi1JbmZpbml0eSIpCiAgICAgICAgICByZXR1cm4gWkVSTzsKICAgICAgICBpZiAodHlwZW9mIHVuc2lnbmVkID09PSAibnVtYmVyIikgewogICAgICAgICAgcmFkaXggPSB1bnNpZ25lZCwgdW5zaWduZWQgPSBmYWxzZTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdW5zaWduZWQgPSAhIXVuc2lnbmVkOwogICAgICAgIH0KICAgICAgICByYWRpeCA9IHJhZGl4IHx8IDEwOwogICAgICAgIGlmIChyYWRpeCA8IDIgfHwgMzYgPCByYWRpeCkKICAgICAgICAgIHRocm93IFJhbmdlRXJyb3IoInJhZGl4Iik7CiAgICAgICAgdmFyIHA7CiAgICAgICAgaWYgKChwID0gc3RyLmluZGV4T2YoIi0iKSkgPiAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImludGVyaW9yIGh5cGhlbiIpOwogICAgICAgIGVsc2UgaWYgKHAgPT09IDApIHsKICAgICAgICAgIHJldHVybiBmcm9tU3RyaW5nKHN0ci5zdWJzdHJpbmcoMSksIHVuc2lnbmVkLCByYWRpeCkubmVnKCk7CiAgICAgICAgfQogICAgICAgIHZhciByYWRpeFRvUG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIDgpKTsKICAgICAgICB2YXIgcmVzdWx0ID0gWkVSTzsKICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IHN0ci5sZW5ndGg7IGkgKz0gOCkgewogICAgICAgICAgdmFyIHNpemUgPSBNYXRoLm1pbig4LCBzdHIubGVuZ3RoIC0gaSksIHZhbHVlID0gcGFyc2VJbnQoc3RyLnN1YnN0cmluZyhpLCBpICsgc2l6ZSksIHJhZGl4KTsKICAgICAgICAgIGlmIChzaXplIDwgOCkgewogICAgICAgICAgICB2YXIgcG93ZXIgPSBmcm9tTn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lwZS50b0ludCA9IGZ1bmN0aW9uIHRvSW50KCkgewogICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkID8gdGhpcy5sb3cgPj4+IDAgOiB0aGlzLmxvdzsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS50b051bWJlciA9IGZ1bmN0aW9uIHRvTnVtYmVyKCkgewogICAgICAgIGlmICh0aGlzLnVuc2lnbmVkKQogICAgICAgICAgcmV0dXJuICh0aGlzLmhpZ2ggPj4+IDApICogVFdPX1BXUl8zMl9EQkwgKyAodGhpcy5sb3cgPj4+IDApOwogICAgICAgIHJldHVybiB0aGlzLmhpZ2ggKiBUV09fUFdSXzMyX0RCTCArICh0aGlzLmxvdyA+Pj4gMCk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9TdHJpbmcgPSBmdW5jdGlvbiB0b1N0cmluZyhyYWRpeCkgewogICAgICAgIHJhZGl4ID0gcmFkaXggfHwgMTA7CiAgICAgICAgaWYgKHJhZGl4IDwgMiB8fCAzNiA8IHJhZGl4KQogICAgICAgICAgdGhyb3cgUmFuZ2VFcnJvcigicmFkaXgiKTsKICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiAiMCI7CiAgICAgICAgaWYgKHRoaXMuaXNOZWdhdGl2ZSgpKSB7CiAgICAgICAgICBpZiAodGhpcy5lcShNSU5fVkFMVUUpKSB7CiAgICAgICAgICAgIHZhciByYWRpeExvbmcgPSBmcm9tTnVtYmVyKHJhZGl4KSwgZGl2ID0gdGhpcy5kaXYocmFkaXhMb25nKSwgcmVtMSA9IGRpdi5tdWwocmFkaXhMb25nKS5zdWIodGhpcyk7CiAgICAgICAgICAgIHJldHVybiBkaXYudG9TdHJpbmcocmFkaXgpICsgcmVtMS50b0ludCgpLnRvU3RyaW5nKHJhZGl4KTsKICAgICAgICAgIH0gZWxzZQogICAgICAgICAgICByZXR1cm4gIi0iICsgdGhpcy5uZWcoKS50b1N0cmluZyhyYWRpeCk7CiAgICAgICAgfQogICAgICAgIHZhciByYWRpeFRvUG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIDYpLCB0aGlzLnVuc2lnbmVkKSwgcmVtID0gdGhpczsKICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHZhciByZW1EaXYgPSByZW0uZGl2KHJhZGl4VG9Qb3dlciksIGludHZhbCA9IHJlbS5zdWIocmVtRGl2Lm11bChyYWRpeFRvUG93ZXIpKS50b0ludCgpID4+PiAwLCBkaWdpdHMgPSBpbnR2YWwudG9TdHJpbmcocmFkaXgpOwogICAgICAgICAgcmVtID0gcmVtRGl2OwogICAgICAgICAgaWYgKHJlbS5pc1plcm8oKSkKICAgICAgICAgICAgcmV0dXJuIGRpZ2l0cyArIHJlc3VsdDsKICAgICAgICAgIGVsc2UgewogICAgICAgICAgICB3aGlsZSAoZGlnaXRzLmxlbmd0aCA8IDYpCiAgICAgICAgICAgICAgZGlnaXRzID0gIjAiICsgZGlnaXRzOwogICAgICAgICAgICByZXN1bHQgPSAiIiArIGRpZ2l0cyArIHJlc3VsdDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZ2V0SGlnaEJpdHMgPSBmdW5jdGlvbiBnZXRIaWdoQml0cygpIHsKICAgICAgICByZXR1cm4gdGhpcy5oaWdoOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmdldEhpZ2hCaXRzVW5zaWduZWQgPSBmdW5jdGlvbiBnZXRIaWdoQml0c1Vuc2lnbmVkKCkgewogICAgICAgIHJldHVybiB0aGlzLmhpZ2ggPj4+IDA7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZ2V0TG93Qml0cyA9IGZ1bmN0aW9uIGdldExvd0JpdHMoKSB7CiAgICAgICAgcmV0dXJuIHRoaXMubG93OwogICAgICB9OwogICAgICBMb25nUHJvd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lKHN1YnRyYWhlbmQpOwogICAgICAgIHJldHVybiB0aGlzLmFkZChzdWJ0cmFoZW5kLm5lZygpKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zdWIgPSBMb25nUHJvdG90eXBlLnN1YnRyYWN0OwogICAgICBMb25nUHJvdG90eXBlLm11bHRpcGx5ID0gZnVuY3Rpb24gbXVsdGlwbHkobXVsdGlwbGllcikgewogICAgICAgIGlmICh0aGlzLmlzWmVybygpKQogICAgICAgICAgcmV0dXJuIFpFUk87CiAgICAgICAgaWYgKCFpc0xvbmcobXVsdGlwbGllcikpCiAgICAgICAgICBtdWx0aXBsaWVyID0gZnJvbVZhbHVlKG11bHRpcGxpZXIpOwogICAgICAgIGlmICh3YXNtKSB7CiAgICAgICAgICB2YXIgbG93ID0gd2FzbS5tdWwodGhpcy5sb3csIHRoaXMuaGlnaCwgbXVsdGlwbGllci5sb3csIG11bHRpcGxpZXIuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAobXVsdGlwbGllci5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiBaRVJPOwogICAgICAgIGlmICh0aGlzLmVxKE1JTl9WQUxVRSkpCiAgICAgICAgICByZXR1cm4gbXVsdGlwbGllci5pc09kZCgpID8gTUlOX1ZBTFVFIDogWkVSTzsKICAgICAgICBpZiAobXVsdGlwbGllci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgcmV0dXJuIHRoaXMuaXNPZGQoKSA/IE1JTl9WQUxVRSA6IFpFUk87CiAgICAgICAgaWYgKHRoaXMuaXNOZWdhdGl2ZSgpKSB7CiAgICAgICAgICBpZiAobXVsdGlwbGllci5pc05lZ2F0aXZlKCkpCiAgICAgICAgICAgIHJldHVybiB0aGlzLm5lZygpLm11bChtdWx0aXBsaWVyLm5lZygpKTsKICAgICAgICAgIGVsc2UKICAg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AgICB9CiAgICAgICAgICB2YXIgbG93ID0gKHRoaXMudW5zaWduZWQgPyB3YXNtLmRpdl91IDogd2FzbS5kaXZfcykodGhpcy5sb3csIHRoaXMuaGlnaCwgZGl2aXNvci5sb3csIGRpdmlzb3IuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkID8gVVpFUk8gOiBaRVJPOwogICAgICAgIHZhciBhcHByb3gsIHJlbSwgcmVzOwogICAgICAgIGlmICghdGhpcy51bnNpZ25lZCkgewogICAgICAgICAgaWYgKHRoaXMuZXEoTUlOX1ZBTFVFKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5lcShPTkUpIHx8IGRpdmlzb3IuZXEoTkVHX09ORSkpCiAgICAgICAgICAgICAgcmV0dXJuIE1JTl9WQUxVRTsKICAgICAgICAgICAgZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICAgIHJldHVybiBPTkU7CiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgIHZhciBoYWxmVGhpcyA9IHRoaXMuc2hyKDEpOwogICAgICAgICAgICAgIGFwcHJveCA9IGhhbGZUaGlzLmRpdihkaXZpc29yKS5zaGwoMSk7CiAgICAgICAgICAgICAgaWYgKGFwcHJveC5lcShaRVJPKSkgewogICAgICAgICAgICAgICAgcmV0dXJuIGRpdmlzb3IuaXNOZWdhdGl2ZSgpID8gT05FIDogTkVHX09ORTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmVtID0gdGhpcy5zdWIoZGl2aXNvci5tdWwoYXBwcm94KSk7CiAgICAgICAgICAgICAgICByZXMgPSBhcHByb3guYWRkKHJlbS5kaXYoZGl2aXNvcikpOwogICAgICAgICAgICAgICAgcmV0dXJuIHJlczsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICByZXR1cm4gdGhpcy51bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICAgIGlmICh0aGlzLmlzTmVnYXRpdmUoKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5pc05lZ2F0aXZlKCkpCiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVnKCkuZGl2KGRpdmlzb3IubmVnKCkpOwogICAgICAgICAgICByZXR1cm4gdGhpcy5uZWcoKS5kaXYoZGl2aXNvcikubmVnKCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGRpdmlzb3IuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgICByZXR1cm4gdGhpcy5kaXYoZGl2aXNvci5uZWcoKSkubmVnKCk7CiAgICAgICAgICByZXMgPSBaRVJPOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoIWRpdmlzb3IudW5zaWduZWQpCiAgICAgICAgICAgIGRpdmlzb3IgPSBkaXZpc29yLnRvVW5zaWduZWQoKTsKICAgICAgICAgIGlmIChkaXZpc29yLmd0KHRoaXMpKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAoZGl2aXNvci5ndCh0aGlzLnNocnUoMSkpKQogICAgICAgICAgICByZXR1cm4gVU9ORTsKICAgICAgICAgIHJlcyA9IFVaRVJPOwogICAgICAgIH0KICAgICAgICByZW0gPSB0aGlzOwogICAgICAgIHdoaWxlIChyZW0uZ3RlKGRpdmlzb3IpKSB7CiAgICAgICAgICBhcHByb3ggPSBNYXRoLm1heCgxLCBNYXRoLmZsb29yKHJlbS50b051bWJlcigpIC8gZGl2aXNvci50b051bWJlcigpKSk7CiAgICAgICAgICB2YXIgbG9nMiA9IE1hdGguY2VpbChNYXRoLmxvZyhhcHByb3gpIC8gTWF0aC5MTjIpLCBkZWx0YSA9IGxvZzIgPD0gNDggPyAxIDogcG93X2RibCgyLCBsb2cyIC0gNDgpLCBhcHByb3hSZXMgPSBmcm9tTnVtYmVyKGFwcHJveCksIGFwcHJveFJlbSA9IGFwcHJveFJlcy5tdWwoZGl2aXNvcik7CiAgICAgICAgICB3aGlsZSAoYXBwcm94UmVtLmlzTmVnYXRpdmUoKSB8fCBhcHByb3hSZW0uZ3QocmVtKSkgewogICAgICAgICAgICBhcHByb3ggLT0gZGVsdGE7CiAgICAgICAgICAgIGFwcHJveFJlcyA9IGZyb21OdW1iZXIoYXBwcm94LCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICAgICAgYXBwcm94UmVtID0gYXBwcm94UmVzLm11bChkaXZpc29yKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChhcHByb3hSZXMuaXNaZXJvKCkpCiAgICAgICAgICAgIGFwcHJveFJlcyA9IE9ORTsKICAgICAgICAgIHJlcyA9IHJlcy5hZGQoYXBwcm94UmVzKTsKICAgICAgICAgIHJlbSA9IHJlbS5zdWIoYXBwcm94UmVtKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlczsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5kaXYgPSBMb25nUHJvdG90eXBlLmRpdmlkZTsKICAgICAgTG9uZ1Byb3RvdHlwZS5tb2R1bG8gPSBmdW5jdGlvbiBtb2R1bG8oZGl2aXNvcikgewogICAgICAgIGlmICghaXNMb25nKGRpdmlzb3IpKQogICAgICAgICAgZGl2aXNvciA9IGZyb21WYWx1ZShkaXZpc29yKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgdmFyIGxvdyA9ICh0aGlzLnVuc2lnbmVkID8gd2FzbS5yZW1fdSA6IHdhc20ucmVtX3MpKHRoaXMubG93LCB0aGlzLmhpZ2gsIGRpdmlzb3IubG93LCBkaXZpc29yLmhpZ2gpOwogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGxvdywgd2FzbS5nZXRfaGlnaCgpLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXMuc3ViKHRoaXMuZGl2KGRpdmlzb3IpLm11bChkaXZpc29yKSk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUubW9kID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUucmVtID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUubm90ID0gZnVuY3Rpb24gbm90KCkgewogICAgICAgIHJldHVybiBmcm9tQml0cyh+dGhpcy5sb3csIH50aGlzLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmFuZCA9IGZ1bmN0aW9uIGFuZChvdGhlcikgewogICAgICAgIGlmICghaXNMb25nKG90aGVyKSkKICAgICAgICAgIG90aGVyID0gZnJvbVZhbHVlKG90aGVyKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3cgJiBvdGhlci5sb3csIHRoaXMuaGlnaCAmIG90aGVyLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm9yID0gZnVuY3Rpb24gb3Iob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1ZShvdGhlcik7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93IHwgb3RoZXIubG93LCB0aGlzLmhpZ2ggfCBvdGhlci5oaWdoLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS54b3IgPSBmdW5jdGlvbiB4b3Iob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1ZShvdGhlcik7CiAgICAgICAgcmV0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51bUJpdHMsIHRoaXMuaGlnaCA+PiBudW1CaXRzLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICBlbHNlCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5oaWdoID4+IG51bUJpdHMgLSAzMiwgdGhpcy5oaWdoID49IDAgPyAwIDogLTEsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnNociA9IExvbmdQcm90b3R5cGUuc2hpZnRSaWdodDsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0VW5zaWduZWQgPSBmdW5jdGlvbiBzaGlmdFJpZ2h0VW5zaWduZWQobnVtQml0cykgewogICAgICAgIGlmIChpc0xvbmcobnVtQml0cykpCiAgICAgICAgICBudW1CaXRzID0gbnVtQml0cy50b0ludCgpOwogICAgICAgIG51bUJpdHMgJj0gNjM7CiAgICAgICAgaWYgKG51bUJpdHMgPT09IDApCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBlbHNlIHsKICAgICAgICAgIHZhciBoaWdoID0gdGhpcy5oaWdoOwogICAgICAgICAgaWYgKG51bUJpdHMgPCAzMikgewogICAgICAgICAgICB2YXIgbG93ID0gdGhpcy5sb3c7CiAgICAgICAgICAgIHJldHVybiBmcm9tQml0cyhsb3cgPj4+IG51bUJpdHMgfCBoaWdoIDw8IDMyIC0gbnVtQml0cywgaGlnaCA+Pj4gbnVtQml0cywgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgICB9IGVsc2UgaWYgKG51bUJpdHMgPT09IDMyKQogICAgICAgICAgICByZXR1cm4gZnJvbUJpdHMoaGlnaCwgMCwgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHJldHVybiBmcm9tQml0cyhoaWdoID4+PiBudW1CaXRzIC0gMzIsIDAsIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaHJ1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2YgSW50MzJBcnJheSAhPT0gInVuZGVmaW5lZCI7CiAgICAgIGZ1bmN0aW9uIF9oYXMob2JqLCBrZXkpIHsKICAgICAgICByZXR1cm4gT2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eS5jYWxsKG9iaiwga2V5KTsKICAgICAgfQogICAgICBleHBvcnRzLmFzc2lnbiA9IGZ1bmN0aW9uKG9iaikgewogICAgICAgIHZhciBzb3VyY2VzID0gQXJyYXkucHJvdG90eXBlLnNsaWNlLmNhbGwoYXJndW1lbnRzLCAxKTsKICAgICAgICB3aGlsZSAoc291cmNlcy5sZW5ndGgpIHsKICAgICAgICAgIHZhciBzb3VyY2UgPSBzb3VyY2VzLnNoaWZ0KCk7CiAgICAgICAgICBpZiAoIXNvdXJjZSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0eXBlb2Ygc291cmNlICE9PSAib2JqZWN0IikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKHNvdXJjZSArICJtdXN0IGJlIG5vbi1vYmplY3QiKTsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAodmFyIHAgaW4gc291cmNlKSB7CiAgICAgICAgICAgIGlmIChfaGFzKHNvdXJjZSwgcCkpIHsKICAgICAgICAgICAgICBvYmpbcF0gPSBzb3VyY2VbcF07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIG9iajsKICAgICAgfTsKICAgICAgZXhwb3J0cy5zaHJpbmtCdWYgPSBmdW5jdGlvbihidWYsIHNpemUpIHsKICAgICAgICBpZiAoYnVmLmxlbmd0aCA9PT0gc2l6ZSkgewogICAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgICB9CiAgICAgICAgaWYgKGJ1Zi5zdWJhcnJheSkgewogICAgICAgICAgcmV0dXJuIGJ1Zi5zdWJhcnJheSgwLCBzaXplKTsKICAgICAgICB9CiAgICAgICAgYnVmLmxlbmd0aCA9IHNpemU7CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgdmFyIGZuVHlwZWQgPSB7CiAgICAgICAgYXJyYXlTZXQ6IGZ1bmN0aW9uKGRlc3QsIHNyYywgc3JjX29mZnMsIGxlbiwgZGVzdF9vZmZzKSB7CiAgICAgICAgICBpZiAoc3JjLnN1YmFycmF5ICYmIGRlc3Quc3ViYXJyYXkpIHsKICAgICAgICAgICAgZGVzdC5zZXQoc3JjLnN1YmFycmF5KHNyY19vZmZzLCBzcmNfb2ZmcyArIGxlbiksIGRlc3Rfb2Zmcyk7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICAgICAgZGVzdFtkZXN0X29mZnMgKyBpXSA9IHNyY1tzcmNfb2ZmcyArIGldOwogICAgICAgICAgfQogICAgICAgIH0sCiAgICAgICAgZmxhdHRlbkNodW5rczogZnVuY3Rpb24oY2h1bmtzKSB7CiAgICAgICAgICB2YXIgaSwgbCwgbGVuLCBwb3MsIGNodW5rLCByZXN1bHQ7CiAgICAgICAgICBsZW4gPSAwOwogICAgICAgICAgZm9yIChpID0gMCwgbCA9IGNodW5rcy5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgbGVuICs9IGNodW5rc1tpXS5sZW5ndGg7CiAgICAgICAgICB9CiAgICAgICAgICByZXN1bHQgPSBuZXcgVWludDhBcnJheShsZW4pOwogICAgICAgICAgcG9zID0gMDsKICAgICAgICAgIGZvciAoaSA9IDAsIGwgPSBjaHVua3MubGVuZ3RoOyBpIDwgbDsgaSsrKSB7CiAgICAgICAgICAgIGNodW5rID0gY2h1bmtzW2ldOwogICAgICAgICAgICByZXN1bHQuc2V0KGNodW5rLCBwb3MpOwogICAgICAgICAgICBwb3MgKz0gY2h1bmsubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgICB9CiAgICAgIH07CiAgICAgIHZhciBmblVudHlwZWQgPSB7CiAgICAgICAgYXJyYXlTZXQ6IGZ1bmN0aW9uKGRlc3QsIHNyYywgc3JjX29mZnMsIGxlbiwgZGVzdF9vZmZzKSB7CiAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgICAgIGRlc3RbZGVzdF9vZmZzICsgaV0gPSBzcmNbc3JjX29mZnMgKyBpXTsKICAgICAgICAgIH0KICAgICAgICB9LAogICAgICAgIGZsYXR0ZW5DaHVua3M6IGZ1bmN0aW9uKGNodW5rcykgewogICAgICAgICAgcmV0dXJuIFtdLmNvbmNhdC5hcHBseShbXSwgY2h1bmtzKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIGV4cG9ydHMuc2V0VHlwZWQgPSBmdW5jdGlvbihvbikgewogICAgICAgIGlmIChvbikgewogICAgICAgICAgZXhwb3J0cy5CdWY4ID0gVWludDhBcnJheTsKICAgICAgICAgIGV4cG9ydHMuQnVmMTYgPSBVaW50MTZBcnJheTsKICAgICAgICAgIGV4cG9ydHMuQnVmMzIgPSBJbnQzMkFycmF5OwogICAgICAgICAgZXhwb3J0cy5hc3NpZ24oZXhwb3J0cywgZm5UeXBlZCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGV4cG9ydHMuQnVmOCA9IEFycmF5OwogICAgICAgICAgZXhwb3J0cy5CdWYxNiA9IEFycmF5OwogICAgICAgICAgZXhwb3J0cy5CdWYzMiA9IEFycmF5OwogICAgICAgICAgZXhwb3J0cy5hc3NpZ24oZXhwb3J0cywgZm5VbnR5cGVkKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIGV4cG9ydHMuc2V0VHlwZWQoVFlQRURfT0spOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvdHJlZXMuanMKICB2YXIgcmVxdWlyZV90cmVlcyA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi90cmVlcy5qcyIoZXhwb3J0cykgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24yKCk7CiAgICAgIHZhciBaX0ZJWEVEID0gNDsKICAgICAgdmFyIFpfQklOQVJZID0gMDsKICAgICAgdmFyIFpfVEVYVCA9IDE7CiAgICAgIHZhciBaX1VOS05PV04gPSAyOwogICAgICBmdW5jdGlvbiB6ZXJvKGJ1ZikgewogICAgICAgIHZhciBsZW4gPSBidWYubGVuZ3RoOwogICAgICAgIHdoaWxlICgtLWxlbiA+PSAwKSB7CiAgICAgICAgICBidWZbbGVuXSA9IDA7CiAgICAgICAgfQogICAgICB9CiAgICAgIHZhciBTVE9SRURfQkxPQ0sgPSAwOwogICAgICB2YXIgU1RBVElDX1RSRUVTID0gMTsKICAgICAgdmFyIERZTl9UUkVFUyA9IDI7CiAgICAgIHZhciBNSU5fTUFUQ0ggPSAzOwogICAgICB2YXIgTUFYX01BVENIID0gMjU4OwogICAgICB2YXIgTEVOR1RIX0NPREVTID0gMjk7CiAgICAgIHZhciBMSVRFUkFMUyA9IDI1NjsKICAgICAgdmFyIExfQ09ERVMgPSBMSVRFUkFMUyArIDEgKyBMRU5HVEhfQ09ERVM7CiAgICAgIHZhciBEX0NPREVTID0gMzA7CiAgICAgIHZhciBCTF9DT0RFUyA9IDE5OwogICAgICB2YXIgSEVBUF9TSVpFID0gMiAqIExfQ09ERVMgKyAxOwogICAgICB2YXIgTUFYX0JJVFMgPSAxNTsKICAgICAgdmFyIEJ1Zl9zaXplID0gMTY7CiAgICAgIHZhciBNQVhfQkxfQklUUyA9IDc7CiAgICAgIHZhciBFTkR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7CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHNdID0gMDsKICAgICAgICB9CiAgICAgICAgdHJlZVtzLmhlYXBbcy5oZWFwX21heF0gKiAyICsgMV0gPSAwOwogICAgICAgIGZvciAoaCA9IHMuaGVhcF9tYXggKyAxOyBoIDwgSEVBUF9TSVpFOyBoKyspIHsKICAgICAgICAgIG4gPSBzLmhlYXBbaF07CiAgICAgICAgICBiaXRzID0gdHJlZVt0cmVlW24gKiAyICsgMV0gKiAyICsgMV0gKyAxOwogICAgICAgICAgaWYgKGJpdHMgPiBtYXhfbGVuZ3RoKSB7CiAgICAgICAgICAgIGJpdHMgPSBtYXhfbGVuZ3RoOwogICAgICAgICAgICBvdmVyZmxvdysrOwogICAgICAgICAgfQogICAgICAgICAgdHJlZVtuICogMiArIDFdID0gYml0czsKICAgICAgICAgIGlmIChuID4gbWF4X2NvZGUpIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHNdKys7CiAgICAgICAgICB4Yml0cyA9IDA7CiAgICAgICAgICBpZiAobiA+PSBiYXNlKSB7CiAgICAgICAgICAgIHhiaXRzID0gZXh0cmFbbiAtIGJhc2VdOwogICAgICAgICAgfQogICAgICAgICAgZiA9IHRyZWVbbiAqIDJdOwogICAgICAgICAgcy5vcHRfbGVuICs9IGYgKiAoYml0cyArIHhiaXRzKTsKICAgICAgICAgIGlmIChoYXNfc3RyZWUpIHsKICAgICAgICAgICAgcy5zdGF0aWNfbGVuICs9IGYgKiAoc3RyZWVbbiAqIDIgKyAxXSArIHhiaXRzKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKG92ZXJmbG93ID09PSAwKSB7CiAgICAgICAgICByZXR1cm47CiAgICAgICAgfQogICAgICAgIGRvIHsKICAgICAgICAgIGJpdHMgPSBtYXhfbGVuZ3RoIC0gMTsKICAgICAgICAgIHdoaWxlIChzLmJsX2NvdW50W2JpdHNdID09PSAwKSB7CiAgICAgICAgICAgIGJpdHMtLTsKICAgICAgICAgIH0KICAgICAgICAgIHMuYmxfY291bnRbYml0c10tLTsKICAgICAgICAgIHMuYmxfY291bnRbYml0cyArIDFdICs9IDI7CiAgICAgICAgICBzLmJsX2NvdW50W21heF9sZW5ndGhdLS07CiAgICAgICAgICBvdmVyZmxvdyAtPSAyOwogICAgICAgIH0gd2hpbGUgKG92ZXJmbG93ID4gMCk7CiAgICAgICAgZm9yIChiaXRzID0gbWF4X2xlbmd0aDsgYml0cyAhPT0gMDsgYml0cy0tKSB7CiAgICAgICAgICBuID0gcy5ibF9jb3VudFtiaXRzXTsKICAgICAgICAgIHdoaWxlIChuICE9PSAwKSB7CiAgICAgICAgICAgIG0gPSBzLmhlYXBbLS1oXTsKICAgICAgICAgICAgaWYgKG0gPiBtYXhfY29kZSkgewogICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh0cmVlW20gKiAyICsgMV0gIT09IGJpdHMpIHsKICAgICAgICAgICAgICBzLm9wdF9sZW4gKz0gKGJpdHMgLSB0cmVlW20gKiAyICsgMV0pICogdHJlZVttICogMl07CiAgICAgICAgICAgICAgdHJlZVttICogMiArIDFdID0gYml0czsKICAgICAgICAgICAgfQogICAgICAgICAgICBuLS07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGdlbl9jb2Rlcyh0cmVlLCBtYXhfY29kZSwgYmxfY291bnQpIHsKICAgICAgICB2YXIgbmV4dF9jb2RlID0gbmV3IEFycmF5KE1BWF9CSVRTICsgMSk7CiAgICAgICAgdmFyIGNvZGUgPSAwOwogICAgICAgIHZhciBiaXRzOwogICAgICAgIHZhciBuOwogICAgICAgIGZvciAoYml0cyA9IDE7IGJpdHMgPD0gTUFYX0JJVFM7IGJpdHMrKykgewogICAgICAgICAgbmV4dF9jb2RlW2JpdHNdID0gY29kZSA9IGNvZGUgKyBibF9jb3VudFtiaXRzIC0gMV0gPDwgMTsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8PSBtYXhfY29kZTsgbisrKSB7CiAgICAgICAgICB2YXIgbGVuID0gdHJlZVtuICogMiArIDFdOwogICAgICAgICAgaWYgKGxlbiA9PT0gMCkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIHRyZWVbbiAqIDJdID0gYmlfcmV2ZXJzZShuZXh0X2NvZGVbbGVuXSsrLCBsZW4pOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiB0cl9zdGF0aWNfaW5pdCgpIHsKICAgICAgICB2YXIgbjsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgbGVuZ3RoOwogICAgICAgIHZhciBjb2RlOwogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBibF9jb3VudCA9IG5ldyBBcnJheShNQVhfQklUUyArIDEpOwogICAgICAgIGxlbmd0aCA9IDA7CiAgICAgICAgZm9yIChjb2RlID0gMDsgY29kZSA8IExFTkdUSF9DT0RFUyAtIDE7IGNvZGUrKykgewogICAgICAgICAgYmFzZV9sZW5ndGhbY29kZV0gPSBsZW5ndGg7CiAgICAgICAgICBmb3IgKG4gPSAwOyBuIDwgMSA8PCBleHRyYV9sYml0c1tjb2RlXTsgbisrKSB7CiAgICAgICAgICAgIF9sZW5ndGhfY29kZVtsZW5ndGgrK10gPSBjb2RlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBfbGVuZ3RoX2NvZGVbbGVuZ3RoIC0gMV0gPSBjb2RlOwogICAgICAgIGRpc3QgPSAwOwogICAgICAgIGZvciAoY29kZSA9IDA7IGNvZGUgPCAxNjsgY29kZSsrKSB7CiAgICAgICAgICBiYXNlX2Rpc3RbY29kZV0gPSBkaXN0OwogICAgICAgICAgZm9yIChuID0gMDsgbiA8IDEgPDwgZXh0cmFfZGJpdHNbY29kZV07IG4rKykgewogICAgICAgICAgICBfZGlzdF9jb2RlW2Rpc3QrK10gPSBjb2RlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBkaXN0ID4+PSA3OwogICAgICAgIGZvciAoOyBjb2RlIDwgRF9DT0RFUzsgY29kZSsrKSB7CiAgICAgICAgICBiYXNlX2Rpc3RbY29kZV0gPSBkaXN0IDw8IDc7CiAgICAgICAgICBmb3IgKG4gPSAwOyBuIDwgMSA8PCBleHRyYV9kYml0c1tjb2RlXSAtIDc7IG4rKykgewogICAgICAgICAgICBfZGlzdF9jb2RlWzI1NiArIGRpc3QrK10gPSBjb2RlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmb3IgKGJpdHMgPSAwOyBiaXRzIDw9IE1BWF9CSVRTOyBiaXRzKyspIHsKICAgICAgICAgIGJsX2NvdW50W2JpdHNdID0gMDsKICAgICAgICB9CiAgICAgICAgbiA9IDA7CiAgICAgICAgd2hpbGUgKG4gPD0gMTQzKSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDg7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs4XSsrOwogICAgICAgIH0KICAgICAgICB3aGlsZSAobiA8PSAyNTUpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gOTsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzldKys7CiAgICAgICAgfQogICAgICAgIHdoaWxlIChuIDw9IDI3OSkgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA3OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbN10rKzsKICAgICAgICB9CiAgICAgICAgd2hpbGUgKG4gPD0gMjg3KSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDg7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs4XSsrOwogICAgICAgIH0KICAgICAgICBnZW5fY29kZXMoc3RhdGljX2x0cmVlLCBMX0NPREVTICsgMSwgYmxfY291bnQpOwogICAgICAgIGZvciAobiA9IDA7IG4gPCBEX0NPREVTOyBuKyspIHsKICAgICAgICAgIHN0YXRpY19kdHJlZVtuICogMiArIDFdID0gNTsKICAgICAgICAgIHN0YXRpY19kdHJlZVtuICogMl0gPSBiaV9yZXZlcnNlKG4sIDUpOwogICAgICAgIH0KICAgICAgICBzdGF0aWNfbF9kZXNjID0gbmV3IFN0YXRpY1RyZWVEZXNjKHN0YXRpY19sdHJlZSwgZXh0cmFfbGJpdHMsIExJVEVSQUxTICsgMSwgTF9DT0RFUywgTUFYX0JJVFMpOwogICAgICAgIHN0YXRpY19kX2Rlc2MgPSBuZXcgU3RhdGljVHJlZURlc2Moc3RhdGljX2R0cmVlLCBleHRyYV9kYml0cywgMCwgRF9DT0RFUywgTUFYX0JJVFMpOwogICAgICAgIHN0YXRpY19ibF9kZXNjID0gbmV3IFN0YXRpY1RyZWVEZXNjKG5ldyBBcnJheSgwKSwgZXh0cmFfYmxiaXRzLCAwLCBCTF9DT0RFUywgTUFYX0JMX0JJVFMpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluaXRfYmxvY2socykgewogICAgICAgIHZhciBuOwogICAgICAgIGZvciAobiA9IDA7IG4gPCBMX0NPREVTOyBuKyspIHsKICAgICAgICAgIHMuZHluX2x0cmVlW24gKiAyXSA9IDA7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPCBEX0NPREVTOyBuKyspIHsKICAgICAgICAgIHMuZHluX2R0cmVlW24gKiAyXSA9IDA7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPCBCTF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzLmJsX3RyZWVbbiAqIDJdID0gMDsKICAgICAgICB9CiAgICAgICAgcy5keW5fbHRyZWVbRU5EX0JMT0NLICogMl0gPSAxOwogICAgICAgIHMub3B0X2xlbiA9IHMuc3RhdGljX2xlbiA9IDA7CiAgICAgICAgcy5sYXN0X2xpdCA9IHMubWF0Y2hlcyA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYmlfd2luZHVwKHMpIHsKICAgICAgICBpZiAocy5iaV92YWxpZCA+IDgpIHsKICAgICAgICAgIHB1dF9zaG9ydChzLCBzLmJpX2J1Zik7CiAgICAgICAgfSBlbHNlIGlmIChzLmJpX3ZhbGlkID4gMCkgewogICAgICAgICAgcy5wZW5kaW5nX2J1ZltzLnBlbmRpbmcrK10gPSBzLmJpX2J1ZjsKICAgICAgICB9CiAgICAgICAgcy5iaV9idWYgPSAwOwogICAgICAgIHMuYmlfdmFsaWQgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGNvcHlfYmxvY2socywgYnVmLCBsZW4sIGhlYWRlcikgewogICAgICAgIGJpX3dpbmR1cChzKTsKICAgICAgICBpZiAoaGVhZGVyKSB7CiAgICAgICAgICBwdXRfc2hvcnQocywgbGVuKTsKICAgICAgICAgIHB1dF9zaG9ydChzLCB+bGVuKTsKICAgICAgICB9CiAgICAgICAgdXRpbHMuYXJyYXlTZXQocy5wZW5kaW5nX2J1Ziwgcy53aW5kb3csIGJ1ZiwgbGVuLCBzLnBlbmRpbmcpOwogICAgICAgIHMucGVuZGluZyArPSBsZW47CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc21hbGxlcih0cmVlLCBuLCBtLCBkZXB0aCkgewogICAgICAgIHZhciBfbjIgPSBuICogMjsKICAgICAgICB2YXIgX20yID0gbSAqIDI7CiAgICAgICAgcmV0dXJuIHRyZWVbX24yXSA8IHRyZWVbX20yXSB8fCB0cmVlW19uMl0gPT09IHRyZWVbX20yXSAmJiBkZXB0aFtuXSA8PSBkZXB0aFttXTsKICAgICAgfQogICAgICBmdW5jdGlvbiBwcWRvd25oZWFwKHMsIHRyZWUsIGspIHsKICAgICAgICB2YXIgdiA9IHMuaGVhcFtrXTsKICAgICAgICB2YXIgaiA9IGsgPDwgMTsKICAgICAgICB3aGlsZSAoaiA8PSBzLmhlYXBfbGVuKSB7CiAgICAgICAgICBpZiAoaiA8IHMuaGVhcF9sZW4gJiYgc21hbGxlcih0cmVlLCBzLmhlYXBbaiArIDFdLCBzLmhlYXBbal0sIHMuZGVwdGgpKSB7CiAgICAgICAgICAgIGorKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzbWFsbGVyKHRyZWUsIHYsIHMuaGVhcFtqXSwgcy5kZXB0aCkpIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBzLmhlYXBba10gPSBzLmhlYXBbal07CiAgICAgICAgICBrID0gajsKICAgICAgICAgIGogPDw9IDE7CiAgICAgICAgfQogICAgICAgIHMuaGVhcFtrXSA9IHY7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gY29tcHJlc3NfYmxvY2socywgbHRyZWUsIGR0cmVlKSB7CiAgICAgICAgdmFyIGRpc3Q7CiAgICAgICAgdmFyIGxjOwogICAgICAgIHZhciBseCA9IDA7CiAgICAgICAgdmFyIGNvZGU7CiAgICAgICAgdmFyIGV4dHJhOwogICAgICAgIGlmIChzLmxhc3RfbGl0ICE9PSAwKSB7CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGRpc3QgPSBzLnBlbmRpbmdfYnVmW3MuZF9idWYgKyBseCAqIDJdIDw8IDggfCBzLnBlbmRpbmdfYnVmW3MuZF9idWYgKyBseCAqIDIgKyAxXTsKICAgICAgICAgICAgbGMgPSBzLnBlbmRpbmdfYnVmW3MubF9idWYgKyBseF07CiAgICAgICAgICAgIGx4Kys7CiAgICAgICAgICAgIGlmIChkaXN0ID09PSAwKSB7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGxjLCBsdHJlZSk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgY29kZSA9IF9sZW5ndGhfY29kZVtsY107CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGNvZGUgKyBMSVRFUkFMUyArIDEsIGx0cmVlKTsKICAgICAgICAgICAgICBleHRyYSA9IGV4dHJhX2xiaXRzW2NvZGVdOwogICAgICAgICAgICAgIGlmIChleHRyYSAhPT0gMCkgewogICAgICAgICAgICAgICAgbGMgLT0gYmFzZV9sZW5ndGhbY29kZV07CiAgICAgICAgICAgICAgICBzZW5kX2JpdHMocywgbGMsIGV4dHJhKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgZGlzdC0tOwogICAgICAgICAgICAgIGNvZGUgPSBkX2NvZGUoZGlzdCk7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGNvZGUsIGR0cmVlKTsKICAgICAgICAgICAgICBleHRyYSA9IGV4dHJhX2RiaXRzW2NvZGVdOwogICAgICAgICAgICAgIGlmIChleHRyYSAhPT0gMCkgewogICAgICAgICAgICAgICAgZGlzdCAtPSBiYXNlX2Rpc3RbY29kZV07CiAgICAgICAgICAgICAgICBzZW5kX2JpdHMocywgZGlzdCwgZXh0cmEpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfSB3aGlsZSAobHggPCBzLmxhc3RfbGl0KTsKICAgICAgICB9CiAgICAgICAgc2VuZF9jb2RlKHMsIEVORF9CTE9DSywgbHRyZWUpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJ1aWxkX3RyZWUocywgZGVzYykgewogICAgICAgIHZhciB0cmVlID0gZGVzYy5keW5fdHJlZTsKICAgICAgICB2YXIgc3RyZWUgPSBkZXNjLnN0YXRfZGVzYy5zdGF0aWNfdHJlZTsKICAgICAgICB2YXIgaGFzX3N0cmVlID0gZGVzYy5zdGF0X2Rlc2MuaGFzX3N0cmVlOwogICAgICAgIHZhciBlbGVtcyA9IGRlc2Muc3RhdF9kZXNjLmVsZW1zOwogICAgICAgIHZhciBuLCBtOwogICAgICAgIHZhciBtYXhfY29kZSA9IC0xOwogICAgICAgIHZhciBub2RlOwogICAgICAgIHMuaGVhcF9sZW4gPSAwOwogICAgICAgIHMuaGVhcF9tYXggPSBIRUFQX1NJWkU7CiAgICAgICAgZm9yIChuID0gMDsgbiA8IGVsZW1zOyBuKyspIHsKICAgICAgICAgIGlmICh0cmVlW24gKiAyXSAhPT0gMCkgewogICAgICAgICAgICBzLmhlYXBbKytzLmhlYXBfbGVuXSA9IG1heF9jb2RlID0gbjsKICAgICAgICAgICAgcy5kZXB0aFtuXSA9IDA7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0cmVlW24gKiAyICsgMV0gPSAwOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB3aGlsZSAocy5oZWFwX2xlbiA8IDIpIHsKICAgICAgICAgIG5vZGUgPSBzLmhlYXBbKytzLmhlYXBfbGVuXSA9IG1heF9jb2RlIDwgMiA/ICsrbWF4X2NvZGUgOiAwOwogICAgICAgICAgdHJlZVtub2RlICogMl0gPSAxOwogICAgICAgICAgcy5kZXB0aFtub2RlXSA9IDA7CiAgICAgICAgICBzLm9wdF9sZW4tLTsKICAgICAgICAgIGlmIChoYXNfc3RyZWUpIHsKICAgICAgICAgICAgcy5zdGF0aWNfbGVuIC09IHN0cmVlW25vZGUgKiAyICsgMV07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRlc2MubWF4X2NvZGUgPSBtYXhfY29kZTsKICAgICAgICBmb3IgKG4gPSBzLmhlYXBfbGVuID4+IDE7IG4gPj0gMTsgbi0tKSB7CiAgICAgICAgICBwcWRvd25oZWFwKHMsIHRyZWUsIG4pOwogICAgICAgIH0KICAgICAgICBub2RlID0gZWxlbXM7CiAgICAgICAgZG8gewogICAgICAgICAgbiA9IHMuaGVhcFsxXTsKICAgICAgICAgIHMuaGVhcFsxXSA9IHMuaGVhcFtzLmhlYXBfbGVuLS1dOwogICAgICAgICAgcHFkb3duaGVhcChzLCB0cmVlLCAxKTsKICAgICAgICAgIG0gPSBzLmhlYXBbMV07CiAgICAgICAgICBzLmhlYXBbLS1zLmhlYXBfbWF4XSA9IG47CiAgICAgICAgICBzLmhlYXBbLS1zLmhlYXBfbWF4XSA9IG07CiAgICAgICAgICB0cmVlW25vZGUgKiAyXSA9IHRyZWVbbiAqIDJdICsgdHJlZVttICogMl07CiAgICAgICAgICBzLmRlcHRoW25vZGVdID0gKHMuZGVwdGhbbl0gPj0gcy5kZXB0aFttXSA/IHMuZGVwdGhbbl0gOiBzLmRlcHRoW21dKSArIDE7CiAgICAgICAgICB0cmVlW24gKiAyICsgMV0gPSB0cmVlW20gKiAyICsgMV0gPSBub2RlOwogICAgICAgICAgcy5oZWFwWzFdID0gbm9kZSsrOwogICAgICAgICAgcHFkb3duaGVhcChzLCB0cmVlLCAxKTsKICAgICAgICB9IHdoaWxlIChzLmhlYXBfbGVuID49IDIpOwogICAgICAgIHMuaGVhcFstLXMuaGVhcF9tYXhdID0gcy5oZWFwWzFdOwogICAgICAgIGdlbl9iaXRsZW4ocywgZGVzYyk7CiAgICAgICAgZ2VuX2NvZGVzKHRyZWUsIG1heF9jb2RlLCBzLmJsX2NvdW50KTsKICAgICAgfQogICAgICBmdW5jdGlvbiBzY2FuX3RyZWUocywgdHJlZSwgbWF4X2NvZGUpIHsKICAgICAgICB2YXIgbjsKICAgICAgICB2YXIgcHJldmxlbiA9IC0xOwogICAgICAgIHZhciBjdXJsZW47CiAgICAgICAgdmFyIG5leHRsZW4gPSB0cmVlWzAgKiAyICsgMV07CiAgICAgICAgdmFyIGNvdW50ID0gMDsKICAgICAgICB2YXIgbWF4X2NvdW50ID0gNzsKICAgICAgICB2YXIgbWluX2NvdW50ID0gNDsKICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICB9CiAgICAgICAgdHJlZVsobWF4X2NvZGUgKyAxKSAqIDIgKyAxXSA9IDY1NTM1OwogICAgICAgIGZvciAobiA9IDA7IG4gPD0gbWF4X2NvZGU7IG4rKykgewogICAgICAgICAgY3VybGVuID0gbmV4dGxlbjsKICAgICAgICAgIG5leHRsZW4gPSB0cmVlWyhuICsgMSkgKiAyICsgMV07CiAgICAgICAgICBpZiAoKytjb3VudCA8IG1heF9jb3VudCAmJiBjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDwgbWluX2NvdW50KSB7CiAgICAgICAgICAgIHMuYmxfdHJlZVtjdXJsZW4gKiAyXSArPSBjb3VudDsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuICE9PSAwKSB7CiAgICAgICAgICAgIGlmIChjdXJsZW4gIT09IHByZXZsZW4pIHsKICAgICAgICAgICAgICBzLmJsX3RyZWVbY3VybGVuICogMl0rKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBzLmJsX3RyZWVbUkVQXzNfNiAqIDJdKys7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDw9IDEwKSB7CiAgICAgICAgICAgIHMuYmxfdHJlZVtSRVBaXzNfMTAgKiAyXSsrOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5ibF90cmVlW1JFUFpfMTFfMTM4ICogMl0rKzsKICAgICAgICAgIH0KICAgICAgICAgIGNvdW50ID0gMDsKICAgICAgICAgIHByZXZsZW4gPSBjdXJsZW47CiAgICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBtYXhfY291bnQgPSA2OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNzsKICAgICAgICAgICAgbWluX2NvdW50ID0gNDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2VuZF90cmVlKHMsIHRyZWUsIG1heF9jb2RlKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIHByZXZsZW4gPSAtMTsKICAgICAgICB2YXIgY3VybGVuOwogICAgICAgIHZhciBuZXh0bGVuID0gdHJlZVswICogMiArIDFdOwogICAgICAgIHZhciBjb3VudCA9IDA7CiAgICAgICAgdmFyIG1heF9jb3VudCA9IDc7CiAgICAgICAgdmFyIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPD0gbWF4X2NvZGU7IG4rKykgewogICAgICAgICAgY3VybGVuID0gbmV4dGxlbjsKICAgICAgICAgIG5leHRsZW4gPSB0cmVlWyhuICsgMSkgKiAyICsgMV07CiAgICAgICAgICBpZiAoKytjb3VudCA8IG1heF9jb3VudCAmJiBjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDwgbWluX2NvdW50KSB7CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY3VybGVuLCBzLmJsX3RyZWUpOwogICAgICAgICAgICB9IHdoaWxlICgtLWNvdW50ICE9PSAwKTsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuICE9PSAwKSB7CiAgICAgICAgICAgIGlmIChjdXJsZW4gIT09IHByZXZsZW4pIHsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY3VybGVuLCBzLmJsX3RyZWUpOwogICAgICAgICAgICAgIGNvdW50LS07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgc2VuZF9jb2RlKHMsIFJFUF8zXzYsIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIHNlbmRfYml0cyhzLCBjb3VudCAtIDMsIDIpOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8PSAxMCkgewogICAgICAgICAgICBzZW5kX2NvZGUocywgUkVQWl8zXzEwLCBzLmJsX3RyZWUpOwogICAgICAgICAgICBzZW5kX2JpdHMocywgY291bnQgLSAzLCAzKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHNlbmRfY29kZShzLCBSRVBaXzExXzEzOCwgcy5ibF90cmVlKTsKICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGNvdW50IC0gMTEsIDcpOwogICAgICAgICAgfQogICAgICAgICAgY291bnQgPSAwOwogICAgICAgICAgcHJldmxlbiA9IGN1cmxlbjsKICAgICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDY7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtYXhfY291bnQgPSA3OwogICAgICAgICAgICBtaW5fY291bnQgPSA0OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBidWlsZF9ibF90cmVlKHMpIHsKICAgICAgICB2YXIgbWF4X2JsaW5kZXg7CiAgICAgICAgc2Nhbl90cmVlKHMsIHMuZHluX2x0cmVlLCBzLmxfZGVzYy5tYXhfY29kZSk7CiAgICAgICAgc2Nhbl90cmVlKHMsIHMuZHluX2R0cmVlLCBzLmRfZGVzYy5tYXhfY29kZSk7CiAgICAgICAgYnVpbGRfdHJlZShzLCBzLmJsX2Rlc2MpOwogICAgICAgIGZvciAobWF4X2JsaW5kZXggPSBCTF9DT0RFUyAtIDE7IG1heF9ibGluZGV4ID49IDM7IG1heF9ibGluZGV4LS0pIHsKICAgICAgICAgIGlmIChzLmJsX3RyZWVbYmxfb3JkZXJbbWF4X2JsaW5kZXhdICogMiArIDFdICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLm9wdF9sZW4gKz0gMyAqIChtYXhfYmxpbmRleCArIDEpICsgNSArIDUgKyA0OwogICAgICAgIHJldHVybiBtYXhfYmxpbmRleDsKICAgICAgfQogICAgICBmdW5jdGlvbiBzZW5kX2FsbF90cmVlcyhzLCBsY29kZXMsIGRjb2RlcywgYmxjb2RlcykgewogICAgICAgIHZhciByYW5rOwogICAgICAgIHNlbmRfYml0cyhzLCBsY29kZXMgLSAyNTcsIDUpOwogICAgICAgIHNlbmRfYml0cyhzLCBkY29kZXMgLSAxLCA1KTsKICAgICAgICBzZW5kX2JpdHMocywgYmxjb2RlcyAtIDQsIDQpOwogICAgICAgIGZvciAocmFuayA9IDA7IHJhbmsgPCBibGNvZGVzOyByYW5rKyspIHsKICAgICAgICAgIHNlbmRfYml0cyhzLCBzLmJsX3RyZWVbYmxfb3JkZXJbcmFua10gKiAyICsgMV0sIDMpOwogICAgICAgIH0KICAgICAgICBzZW5kX3RyZWUocywgcy5keW5fbHRyZWUsIGxjb2RlcyAtIDEpOwogICAgICAgIHNlbmRfdHJlZShzLCBzLmR5bl9kdHJlZSwgZGNvZGVzIC0gMSk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGV0ZWN0X2RhdGFfdHlwZShzKSB7CiAgICAgICAgdmFyIGJsYWNrX21hc2sgPSA0MDkzNjI0NDQ3OwogICAgICAgIHZhciBuOwogICAgICAgIGZvciAobiA9IDA7IG4gPD0gMzE7IG4rKywgYmxhY2tfbWFzayA+Pj49IDEpIHsKICAgICAgICAgIGlmIChibGFja19tYXNrICYgMSAmJiBzLmR5bl9sdHJlZVtuICogMl0gIT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIFpfQklOQVJZOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5keW5fbHRyZWVbOSAqIDJdICE9PSAwIHx8IHMuZHluX2x0cmVlWzEwICogMl0gIT09IDAgfHwgcy5keW5fbHRyZWVbMTMgKiAyXSAhPT0gMCkgewogICAgICAgICAgcmV0dXJuIFpfVEVYVDsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMzI7IG4gPCBMSVRFUkFMUzsgbisrKSB7CiAgICAgICAgICBpZiAocy5keW5fbHRyZWVbbiAqIDJdICE9PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBaX1RFWFQ7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBaX0JJTkFSWTsKICAgICAgfQogICAgICB2YXIgc3RhdGljX2luaXRfZG9uZSA9IGZhbHNlOwogICAgICBmdW5jdGlvbiBfdHJfaW5pdChzKSB7CiAgICAgICAgaWYgKCFzdGF0aWNfaW5pdF9kb25lKSB7CiAgICAgICAgICB0cl9zdGF0aWNfaW5pdCgpOwogICAgICAgICAgc3RhdGljX2luaXRfZG9uZSA9IHRydWU7CiAgICAgICAgfQogICAgICAgIHMubF9kZXNjID0gbmV3IFRyZWVEZXNjKHMuZHluX2x0cmVlLCBzdGF0aWNfbF9kZXNjKTsKICAgICAgICBzLmRfZGVzYyA9IG5ldyBUcmVlRGVzYyhzLmR5bl9kdHJlZSwgc3RhdGljX2RfZGVzYyk7CiAgICAgICAgcy5ibF9kZXNjID0gbmV3IFRyZWVEZXNjKHMuYmxfdHJlZSwgc3RhdGljX2JsX2Rlc2MpOwogICAgICAgIHMuYmlfYnVmID0gMDsKICAgICAgICBzLmJpX3ZhbGlkID0gMDsKICAgICAgICBpbml0X2Jsb2NrKHMpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF90cl9zdG9yZWRfYmxvY2socywgYnVmLCBzdG9yZWRfbGVuLCBsYXN0KSB7CiAgICAgICAgc2VuZF9iaXRzKHMsIChTVE9SRURfQkxPQ0sgPDwgMSkgKyAobGFzdCA/IDEgOiAwKSwgMyk7CiAgICAgICAgY29weV9ibG9jayhzLCBidWYsIHN0b3JlZF9sZW4sIHR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gJiA2NTUzNSB8IDAsIHMyID0gYWRsZXIgPj4+IDE2ICYgNjU1MzUgfCAwLCBuID0gMDsKICAgICAgICB3aGlsZSAobGVuICE9PSAwKSB7CiAgICAgICAgICBuID0gbGVuID4gMmUzID8gMmUzIDogbGVuOwogICAgICAgICAgbGVuIC09IG47CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIHMxID0gczEgKyBidWZbcG9zKytdIHwgMDsKICAgICAgICAgICAgczIgPSBzMiArIHMxIHwgMDsKICAgICAgICAgIH0gd2hpbGUgKC0tbik7CiAgICAgICAgICBzMSAlPSA2NTUyMTsKICAgICAgICAgIHMyICU9IDY1NTIxOwogICAgICAgIH0KICAgICAgICByZXR1cm4gczEgfCBzMiA8PCAxNiB8IDA7CiAgICAgIH0KICAgICAgbW9kdWxlLmV4cG9ydHMgPSBhZGxlcjMyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvY3JjMzIuanMKICB2YXIgcmVxdWlyZV9jcmMzMiA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9jcmMzMi5qcyIoZXhwb3J0cywgbW9kdWxlKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBmdW5jdGlvbiBtYWtlVGFibGUoKSB7CiAgICAgICAgdmFyIGMsIHRhYmxlID0gW107CiAgICAgICAgZm9yICh2YXIgbiA9IDA7IG4gPCAyNTY7IG4rKykgewogICAgICAgICAgYyA9IG47CiAgICAgICAgICBmb3IgKHZhciBrID0gMDsgayA8IDg7IGsrKykgewogICAgICAgICAgICBjID0gYyAmIDEgPyAzOTg4MjkyMzg0IF4gYyA+Pj4gMSA6IGMgPj4+IDE7CiAgICAgICAgICB9CiAgICAgICAgICB0YWJsZVtuXSA9IGM7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0YWJsZTsKICAgICAgfQogICAgICB2YXIgY3JjVGFibGUgPSBtYWtlVGFibGUoKTsKICAgICAgZnVuY3Rpb24gY3JjMzIyKGNyYywgYnVmLCBsZW4sIHBvcykgewogICAgICAgIHZhciB0ID0gY3JjVGFibGUsIGVuZCA9IHBvcyArIGxlbjsKICAgICAgICBjcmMgXj0gLTE7CiAgICAgICAgZm9yICh2YXIgaSA9IHBvczsgaSA8IGVuZDsgaSsrKSB7CiAgICAgICAgICBjcmMgPSBjcmMgPj4+IDggXiB0WyhjcmMgXiBidWZbaV0pICYgMjU1XTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGNyYyBeIC0xOwogICAgICB9CiAgICAgIG1vZHVsZS5leHBvcnRzID0gY3JjMzIyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvbWVzc2FnZXMuanMKICB2YXIgcmVxdWlyZV9tZXNzYWdlczIgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvbWVzc2FnZXMuanMiKGV4cG9ydHMsIG1vZHVsZSkgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgbW9kdWxlLmV4cG9ydHMgPSB7CiAgICAgICAgMjogIm5lZWQgZGljdGlvbmFyeSIsCiAgICAgICAgMTogInN0cmVhbSBlbmQiLAogICAgICAgIDA6ICIiLAogICAgICAgICItMSI6ICJmaWxlIGVycm9yIiwKICAgICAgICAiLTIiOiAic3RyZWFtIGVycm9yIiwKICAgICAgICAiLTMiOiAiZGF0YSBlcnJvciIsCiAgICAgICAgIi00IjogImluc3VmZmljaWVudCBtZW1vcnkiL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DS19ET05FID0gMjsKICAgICAgdmFyIEJTX0ZJTklTSF9TVEFSVEVEID0gMzsKICAgICAgdmFyIEJTX0ZJTklTSF9ET05FID0gNDsKICAgICAgdmFyIE9TX0NPREUgPSAzOwogICAgICBmdW5jdGlvbiBlcnIoc3RybSwgZXJyb3JDb2RlKSB7CiAgICAgICAgc3RybS5tc2cgPSBtc2dbZXJyb3JDb2RlXTsKICAgICAgICByZXR1cm4gZXJyb3JDb2RlOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHJhbmsoZikgewogICAgICAgIHJldHVybiAoZiA8PCAxKSAtIChmID4gNCA/IDkgOiAwKTsKICAgICAgfQogICAgICBmdW5jdGlvbiB6ZXJvKGJ1ZikgewogICAgICAgIHZhciBsZW4gPSBidWYubGVuZ3RoOwogICAgICAgIHdoaWxlICgtLWxlbiA+PSAwKSB7CiAgICAgICAgICBidWZbbGVuXSA9IDA7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZsdXNoX3BlbmRpbmcoc3RybSkgewogICAgICAgIHZhciBzID0gc3RybS5zdGF0ZTsKICAgICAgICB2YXIgbGVuID0gcy5wZW5kaW5nOwogICAgICAgIGlmIChsZW4gPiBzdHJtLmF2YWlsX291dCkgewogICAgICAgICAgbGVuID0gc3RybS5hdmFpbF9vdXQ7CiAgICAgICAgfQogICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RybS5vdXRwdXQsIHMucGVuZGluZ19idWYsIHMucGVuZGluZ19vdXQsIGxlbiwgc3RybS5uZXh0X291dCk7CiAgICAgICAgc3RybS5uZXh0X291dCArPSBsZW47CiAgICAgICAgcy5wZW5kaW5nX291dCArPSBsZW47CiAgICAgICAgc3RybS50b3RhbF9vdXQgKz0gbGVuOwogICAgICAgIHN0cm0uYXZhaWxfb3V0IC09IGxlbjsKICAgICAgICBzLnBlbmRpbmcgLT0gbGVuOwogICAgICAgIGlmIChzLnBlbmRpbmcgPT09IDApIHsKICAgICAgICAgIHMucGVuZGluZ19vdXQgPSAwOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBmbHVzaF9ibG9ja19vbmx5KHMsIGxhc3QpIHsKICAgICAgICB0cmVlcy5fdHJfZmx1c2hfYmxvY2socywgcy5ibG9ja19zdGFydCA+PSAwID8gcy5ibG9ja19zdGFydCA6IC0xLCBzLnN0cnN0YXJ0IC0gcy5ibG9ja19zdGFydCwgbGFzdCk7CiAgICAgICAgcy5ibG9ja19zdGFydCA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgZmx1c2hfcGVuZGluZyhzLnN0cm0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHB1dF9ieXRlKHMsIGIpIHsKICAgICAgICBzLnBlbmRpbmdfYnVmW3MucGVuZGluZysrXSA9IGI7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcHV0U2hvcnRNU0IocywgYikgewogICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gYiA+Pj4gOCAmIDI1NTsKICAgICAgICBzLnBlbmRpbmdfYnVmW3MucGVuZGluZysrXSA9IGIgJiAyNTU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcmVhZF9idWYoc3RybSwgYnVmLCBzdGFydCwgc2l6ZSkgewogICAgICAgIHZhciBsZW4gPSBzdHJtLmF2YWlsX2luOwogICAgICAgIGlmIChsZW4gPiBzaXplKSB7CiAgICAgICAgICBsZW4gPSBzaXplOwogICAgICAgIH0KICAgICAgICBpZiAobGVuID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICAgICAgc3RybS5hdmFpbF9pbiAtPSBsZW47CiAgICAgICAgdXRpbHMuYXJyYXlTZXQoYnVmLCBzdHJtLmlucHV0LCBzdHJtLm5leHRfaW4sIGxlbiwgc3RhcnQpOwogICAgICAgIGlmIChzdHJtLnN0YXRlLndyYXAgPT09IDE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ZiAocy5wcmV2X2xlbmd0aCA+PSBzLmdvb2RfbWF0Y2gpIHsKICAgICAgICAgIGNoYWluX2xlbmd0aCA+Pj0gMjsKICAgICAgICB9CiAgICAgICAgaWYgKG5pY2VfbWF0Y2ggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgbmljZV9tYXRjaCA9IHMubG9va2FoZWFkOwogICAgICAgIH0KICAgICAgICBkbyB7CiAgICAgICAgICBtYXRjaCA9IGN1cl9tYXRjaDsKICAgICAgICAgIGlmIChfd2luW21hdGNoICsgYmVzdF9sZW5dICE9PSBzY2FuX2VuZCB8fCBfd2luW21hdGNoICsgYmVzdF9sZW4gLSAxXSAhPT0gc2Nhbl9lbmQxIHx8IF93aW5bbWF0Y2hdICE9PSBfd2luW3NjYW5dIHx8IF93aW5bKyttYXRjaF0gIT09IF93aW5bc2NhbiArIDFdKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgc2NhbiArPSAyOwogICAgICAgICAgbWF0Y2grKzsKICAgICAgICAgIGRvIHsKICAgICAgICAgIH0gd2hpbGUgKF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgc2NhbiA8IHN0cmVuZCk7CiAgICAgICAgICBsZW4gPSBNQVhfTUFUQ0ggLSAoc3RyZW5kIC0gc2Nhbik7CiAgICAgICAgICBzY2FuID0gc3RyZW5kIC0gTUFYX01BVENIOwogICAgICAgICAgaWYgKGxlbiA+IGJlc3RfbGVuKSB7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgPSBjdXJfbWF0Y2g7CiAgICAgICAgICAgIGJlc3RfbGVuID0gbGVuOwogICAgICAgICAgICBpZiAobGVuID49IG5pY2VfbWF0Y2gpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBzY2FuX2VuZDEgPSBfd2luW3NjYW4gKyBiZXN0X2xlbiAtIDFdOwogICAgICAgICAgICBzY2FuX2VuZCA9IF93aW5bc2NhbiArIGJlc3RfbGVuXTsKICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlICgoY3VyX21hdGNoID0gcHJldltjdXJfbWF0Y2ggJiB3bWFza10pID4gbGltaXQgJiYgLS1jaGFpbl9sZW5ndGggIT09IDApOwogICAgICAgIGlmIChiZXN0X2xlbiA8PSBzLmxvb2thaGVhZCkgewogICAgICAgICAgcmV0dXJuIGJlc3RfbGVuOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcy5sb29rYWhlYWQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZmlsbF93aW5kb3cocykgewogICAgICAgIHZhciBfd19zaXplID0gcy53X3NpemU7CiAgICAgICAgdmFyIHAsIG4sIG0sIG1vcmUsIHN0cjsKICAgICAgICBkbyB7CiAgICAgICAgICBtb3JlID0gcy53aW5kb3dfc2l6ZSAtIHMubG9va2FoZWFkIC0gcy5zdHJzdGFydDsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID49IF93X3NpemUgKyAoX3dfc2l6ZSAtIE1JTl9MT09LQUhFQUQpKSB7CiAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHMud2luZG93LCBzLndpbmRvdywgX3dfc2l6ZSwgX3dfc2l6ZSwgMCk7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgLT0gX3dfc2l6ZTsKICAgICAgICAgICAgcy5zdHJzdGFydCAtPSBfd19zaXplOwogICAgICAgICAgICBzLmJsb2NrX3N0YXJ0IC09IF93X3NpemU7CiAgICAgICAgICAgIG4gPSBzLmhhc2hfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5oZWFkWy0tcF07CiAgICAgICAgICAgICAgcy5oZWFkW3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBuID0gX3dfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5wcmV2Wy0tcF07CiAgICAgICAgICAgICAgcy5wcmV2W3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBtb3JlICs9IF93X3NpemU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX2luID09PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgbiA9IHJlYWRfYnVmKHMuc3RybSwgcy53aW5kb3csIHMuc3Ryc3RhcnQgKyBzLmxvb2thaGVhZCwgbW9yZSk7CiAgICAgICAgICBzLmxvb2thaGVhZCArPSBuOwogICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHN0ciA9IHMuc3Ryc3RhcnQgLSBzLmluc2VydDsKICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3N0cl07CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgd2hpbGUgKHMuaW5zZXJ0KSB7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3N0ciArIE1JTl9NQVRDSCAtIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gc3RyOwogICAgICAgICAgICAgIHN0cisrOwogICAgICAgICAgICAgIHMuaW5zZXJ0LS07CiAgICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPCBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBzLnN0cm0uYXZhaWxfaW4gIT09IDApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfc3RvcmVkKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIG1heF9ibG9ja19zaXplID0gNjU1MzU7CiAgICAgICAgaWYgKG1heF9ibG9ja19zaXplID4gcy5wZW5kaW5nX2J1Zl9zaXplIC0gNSkgewogICAgICAgICAgbWF4X2Jsb2NrX3NpemUgPSBzLnBlbmRpbmdfYnVmX3NpemUgLSA1OwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSAxKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDAgJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubG9va2FoZWFkOwogICAgICAgICAgcy5sb29rYWhlYWQgPSAwOwogICAgICAgICAgdmFyIG1heF9zdGFydCA9IHMuYmxvY2tfc3RhcnQgKyBtYXhfYmxvY2tfc2l6ZTsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID09PSAwIHx8IHMuc3Ryc3RhcnQgPj0gbWF4X3N0YXJ0KSB7CiAgICAgICAgICAgIHMubG9va2FoZWFkID0gcy5zdHJzdGFydCAtIG1heF9zdGFydDsKICAgICAgICAgICAgcy5zdHJzdGFydCA9IG1heF9zdGFydDsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgLSBzLmJsb2NrX3N0YXJ0ID49IHMud19zaXplIC0gTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5zdHJzdGFydCA+IHMuYmxvY2tfc3RhcnQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX2Zhc3QocywgZmx1c2gpIHsKICAgICAgICB2YXIgaGFzaF9oZWFkOwogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEICYmIGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaGFzaF9oZWFkID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgaGFzaF9oZWFkID0gcy5wcmV2W3Muc3Ryc3RhcnQgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaGFzaF9oZWFkICE9PSAwICYmIHMuc3Ryc3RhcnQgLSBoYXNoX2hlYWQgPD0gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gbG9uZ2VzdF9tYXRjaChzLCBoYXNoX2hlYWQpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHMubWF0Y2hfbGVuZ3RoID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgcy5zdHJzdGFydCAtIHMubWF0Y2hfc3RhcnQsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA8PSBzLm1heF9sYXp5X21hdGNoICYmIHMubG9va2FoZWFkID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoLS07CiAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9IHdoaWxlICgtLXMubWF0Y2hfbGVuZ3RoICE9PSAwKTsKICAgICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcy5zdHJzdGFydCArPSBzLm1hdGNoX2xlbmd0aDsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3Muc3Ryc3RhcnRdOwogICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IHMuc3Ryc3RhcnQgPCBNSU5fTUFUQ0ggLSAxID8gcy5zdHJzdGFydCA6IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9zbG93KHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGhhc2hfaGVhZDsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIHZhciBtYXhfaW5zZXJ0OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGhhc2hfaGVhZCA9IDA7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICBzLmhlYWRbcy5pbnNfaF0gPSBzLnN0c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gIHMucHJldl9sZW5ndGggLT0gMjsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIGlmICgrK3Muc3Ryc3RhcnQgPD0gbWF4X2luc2VydCkgewogICAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gd2hpbGUgKC0tcy5wcmV2X2xlbmd0aCAhPT0gMCk7CiAgICAgICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMDsKICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAocy5tYXRjaF9hdmFpbGFibGUpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5tYXRjaF9hdmFpbGFibGUgPSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLm1hdGNoX2F2YWlsYWJsZSkgewogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gcy5zdHJzdGFydCA8IE1JTl9NQVRDSCAtIDEgPyBzLnN0cnN0YXJ0IDogTUlOX01BVENIIC0gMTsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5sYXN0X2xpdCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gQlNfQkxPQ0tfRE9ORTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX3JsZShzLCBmbHVzaCkgewogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgdmFyIHByZXY7CiAgICAgICAgdmFyIHNjYW4sIHN0cmVuZDsKICAgICAgICB2YXIgX3dpbiA9IHMud2luZG93OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0ggJiYgcy5zdHJzdGFydCA+IDApIHsKICAgICAgICAgICAgc2NhbiA9IHMuc3Ryc3RhcnQgLSAxOwogICAgICAgICAgICBwcmV2ID0gX3dpbltzY2FuXTsKICAgICAgICAgICAgaWYgKHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dKSB7CiAgICAgICAgICAgICAgc3RyZW5kID0gcy5zdHJzdGFydCArIE1BWF9NQVRDSDsKICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgfSB3aGlsZSAocHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBzY2FuIDwgc3RyZW5kKTsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IE1BWF9NQVRDSCAtIChzdHJlbmQgLSBzY2FuKTsKICAgICAgICAgICAgICBpZiAocy5tYXRjaF9sZW5ndGggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBzLmxvb2thaGVhZDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDEsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgKz0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9odWZmKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGJmbHVzaDsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSAwOwogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnRdKTsKICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19CTE9DS19ET05FOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIENvbmZpZyhnb29kX2xlbmd0aCwgbWF4X2xhenksIG5pY2VfbGVuZ3RoLCBtYXhfY2hhaW4sIGZ1bmMpIHsKICAgICAgICB0aGlzLmdvb2RfbGVuZ3RoID0gZ29vZF9sZW5ndGg7CiAgICAgICAgdGhpcy5tYXhfbGF6eSA9IG1heF9sYXp5OwogICAgICAgIHRoaXMubmljZV9sZW5ndGggPSBuaWNlX2xlbmd0aDsKICAgICAgICB0aGlzLm1heF9jaGFpbiA9IG1heF9jaGFpbjsKICAgICA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A9IGNvbmZpZ3VyYXRpb25fdGFibGVbcy5sZXZlbF0ubmljZV9sZW5ndGg7CiAgICAgICAgcy5tYXhfY2hhaW5fbGVuZ3RoID0gY29uZmlndXJhdGlvbl90YWJsZVtzLmxldmVsXS5tYXhfY2hhaW47CiAgICAgICAgcy5zdHJzdGFydCA9IDA7CiAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgcy5sb29rYWhlYWQgPSAwOwogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IHMucHJldl9sZW5ndGggPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMDsKICAgICAgICBzLmluc19oID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBEZWZsYXRlU3RhdGUoKSB7CiAgICAgICAgdGhpcy5zdHJtID0gbnVsbDsKICAgICAgICB0aGlzLnN0YXR1cyA9IDA7CiAgICAgICAgdGhpcy5wZW5kaW5nX2J1ZiA9IG51bGw7CiAgICAgICAgdGhpcy5wZW5kaW5nX2J1Zl9zaXplID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmcgPSAwOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5nemhlYWQgPSBudWxsOwogICAgICAgIHRoaXMuZ3ppbmRleCA9IDA7CiAgICAgICAgdGhpcy5tZXRob2QgPSBaX0RFRkxBVEVEOwogICAgICAgIHRoaXMubGFzdF9mbHVzaCA9IC0xOwogICAgICAgIHRoaXMud19zaXplID0gMDsKICAgICAgICB0aGlzLndfYml0cyA9IDA7CiAgICAgICAgdGhpcy53X21hc2sgPSAwOwogICAgICAgIHRoaXMud2luZG93ID0gbnVsbDsKICAgICAgICB0aGlzLndpbmRvd19zaXplID0gMDsKICAgICAgICB0aGlzLnByZXYgPSBudWxsOwogICAgICAgIHRoaXMuaGVhZCA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B0aGlzLmxfZGVzYyA9IG51bGw7CiAgICAgICAgdGhpcy5kX2Rlc2MgPSBudWxsOwogICAgICAgIHRoaXMuYmxfZGVzYyA9IG51bGw7CiAgICAgICAgdGhpcy5ibF9jb3VudCA9IG5ldyB1dGlscy5CdWYxNihNQVhfQklUUyArIDEpOwogICAgICAgIHRoaXMuaGVhcCA9IG5ldyB1dGlscy5CdWYxNigyICogTF9DT0RFUyArIDEpOwogICAgICAgIHplcm8odGhpcy5oZWFwKTsKICAgICAgICB0aGlzLmhlYXBfbGVuID0gMDsKICAgICAgICB0aGlzLmhlYXBfbWF4ID0gMDsKICAgICAgICB0aGlzLmRlcHRoID0gbmV3IHV0aWxzLkJ1ZjE2KDIgKiBMX0NPREVTICsgMSk7CiAgICAgICAgemVybyh0aGlzLmRlcHRoKTsKICAgICAgICB0aGlzLmxfYnVmID0gMDsKICAgICAgICB0aGlzLmxpdF9idWZzaXplID0gMDsKICAgICAgICB0aGlzLmxhc3RfbGl0ID0gMDsKICAgICAgICB0aGlzLmRfYnVmID0gMDsKICAgICAgICB0aGlzLm9wdF9sZW4gPSAwOwogICAgICAgIHRoaXMuc3RhdGljX2xlbiA9IDA7CiAgICAgICAgdGhpcy5tYXRjaGVzID0gMDsKICAgICAgICB0aGlzLmluc2VydCA9IDA7CiAgICAgICAgdGhpcy5iaV9idWYgPSAwOwogICAgICAgIHRoaXMuYmlfdmFsaWQgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVSZXNldEtlZXAoc3RybSkgewogICAgICAgIHZhciBzOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBaX1NUUkVBTV9FUlJPUik7CiAgICAgICAgfQogICAgICAgIHN0cm0udG90YWxfaW4gPSBzdHJtLnRvdGFsX291dCA9IDA7CiAgICAgICAgc3RybS5kYXRhX3R5cGUgPSBaX1VOS05PV047CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgcy5wZW5kaW5nID0gMDsKICAgICAgICBzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICBpZiAocy53cmFwIDwgMCkgewogICAgICAgICAgcy53cmFwID0gLXMud3JhcDsKICAgICAgICB9CiAgICAgICAgcy5zdGF0dXMgPSBzLndyYXAgPyBJTklUX1NUQVRFIDogQlVTWV9TVEFURTsKICAgICAgICBzdHJtLmFkbGVyID0gcy53cmFwID09PSAyID8gMCA6IDE7CiAgICAgICAgcy5sYXN0X2ZsdXNoID0gWl9OT19GTFVTSDsKICAgICAgICB0cmVlcy5fdHJfaW5pdChzKTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmVzZXQoc3RybSkgewogICAgICAgIHZhciByZXQgPSBkZWZsYXRlUmVzZXRLZWVwKHN0cm0pOwogICAgICAgIGlmIChyZXQgPT09IFpfT0spIHsKICAgICAgICAgIGxtX2luaXQoc3RybS5zdGF0ZSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZVNldEhlYWRlcihzdHJtLCBoZWFkKSB7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmIChzdHJtLnN0YXRlLndyYXAgIT09IDIpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RybS5zdGF0ZS5nemhlYWQgPSBoZWFkOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVJbml0MihzdHJtLCBsZXZlbCwgbWV0aG9kLCB3aW5kb3dCaXRzLCBtZW1MZXZlbCwgc3RyYXRlZ3kpIHsKICAgICAgICBpZiAoIXN0cm0pIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgdmFyIHdyYXAgPSAxOwogICAgICAgIGlmIChsZXZlbCA9PT0gWl9ERUZBVUxUX0NPTVBSRVNTSU9OKSB7CiAgICAgICAgICBsZXZlbCA9IDY7CiAgICAgICAgfQogICAgICAgIGlmICh3aW5kb3dCaXRzIDwgMCkgewogICAgICAgICAgd3JhcCA9IDA7CiAgICAgICAgICB3aW5kb3dCaXRzID0gLXdpbmRvd0JpdHM7CiAgICAgICAgfSBlbHNlIGlmICh3aW5kb3dCaXRzID4gMTUpIHsKICAgICAgICAgIHdyYXAgPSAyOwogICAgICAgICAgd2luZG93Qml0cyAtPSAxNjsKICAgICAgICB9CiAgICAgICAgaWYgKG1lbUxldmVsIDwgMSB8fCBtZW1MZXZlbCA+IE1BWF9NRU1fTEVWRUwgfHwgbWV0aG9kICE9PSBaX0RFRkxBVEVEIHx8IHdpbmRvd0JpdHMgPCA4IHx8IHdpbmRvd0JpdHMgPiAxNSB8fCBsZXZlbCA8IDAgfHwgbGV2ZWwgPiA5IHx8IHN0cmF0ZWd5IDwgMCB8fCBzdHJhdGVneSA+IFpfRklYRUQpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyA9PT0gOCkgewogICAgICAgICAgd2luZG93Qml0cyA9IDk7CiAgICAgICAgfQogICAgICAgIHZhciBzID0gbmV3IERlZmxhdGVTdGF0ZSgpOwogICAgICAgIHN0cm0uc3RhdGUgPSBzOwogICAgICAgIHMuc3RybSA9IHN0cm07CiAgICAgICAgcy53cmFwID0gd3JhcDsKICAgICAgICBzLmd6aGVhZCA9IG51bGw7CiAgICAgICAgcy53X2JpdHMgPSB3aW5kb3dCaXRzOwogICAgICAgIHMud19zaXplID0gMSA8PCBzLndfYml0czsKICAgICAgICBzLndfbWFzayA9IHMud19zaXplIC0gMTsKIC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CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGUoc3RybSwgZmx1c2gpIHsKICAgICAgICB2YXIgb2xkX2ZsdXNoLCBzOwogICAgICAgIHZhciBiZWcsIHZhbDsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUgfHwgZmx1c2ggPiBaX0JMT0NLIHx8IGZsdXNoIDwgMCkgewogICAgICAgICAgcmV0dXJuIHN0cm0gPyBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpIDogWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHMgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmICghc3RybS5vdXRwdXQgfHwgIXN0cm0uaW5wdXQgJiYgc3RybS5hdmFpbF9pbiAhPT0gMCB8fCBzLnN0YXR1cyA9PT0gRklOSVNIX1NUQVRFICYmIGZsdXNoICE9PSBaX0ZJTklTSCkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBzdHJtLmF2YWlsX291dCA9PT0gMCA/IFpfQlVGX0VSUk9SIDogWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBzLnN0cm0gPSBzdHJtOwogICAgICAgIG9sZF9mbHVzaCA9IHMubGFzdF9mbHVzaDsKICAgICAgICBzLmxhc3RfZmx1c2ggPSBmbHVzaDsKICAgICAgICBpZiAocy5zdGF0dXMgPT09IElOSVRfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLndyYXAgPT09IDIpIHsKICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgIHB1dF9ieXRlKHMsIDMxKTsKICAgICAgICAgICAgcHV0X2J5dGUocywgMTM5KTsKICAgICAgICAgICAgcHV0X2J5dGUocywgOCk7CiAgICAgICAgICAgIGlmICghcy5nemhlYWQpIHsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgT1NfQ09ERSk7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIChzLmd6aGVhZC50ZXh0ID8gMSA6IDApICsgKHMuZ3poZWFkLmhjcmMgPyAyIDogMCkgKyAoIXMuZ3poZWFkLmV4dHJhID8gMCA6IDQpICsgKCFzLmd6aGVhZC5uYW1lID8gMCA6IDgpICsgKCFzLmd6aGVhZC5jb21tZW50ID8gMCA6IDE2KSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiA4ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDE2ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDI0ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQub3MgJiAyNTUpOwogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5leHRyYSAmJiBzLmd6aGVhZC5leHRyYS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLmV4dHJhLmxlbmd0aCAmIDI1NSk7CiAgICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYS5sZW5ndGggPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjKSB7CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZywgMCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBFWFRSQV9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdmFyIGhlYWRlciA9IFpfREVGTEFURUQgKyAocy53X2JpdHMgLSA4IDw8IDQpIDw8IDg7CiAgICAgICAgICAgIHZhciBsZXZlbF9mbGFncyA9IC0xOwogICAgICAgICAgICBpZiAocy5zdHJhdGVneSA+PSBaX0hVRkZNQU5fT05MWSB8fCBzLmxldmVsIDwgMikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMDsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsIDwgNikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMTsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsID09PSA2KSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAyOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMzsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZWFkZXIgfD0gbGV2ZWxfZmxhZ3MgPDwgNjsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBoZWFkZXIgfD0gUFJFU0VUX0RJQ1Q7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaGVhZGVyICs9IDMxIC0gaGVhZGVyICUgMzE7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgICAgcHV0U2hvcnRNU0IocywgaGVhZGVyKTsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBzdHJtLmFkbGVyID4+PiAxNik7CiAgICAgICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxlciAmIDY1NTM1KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzdHJtLmFkbGVyID0gMTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBFWFRSQV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmV4dHJhKSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgd2hpbGUgKHMuZ3ppbmRleCA8IChzLmd6aGVhZC5leHRyYS5sZW5ndGggJiA2NTUzNSkpIHsKICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLmV4dHJhW3MuZ3ppbmRleF0gJiAyNTUpOwogICAgICAgICAgICAgIHMuZ3ppbmRleCsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMjIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPT09IHMuZ3poZWFkLmV4dHJhLmxlbmd0aCkgewogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBOQU1FX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IE5BTUVfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gTkFNRV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLm5hbWUpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICAgIHZhbCA9IDE7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAocy5nemluZGV4IDwgcy5nemhlYWQubmFtZS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHZhbCA9IHMuZ3poZWFkLm5hbWUuY2hhckNvZGVBdChzLmd6aW5kZXgrKykgJiAyNTU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHZhbCA9IDA7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHZhbCk7CiAgICAgICAgICAgIH0gd2hpbGUgKHZhbCAhPT0gMCk7CiAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMjIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh2YWwgPT09IDApIHsKICAgICAgICAgICAgICBzLmd6aW5kZXggPSAwOwogICAgICAgICAgICAgIHMuc3RhdHVzID0gQ09NTUVOVF9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5zdGF0dXMgPSBDT01NRU5UX1NUQVRFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IENPTU1FTlRfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLmd6aGVhZC5jb21tZW50KSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMjIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgICB2YWwgPSAxOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHMuZ3ppbmRleCA8IHMuZ3poZWFkLmNvbW1lbnQubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICB2YWwgPSBzLmd6aGVhZC5jb21tZW50LmNoYXJDb2RlQXQocy5nemluZGV4KyspICYgMjU1OwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB2YWwgPSAwOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBwdXRfYnl0ZShzLCB2YWwpOwogICAgICAgICAgICB9IHdoaWxlICh2YWwgIT09IDApOwogICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodmFsID09PSAwKSB7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBIQ1JDX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IEhDUkNfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gSENSQ19TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMpIHsKICAgICAgICAgICAgaWYgKHMucGVuZGluZyArIDIgPiBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgKyAyIDw9IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgJiAyNTUpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IEJVU1lfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnBlbmRpbmcgIT09IDApIHsKICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgIHJldHVybiBaX09LOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSBpZiAoc3RybS5hdmFpbF9pbiA9PT0gMCAmJiByYW5rKGZsdXNoKSA8PSByYW5rKG9sZF9mbHVzaCkgJiYgZmx1c2ggIT09IFpfRklOSVNIKSB7CiAgICAgICAgICByZXR1cm4gZXJyKHN0cm0sIFpfQlVGX0VSUk9SKTsK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FsaWduKHMpOwogICAgICAgICAgICB9IGVsc2UgaWYgKGZsdXNoICE9PSBaX0JMT0NLKSB7CiAgICAgICAgICAgICAgdHJlZXMuX3RyX3N0b3JlZF9ibG9jayhzLCAwLCAwLCBmYWxzZSk7CiAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZVTExfRkxVU0gpIHsKICAgICAgICAgICAgICAgIHplcm8ocy5oZWFkKTsKICAgICAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGZsdXNoICE9PSBaX0ZJTklTSCkgewogICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChzLndyYXAgPD0gMCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VORDsKICAgICAgICB9CiAgICAgICAgaWYgKHMud3JhcCA9PT0gMikgewogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDggJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciA+PiAxNiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+ID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AgICAgIHJldHVybiBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBzdHJtLnN0YXRlID0gbnVsbDsKICAgICAgICByZXR1cm4gc3RhdHVzID09PSBCVVNZX1NUQVRFID8gZXJyKHN0cm0sIFpfREFUQV9FUlJPUikgOiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVTZXREaWN0aW9uYXJ5KHN0cm0sIGRpY3Rpb25hcnkpIHsKICAgICAgICB2YXIgZGljdExlbmd0aCA9IGRpY3Rpb25hcnkubGVuZ3RoOwogICAgICAgIHZhciBzOwogICAgICAgIHZhciBzdHIsIG47CiAgICAgICAgdmFyIHdyYXA7CiAgICAgICAgdmFyIGF2YWlsOwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBpbnB1dDsKICAgICAgICB2YXIgdG1wRGljdDsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgd3JhcCA9IHMud3JhcDsKICAgICAgICBpZiAod3JhcCA9PT0gMiB8fCB3cmFwID09PSAxICYmIHMuc3RhdHVzICE9PSBJTklUX1NUQVRFIHx8IHMubG9va2FoZWFkKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmICh3cmFwID09PSAxKSB7CiAgICAgICAgICBzdHJtLmFkbGVyID0gYWRsZXIzMihzdHJtLmFkbGVyLCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoLCAwKTsKICAgICAgICB9CiAgICAgICAgcy53cmFwID0gMDsKICAgICAgICBpZiAoZGljdExlbmd0aCA+PSBzLndfc2l6ZSkgewogICAgICAgICAgaWYgKHdyYXAgPT09IDApIHsKICAgICAgICAgICAgemVybyhzLmhlYWQpOwogICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHRtcERpY3QgPSBuZXcgdXRpbHMuQnVmOChzLndfc2l6ZSk7CiAgICAgICAgICB1dGlscy5hcnJheVNldCh0bXBEaWN0LCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoIC0gcy53X3NpemUsIHMud19zaXplLCAwKTsKICAgICAgICAgIGRpY3Rpb25hcnkgPSB0bXBEaWN0OwogICAgICAgICAgZGljdExlbmd0aCA9IHMud19zaXplOwogICAgICAgIH0KICAgICAgICBhdmFpbCA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgbmV4dCA9IHN0cm0ubmV4dF9pbjsKICAgICAgICBpbnB1dCA9IHN0cm0uaW5wdXQ7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IGRpY3RMZW5ndGg7CiAgICAgICAgc3RybS5uZXh0X2luID0gMDsKICAgICAgICBzdHJtLmlucHV0ID0gZGljdGlvbmFyeTsKICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICB3aGlsZSAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICBzdHIgPSBzLnN0cnN0YXJ0OwogICAgICAgICAgbiA9IHMubG9va2FoZWFkIC0gKE1JTl9NQVRDSCAtIDEpOwogICAgICAgICAgZG8gewogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbc3RyICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHN0cjsKICAgICAgICAgICAgc3RyKys7CiAgICAgICAgICB9IHdoaWxlICgtLW4pOw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b3MgKyAxKTsKICAgICAgICAgICAgaWYgKChjMiAmIDY0NTEyKSA9PT0gNTYzMjApIHsKICAgICAgICAgICAgICBjID0gNjU1MzYgKyAoYyAtIDU1Mjk2IDw8IDEwKSArIChjMiAtIDU2MzIwKTsKICAgICAgICAgICAgICBtX3BvcysrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDEyOCkgewogICAgICAgICAgICBidWZbaSsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCAyMDQ4KSB7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTkyIHwgYyA+Pj4gNjsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCA2NTUzNikgewogICAgICAgICAgICBidWZbaSsrXSA9IDIyNCB8IGMgPj4+IDEyOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDYgJiA2MzsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBidWZbaSsrXSA9IDI0MCB8IGMgPj4+IDE4OwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDEyICYgNjM7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyA+Pj4gNiAmIDYzOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgJiA2MzsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gYnVmMmJpbnN0cmluZyhidWYsIGxlbikgewogICAgICAgIGlmIChsZW4gPCA2NTUzNCkgewogICAgICAgICAgaWYgKGJ1Zi5zdWJhcnJheSAmJiBTVFJfQVBQTFlfVUlBX09LIHx8ICFidWYuc3ViYXJyYXkgJiYgU1RSX0FQUExZX09LKSB7CiAgICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KG51bGwsIHV0aWxzLnNocmlua0J1ZihidWYsIGxlbikpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgcmVzdWx0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgfQogICAgICBleHBvcnRzLmJ1ZjJiaW5zdHJpbmcgPSBmdW5jdGlvbihidWYpIHsKICAgICAgICByZXR1cm4gYnVmMmJpbnN0cmluZyhidWYsIGJ1Zi5sZW5ndGgpOwogICAgICB9OwogICAgICBleHBvcnRzLmJpbnN0cmluZzJidWYgPSBmdW5jdGlvbihzdHIpIHsKICAgICAgICB2YXIgYnVmID0gbmV3IHV0aWxzLkJ1Zjgoc3RyLmxlbmd0aCk7CiAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IGJ1Zi5sZW5ndGg7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgYnVmW2ldID0gc3RyLmNoYXJDb2RlQXQoaSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIGV4cG9ydHMuYnVmMnN0cmluZyA9IGZ1bmN0aW9uKGJ1ZiwgbWF4KSB7CiAgICAgICAgdmFyIGksIG91dCwgYywgY19sZW47CiAgICAgICAgdmFyIGxlbiA9IG1heCB8fCBidWYubGVuZ3RoOwogICAgICAgIHZhciB1dGYxNmJ1ZiA9IG5ldyBBcnJheShsZW4gKiAyKTsKICAgICAgICBmb3IgKG91dCA9IDAsIGkgPSAwOyBpIDwgbGVuOyApIHsKICAgICAgICAgIGMgPSBidWZbaSsrXTsKICAgICAgICAgIGlmIChjIDwgMTI4KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgY19sZW4gPSBfdXRmOGxlbltjXTsKICAgICAgICAgIGlmIChjX2xlbiA+IDQpIHsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNjU1MzM7CiAgICAgICAgICAgIGkgKz0gY19sZW4gLSAxOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGMgJj0gY19sZW4gPT09IDIgPyAzMSA6IGNfbGVuID09PSAzID8gMTUgOiA3OwogICAgICAgICAgd2hpbGUgKGNfbGVuID4gMSAmJiBpIDwgbGVuKSB7CiAgICAgICAgICAgIGMgPSBjIDw8IDYgfCBidWZbaSsrXSAmIDYzOwogICAgICAgICAgICBjX2xlbi0tOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGNfbGVuID4gMSkgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA2NTUzMzsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDY1NTM2KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjIC09IDY1NTM2OwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NTI5NiB8IGMgPj4gMTAgJiAxMDIzOwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NjMyMCB8IGMgJiAxMDIzOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gYnVmMmJpbnN0cmluZyh1dGYxNmJ1Ziwgb3V0KTsKICAgICAgfTsKICAgICAgZXhwb3J0cy51dGY4Ym9yZGVyID0gZnVuY3Rpb24oYnVmLCBtYXgpIHsKICAgICAgICB2YXIgcG9zOwogICAgICAgIG1heCA9IG1heCB8fCBidWYubGVuZ3RoOwogICAgICAgIGlmIChtYXggPiBidWYubGVuZ3RoKSB7CiAgICAgICAgICBtYXggPSBidWYubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBwb3MgPSBtYXggLSAxOwogICAgICAgIHdoaWxlIChwb3MgPj0gMCAmJiAoYnVmW3Bvc10gJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgIHBvcy0tOwogICAgICAgIH0KICAgICAgICBpZiAocG9zIDwgMCkgewogICAgICAgICAgcmV0dXJuIG1heDsKICAgICAgICB9CiAgICAgICAgaWYgKHBvcyA9PT0gMCkgewogICAgICAgICAgcmV0dXJuIG1heDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHBvcyArIF91dGY4bGVuW2J1Zltwb3NdXSA+IG1heCA/IHBvcyA6IG1heDsKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL3pzdHJlYW0uanMKICB2YXIgcmVxdWlyZV96c3RyZWFtID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL3pzdHJlYW0uanMiKGV4cG9ydHMsIG1vZHVsZSkgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgZnVuY3Rpb24gWlN0cmVhbSgpIHsKICAgICAgICB0aGlzLmlucHV0ID0gbnVsbDsKICAgICAgICB0aGlzLm5leHRfaW4gPSAwOwogICAgICAgIHRoaXMuYXZhaWxfaW4gPSAwOwogICAgICAgIHRoaXMudG90YWxfaW4gPSAwOwogICAgICAgIHRoaXMub3V0cHV0ID0gbnVsbDsKICAgICAgICB0aGlzLm5leHRfb3V0ID0gMDsKICAgICAgICB0aGlzLmF2YWlsX291dCA9IDA7CiAgICAgICAgdGhpcy50b3RhbF9vdXQgPSAwOwogICAgICAgIHRoaXMubXNnID0gIiI7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4OwogICAgICBmdW5jdGlvbiBEZWZsYXRlKG9wdGlvbnMpIHsKICAgICAgICBpZiAoISh0aGlzIGluc3RhbmNlb2YgRGVmbGF0ZSkpCiAgICAgICAgICByZXR1cm4gbmV3IERlZmxhdGUob3B0aW9ucyk7CiAgICAgICAgdGhpcy5vcHRpb25zID0gdXRpbHMuYXNzaWduKHsKICAgICAgICAgIGxldmVsOiBaX0RFRkFVTFRfQ09NUFJFU1NJT04sCiAgICAgICAgICBtZXRob2Q6IFpfREVGTEFURUQsCiAgICAgICAgICBjaHVua1NpemU6IDE2Mzg0LAogICAgICAgICAgd2luZG93Qml0czogMTUsCiAgICAgICAgICBtZW1MZXZlbDogOCwKICAgICAgICAgIHN0cmF0ZWd5OiBaX0RFRkFVTFRfU1RSQVRFR1ksCiAgICAgICAgICB0bzogIiIKICAgICAgICB9LCBvcHRpb25zIHx8IHt9KTsKICAgICAgICB2YXIgb3B0ID0gdGhpcy5vcHRpb25zOwogICAgICAgIGlmIChvcHQucmF3ICYmIG9wdC53aW5kb3dCaXRzID4gMCkgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgPSAtb3B0LndpbmRvd0JpdHM7CiAgICAgICAgfSBlbHNlIGlmIChvcHQuZ3ppcCAmJiBvcHQud2luZG93Qml0cyA+IDAgJiYgb3B0LndpbmRvd0JpdHMgPCAxNikgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgKz0gMTY7CiAgICAgICAgfQogICAgICAgIHRoaXMuZXJyID0gMDsKICAgICAgICB0aGlzLm1zZyA9ICIiOwogICAgICAgIHRoaXMuZW5kZWQgPSBmYWxzZTsKICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuc3RybSA9IG5ldyBaU3RyZWFtKCk7CiAgICAgICAgdGhpcy5zdHJtLmF2YWlsX291dCA9IDA7CiAgICAgICAgdmFyIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlSW5pdDIodGhpcy5zdHJtLCBvcH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uY3Rpb24oZGF0YSwgbW9kZSkgewogICAgICAgIHZhciBzdHJtID0gdGhpcy5zdHJtOwogICAgICAgIHZhciBjaHVua1NpemUgPSB0aGlzLm9wdGlvbnMuY2h1bmtTaXplOwogICAgICAgIHZhciBzdGF0dXMsIF9tb2RlOwogICAgICAgIGlmICh0aGlzLmVuZGVkKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICAgIF9tb2RlID0gbW9kZSA9PT0gfn5tb2RlID8gbW9kZSA6IG1vZGUgPT09IHRydWUgPyBaX0ZJTklTSCA6IFpfTk9fRkxVU0g7CiAgICAgICAgaWYgKHR5cGVvZiBkYXRhID09PSAic3RyaW5nIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IHN0cmluZ3Muc3RyaW5nMmJ1ZihkYXRhKTsKICAgICAgICB9IGVsc2UgaWYgKHRvU3RyaW5nLmNhbGwoZGF0YSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBuZXcgVWludDhBcnJheShkYXRhKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgc3RybS5pbnB1dCA9IGRhdGE7CiAgICAgICAgfQogICAgICAgIHN0cm0ubmV4dF9pbiA9IDA7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IHN0cm0uaW5wdXQubGVuZ3RoOwogICAgICAgIGRvIHsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzdHJtLm91dHB1dCA9IG5ldyB1dGlscy5CdWY4KGNodW5rU2l6ZSk7CiAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSAwOwogICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlKHN0cm0sIF9tb2RlKTsKICAgICAgICAgIGlmIChzdGF0dXMgIT09IFpfU1RSRUFNX0VORCAmJiBzdGF0dXMgIT09IFpfT0spIHsKICAgICAgICAgICAgdGhpcy5vbkVuZChzdGF0dXMpOwogICAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwIHx8IHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgKF9tb2RlID09PSBaX0ZJTklTSCB8fCBfbW9kZSA9PT0gWl9TWU5DX0ZMVVNIMikpIHsKICAgICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICB0aGlzLm9uRGF0YShzdHJpbmdzLmJ1ZjJiaW5zdHJpbmcodXRpbHMuc2hyaW5rQnVmKHN0cm0ub3V0cHV0LCBzdHJtLm5leHRfb3V0KSkpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKHN0cm0uYXZhaWxfaW4gPiAwIHx8IHN0cm0uYXZhaWxfb3V0ID09PSAwKSAmJiBzdGF0dXMgIT09IFpfU1RSRUFNX0VORCk7CiAgICAgICAgaWYgKF9tb2RlID09PSBaX0ZJTklTSCkgewogICAgICAgICAgc3RhdHVzID0gemxpYl9kZWZsYXRlLmRlZmxhdGVFbmQodGhpcy5zdHJtKTsKICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgcmV0dXJuIHN0YXR1cyA9PT0gWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBaX1NZTkNfRkxVU0gyKSB7CiAgICAgICAgICB0aGlzLm9uRW5kKFpfT0spOwogICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0cnVlOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkRhdGEgPSBmdW5jdGlvbihjaHVuaykgewogICAgICAgIHRoaXMuY2h1bmtzLnB1c2goY2h1bmspOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkVuZCA9IGZ1bmN0aW9uKHN0YXR1cykgewogICAgICAgIGlmIChzdGF0dXMgPT09IFpfT0spIHsKICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdGhpcy5jaHVua3Muam9pbigiIik7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHV0aWxzLmZsYXR0ZW5DaHVua3ModGhpcy5jaHVua3MpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuZXJyID0gc3RhdHVzOwogICAgICAgIHRoaXMubXNnID0gdGhpcy5zdHJtLm1zZzsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gZGVmbGF0ZShpbnB1dCwgb3B0aW9ucykgewogICAgICAgIHZhciBkZWZsYXRvciA9IG5ldyBEZWZsYXRlKG9wdGlvbnMpOwogICAgICAgIGRlZmxhdG9yLnB1c2goaW5wdXQsIHRydWUpOwogICAgICAgIGlmIChkZWZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IGRlZmxhdG9yLm1zZyB8fCBtc2dbZGVmbGF0b3IuZXJyXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGRlZmxhdG9yLnJlc3VsdDsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmF3KGlucHV0LCBvcHRpb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ciBiZWc7CiAgICAgICAgdmFyIGVuZDsKICAgICAgICB2YXIgZG1heDsKICAgICAgICB2YXIgd3NpemU7CiAgICAgICAgdmFyIHdoYXZlOwogICAgICAgIHZhciB3bmV4dDsKICAgICAgICB2YXIgc193aW5kb3c7CiAgICAgICAgdmFyIGhvbGQ7CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIGxjb2RlOwogICAgICAgIHZhciBkY29kZTsKICAgICAgICB2YXIgbG1hc2s7CiAgICAgICAgdmFyIGRtYXNrOwogICAgICAgIHZhciBoZXJlOwogICAgICAgIHZhciBvcDsKICAgICAgICB2YXIgbGVuOwogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBmcm9tOwogICAgICAgIHZhciBmcm9tX3NvdXJjZTsKICAgICAgICB2YXIgaW5wdXQsIG91dHB1dDsKICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgX2luID0gc3RybS5uZXh0X2luOwogICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICBsYXN0ID0gX2luICsgKHN0cm0uYXZhaWxfaW4gLSA1KTsKICAgICAgICBfb3V0ID0gc3RybS5uZXh0X291dDsKICAgICAgICBvdXRwdXQgPSBzdHJtLm91dHB1dDsKICAgICAgICBiZWcgPSBfb3V0IC0gKHN0YXJ0IC0gc3RybS5hdmFpbF9vdXQpOwogICAgICAgIGVuZCA9IF9vdXQgKyAoc3RybS5hdmFpbF9vdXQgLSAyNTcpOwogICAgICAgIGRtYXggPSBzdGF0ZS5kbWF4OwogICAgICAgIHdzaXplID0gc3RhdGUud3NpemU7CiAgICAgICAgd2hhdmUgPSBzdGF0ZS53aGF2ZTsKICAgICAgICB3bmV4dCA9IHN0YXRlLnduZXh0OwogICAgICAgIHNfd2luZG93ID0gc3RhdGUud2luZG93OwogICAgICAgIGhvbGQgPSBzdGF0ZS5ob2xkOwogICAgICAgIGJpdHMgPSBzdGF0ZS5iaXRzOwogICAgICAgIGxjb2RlID0gc3RhdGUubGVuY29kZTsKICAgICAgICBkY29kZSA9IHN0YXRlLmRpc3Rjb2RlOwogICAgICAgIGxtYXNrID0gKDEgPDwgc3RhdGUubGVuYml0cykgLSAxOwogICAgICAgIGRtYXNrID0gKDEgPDwgc3RhdGUuZGlzdGJpdHMpIC0gMTsKICAgICAgICB0b3A6CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGlmIChiaXRzIDwgMTUpIHsKICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZXJlID0gbGNvZGVbaG9sZCAmIGxtYXNrXTsKICAgICAgICAgICAgZG9sZW46CiAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICBpZiAob3AgPT09IDApIHsKICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKG9wICYgMTYpIHsKICAgICAgICAgICAgICAgICAgbGVuID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICBvcCAmPSAxNTsKICAgICAgICAgICAgICAgICAgaWYgKG9wKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgbGVuICs9IGhvbGQgJiAoMSA8PCBvcCkgLSAxOwogICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgMTUpIHsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoZXJlID0gZGNvZGVbaG9sZCAmIGRtYXNrXTsKICAgICAgICAgICAgICAgICAgZG9kaXN0OgogICAgICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAyNDsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgICAgaWYgKG9wICYgMTYpIHsKICAgICAgICAgICAgICAgICAgICAgICAgZGlzdCA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgICAgICAgb3AgJj0gMTU7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBkaXN0ICs9IGhvbGQgJiAoMSA8PCBvcCkgLSAxOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZGlzdCA+IGRtYXgpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICBvcCA9IF9vdXQgLSBiZWc7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkaXN0ID4gb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBvcCA9IGRpc3QgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPiB3aGF2ZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLnNhbmUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2siOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSAwOwogICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gc193aW5kb3c7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHduZXh0ID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tICs9IHdzaXplIC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHduZXh0IDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gKz0gd3NpemUgKyB3bmV4dCAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3AgLT0gd25leHQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IDA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh3bmV4dCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9wID0gd25leHQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSArPSB3bmV4dCAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wIDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIHdoaWxlIChsZW4gPiAyKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gMzsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbiA+IDEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IDM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAobGVuID4gMik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4gPiAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKChvcCAmIDY0KSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICBoZXJlID0gZGNvZGVbKGhlcmUgJiA2NTUzNSkgKyAoaG9sZCAmICgxIDw8IG9wKSAtIDEpXTsKICAgICAgICAgICAgICAgICAgICAgICAgY29udGludWUgZG9kaXN0OwogICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSBjb2RlIjsKICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIGlmICgob3AgJiA2NCkgPT09IDApIHsKICAgICAgICAgICAgICAgICAgaGVyZSA9IGxjb2RlWyhoZXJlICYgNjU1MzUpICsgKGhvbGQgJiAoMSA8PCBvcCkgLSAxKV07CiAgICAgICAgICAgICAgICAgIGNvbnRpbnVlIGRvbGVuOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChvcCAmIDMyKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFOwogICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGxpdGVyYWwvbGVuZ3RoIGNvZGUiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICB9IHdoaWxlIChfaW4gPCBsYXN0ICYmIF9vdXQgPCBlbmQpOwogICAgICAgIGxlbiA9IGJpdHMgPj4gMzsKICAgICAgICBfaW4gLT0gbGVuOwogICAgICAgIGJpdHMgLT0gbGVuIDw8IDM7CiAgICAgICAgaG9sZCAmPSAoMSA8PCBiaXRzKSAtIDE7CiAgICAgICAgc3RybS5uZXh0X2luID0gX2luOwogICAgICAgIHN0cm0ubmV4dF9vdXQgPSBfb3V0OwogICAgICAgIHN0cm0uYXZhaWxfaW4gPSBfaW4gPCBsYXN0ID8gNSArIChsYXN0IC0gX2luKSA6IDUgLSAoX2luIC0gbGFzdCk7CiAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBfb3V0IDwgZW5kID8gMjU3ICsgKGVuZCAtIF9vdXQpIDogMjU3IC0gKF9vdXQgLSBlbmQpOwogICAgICAgIHN0YXRlLmhvbGQgPSBob2xkOwogICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzOwogICAgICAgIHJldHVybjsKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZnRyZWVzLmpzCiAgdmFyIHJlcXVpcmVfaW5mdHJlZXMgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mdHJlZXMuanMiKGV4cG9ydHMsIG1vZHVsZSkgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24yKCk7CiAgICAgIHZhciBNQVhCSVRTID0gMTU7CiAgICAgIHZhciBFTk9VR0hfTEVOUyA9IDg1MjsKICAgICAgdmFyIEVOT1VHSF9ESVNUUyA9IDU5MjsKICAgICAgdmFyIENPREVTID0gMDsKICAgICAgdmFyIExFTlMgPSAxOwogICAgICB2YXIgRElTVFMgPSAyOwogICAgICB2YXIgbGJhc2UgPSBbCiAgICAgICAgMywKICAgICAgICA0LAogICAgICAgIDUsCiAgICAgICAgNiwKICAgICAgICA3LAogICAgICAgIDgsCiAgICAgICAgOSwKICAgICAgICAxMCwKICAgICAgICAxMSwKICAgICAgICAxMywKICAgICAgICAxNSwKICAgICAgICAxNywKICAgICAgICAxOSwKICAgICAgICAyMywKICAgICAgICAyNywKICAgICAgICAzMSwKICAgICAgICAzNSwKICAgICAgICA0MywKICAgICAgICA1MSwKICAgICAgICA1OSwKICAgICAgICA2NywKICAgICAgICA4MywKICAgICAgICA5OSwKICAgICAgICAxMTUsCiAgICAgICAgMTMxLAogICAgICAgIDE2MywKICAgICAgICAxOTUsCiAgICAgICAgMjI3LAogICAgICAgIDI1OCwKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGxleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMTYsCiAgICAgICAgNzIsCiAgICAgICAgNzgKICAgICAgXTsKICAgICAgdmFyIGRiYXNlID0gWwogICAgICAgIDEsCiAgICAgICAgMiwKICAgICAgICAzLAogICAgICAgIDQsCiAgICAgICAgNSwKICAgICAgICA3LAogICAgICAgIDksCiAgICAgICAgMTMsCiAgICAgICAgMTcsCiAgICAgICAgMjUsCiAgICAgICAgMzMsCiAgICAgICAgNDksCiAgICAgICAgNjUsCiAgICAgICAgOTcsCiAgICAgICAgMTI5LAogICAgICAgIDE5MywKICAgICAgICAyNTcsCiAgICAgICAgMzg1LAogICAgICAgIDUxMywKICAgICAgICA3NjksCiAgICAgICAgMTAyNSwKICAgICAgICAxNTM3LAogICAgICAgIDIwNDksCiAgICAgICAgMzA3MywKICAgICAgICA0MDk3LAogICAgICAgIDYxNDUsCiAgICAgICAgODE5MywKICAgICAgICAxMjI4OSwKICAgICAgICAxNjM4NSwKICAgICAgICAyNDU3NywKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGRleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjIsCiAgICAgICAgMjIsCiAgICAgICAgMjMsCiAgICAgICAgMjMsCiAgICAgICAgMjQsCiAgICAgICAgMjQsCiAgICAgICAgMjUsCiAgICAgICAgMjUsCiAgICAgICAgMjYsCiAgICAgICAgMjYsCiAgICAgICAgMjcsCiAgICAgICAgMjcsCiAgICAgICAgMjgsCiAgICAgICAgMjgsCiAgICAgICAgMjksCiAgICAgICAgMjksCiAgICAgICAgNjQsCiAgICAgICAgNjQKICAgICAgXTsKICAgICAgbW9kdWxlLmV4cG9ydHMgPSBmdW5jdGlvbiBpbmZsYXRlX3RhYmxlKHR5cGUsIGxlbnMsIGxlbnNfaW5kZXgsIGNvZGVzLCB0YWJsZSwgdGFibGVfaW5kZXgsIHdvcmssIG9wdHMpIHsKICAgICAgICB2YXIgYml0cyA9IG9wdHMuYml0czsKICAgICAgICB2YXIgbGVuID0gMDsKICAgICAgICB2YXIgc3ltID0gMDsKICAgICAgICB2YXIgbWluID0gMCwgbWF4ID0gMDsKICAgICAgICB2YXIgcm9vdCA9IDA7CiAgICAgICAgdmFyIGN1cnIgPSAwOwogICAgICAgIHZhciBkcm9wID0gMDsKICAgICAgICB2YXIgbGVmdCA9IDA7CiAgICAgICAgdmFyIHVzZWQgPSAwOwogICAgICAgIHZhciBodWZmID0gMDsKICAgICAgICB2YXIgaW5jcjsKICAgICAgICB2YXIgZmlsbDsKICAgICAgICB2YXIgbG93OwogICAgICAgIHZhciBtYXNrOwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBiYXNlID0gbnVsbDsKICAgICAgICB2YXIgYmFzZV9pbmRleCA9IDA7CiAgICAgICAgdmFyIGVuZDsKICAgICAgICB2YXIgY291bnQgPSBuZXcgdXRpbHMuQnVmMTYoTUFYQklUUyArIDEpOwogICAgICAgIHZhciBvZmZzID0gbmV3IHV0aWxzLkJ1ZjE2KE1BWEJJVFMgKyAxKTsKICAgICAgICB2YXIgZXh0cmEgPSBudWxsOwogICAgICAgIHZhciBleHRyYV9pbmRleCA9IDA7CiAgICAgICAgdmFyIGhlcmVfYml0cywgaGVyZV9vcCwgaGVyZV92YWw7CiAgICAgICAgZm9yIChsZW4gPSAwOyBsZW4gPD0gTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIGNvdW50W2xlbl0gPSAwOwogICAgICAgIH0KICAgICAgICBmb3IgKHN5bSA9IDA7IHN5bSA8IGNvZGVzOyBzeW0rKykgewogICAgICAgICAgY291bnRbbGVuc1tsZW5zX2luZGV4ICsgc3ltXV0rKzsKICAgICAgICB9CiAgICAgICAgcm9vdCA9IGJpdHM7CiAgICAgICAgZm9yIChtYXggPSBNQVhCSVRTOyBtYXggPj0gMTsgbWF4LS0pIHsKICAgICAgICAgIGlmIChjb3VudFttYXhdICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocm9vdCA+IG1heCkgewogICAgICAgICAgcm9vdCA9IG1heDsKICAgICAgICB9CiAgICAgICAgaWYgKG1heCA9PT0gMCkgewogICAgICAgICAgdGFibGVbdGFibGVfaW5kZXgrK10gPSAxIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgICAgdGFibGVbdGFibGVfaW5kZXgrK10gPSAxIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgICAgb3B0cy5iaXRzID0gMTsKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICBmb3IgKG1pbiA9IDE7IG1pbiA8IG1heDsgbWluKyspIHsKICAgICAgICAgIGlmIChjb3VudFttaW5dICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocm9vdCA8IG1pbikgewogICAgICAgICAgcm9vdCA9IG1pbjsKICAgICAgICB9CiAgICAgICAgbGVmdCA9IDE7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPD0gTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIGxlZnQgPDw9IDE7CiAgICAgICAgICBsZWZ0IC09IGNvdW50W2xlbl07CiAgICAgICAgICBpZiAobGVmdCA8IDApIHsKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAobGVmdCA+IDAgJiYgKHR5cGUgPT09IENPREVTIHx8IG1heCAhPT0gMSkpIHsKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgb2Zmc1sxXSA9IDA7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPCBNQVhCSVRTOyBsZW4rKykgewogICAgICAgICAgb2Zmc1tsZW4gKyAxXSA9IG9mZnNbbGVuXSArIGNvdW50W2xlbl07CiAgICAgICAgfQogICAgICAgIGZvciAoc3ltID0gMDsgc3ltIDwgY29kZXM7IHN5bSsrKSB7CiAgICAgICAgICBpZiAobGVuc1tsZW5zX2luZGV4ICsgc3ltXSAhPT0gMCkgewogICAgICAgICAgICB3b3JrW29mZnNbbGVuc1tsZW5zX2luZGV4ICsgc3ltXV0rK10gPSBzeW07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlID09PSBDT0RFUykgewogICAgICAgICAgYmFzZSA9IGV4dHJhID0gd29yazsKICAgICAgICAgIGVuZCA9IDE5OwogICAgICAgIH0gZWxzZSBpZiAodHlwZSA9PT0gTEVOUykgewogICAgICAgICAgYmFzZSA9IGxiYXNlOwogICAgICAgICAgYmFzZV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBleHRyYSA9IGxleHQ7CiAgICAgICAgICBleHRyYV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBlbmQgPSAyNTY7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGJhc2UgPSBkYmFzZTsKICAgICAgICAgIGV4dHJhID0gZGV4dDsKICAgICAgICAgIGVuZCA9IC0xOwogICAgICAgIH0KICAgICAgICBodWZmID0gMDsKICAgICAgICBzeW0gPSAwOwogICAgICAgIGxlbiA9IG1pbjsKICAgICAgICBuZXh0ID0gdGFibGVfaW5kZXg7CiAgICAgICAgY3VyciA9IHJvb3Q7CiAgICAgICAgZHJvcCA9IDA7CiAgICAgICAgbG93ID0gLTE7CiAgICAgICAgdXNlZCA9IDEgPDwgcm9vdDsKICAgICAgICBtYXNrID0gdXNlZCAtIDE7CiAgICAgICAgaWYgKHR5cGUgPT09IExFTlMgJiYgdXNlZCA+IEVOT1VHSF9MRU5TIHx8IHR5cGUgPT09IERJU1RTICYmIHVzZWQgPiBFTk9VR0hfRElTVFMpIHsKICAgICAgICAgIHJldHVybiAxOwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGhlcmVfYml0cyA9IGxlbiAtIGRyb3A7CiAgICAgICAgICBpZiAod29ya1tzeW1dIDwgZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAwOwogICAgICAgICAgICBoZXJlX3ZhbCA9IHdvcmtbc3ltXTsKICAgICAgICAgIH0gZWxzZSBpZiAod29ya1tzeW1dID4gZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSBleHRyYVtleHRyYV9pbmRleCArIHdvcmtbc3ltXV07CiAgICAgICAgICAgIGhlcmVfdmFsID0gYmFzZVtiYXNlX2luZGV4ICsgd29ya1tzeW1dXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAzMiArIDY0OwogICAgICAgICAgICBoZXJlX3ZhbCA9IDA7CiAgICAgICAgICB9CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSBkcm9wOwogICAgICAgICAgZmlsbCA9IDEgPDwgY3VycjsKICAgICAgICAgIG1pbiA9IGZpbGw7CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGZpbGwgLT0gaW5jcjsKICAgICAgICAgICAgdGFibGVbbmV4dCArIChodWZmID4+IGRyb3ApICsgZmlsbF0gPSBoZXJlX2JpdHMgPDwgMjQgfCBoZXJlX29wIDw8IDE2IHwgaGVyZV92YWwgfCAwOwogICAgICAgICAgfSB3aGlsZSAoZmlsbCAhPT0gMCk7CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSAxOwogICAgICAgICAgd2hpbGUgKGh1ZmYgJiBpbmNyKSB7CiAgICAgICAgICAgIGluY3IgPj49IDE7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaW5jciAhPT0gMCkgewogICAgICAgICAgICBodWZmICY9IGluY3IgLSAxOwogICAgICAgICAgICBodWZmICs9IGluY3I7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBodWZmID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHN5bSsrOwogICAgICAgICAgaWYgKC0tY291bnRbbGVuXSA9PT0gMCkgewogICAgICAgICAgICBpZiAobGVuID09PSBtYXgpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBsZW4gPSBsZW5zW2xlbnNfaW5kZXggKyB3b3JrW3N5bV1dOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGxlbiA+IHJvb3QgJiYgKGh1ZmYgJiBtYXNrKSAhPT0gbG93KSB7CiAgICAgICAgICAgIGlmIChkcm9wID09PSAwKSB7CiAgICAgICAgICAgICAgZHJvcCA9IHJvb3Q7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbmV4dCArPSBtaW47CiAgICAgICAgICAgIGN1cnIgPSBsZW4gLSBkcm9wOwogICAgICAgICAgICBsZWZ0ID0gMSA8PCBjdXJyOwogICAgICAgICAgICB3aGlsZSAoY3VyciArIGRyb3AgPCBtYXgpIHsKICAgICAgICAgICAgICBsZWZ0IC09IGNvdW50W2N1cnIgKyBkcm9wXTsKICAgICAgICAgICAgICBpZiAobGVmdCA8PSAwKSB7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgY3VycisrOwogICAgICAgICAgICAgIGxlZnQgPDw9IDE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdXNlZCArPSAxIDw8IGN1cnI7CiAgICAgICAgICAgIGlmICh0eXBlID09PSBMRU5TICYmIHVzZWQgPiBFTk9VR0hfTEVOUyB8fCB0eXBlID09PSBESVNUUyAmJiB1c2VkID4gRU5PVUdIX0RJU1RTKSB7CiAgICAgICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbG93ID0gaHVmZiAmIG1hc2s7CiAgICAgICAgICAgIHRhYmxlW2xvd10gPSByb290IDw8IDI0IHwgY3VyciA8PCAxNiB8IG5leHQgLSB0YWJsZV9pbmRleCB8IDA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChodWZmICE9PSAwKSB7CiAgICAgICAgICB0YWJsZVtuZXh0ICsgaHVmZl0gPSBsZW4gLSBkcm9wIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgIH0KICAgICAgICBvcHRzLmJpdHMgPSByb290OwogICAgICAgIHJldHVybiAwOwogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mbGF0ZS5qcwogIHZhciByZXF1aXJlX2luZmxhdGUgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mbGF0ZS5qcyIoZXhwb3J0cykgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24yKCk7CiAgICAgIHZhciBhZGxlcjMyID0gcmVxdWlyZV9hZGxlcjMyKCk7CiAgICAgIHZhciBjcmMzMjIgPSByZXF1aXJlX2NyYzMyKCk7CiAgICAgIHZhciBpbmZsYXRlX2Zhc3QgPSByZXF1aXJlX2luZmZhc3QoKTsKICAgICAgdmFyIGluZmxhdGVfdGFibGUgPSByZXF1aXJlX2luZnRyZWVzKCk7CiAgICAgIHZhciBDT0RFUyA9IDA7CiAgICAgIHZhciBMRU5TID0gMTsKICAgICAgdmFyIERJU1RTID0gMjsKICAgICAgdmFyIFpfRklOSVNIID0gNDsKICAgICAgdmFyIFpfQkxPQ0sgPSA1OwogICAgICB2YXIgWl9UUkVFUyA9IDY7CiAgICAgIHZhciBaX09LID0gMDsKICAgICAgdmFyIFpfU1RSRUFNX0VORCA9IDE7CiAgICAgIHZhciBaX05FRURfRElDVCA9IDI7CiAgICAgIHZhciBaX1NUUkVBTV9FUlJPUiA9IC0yOwogICAgICB2YXIgWl9EQVRBX0VSUk9SID0gLTM7CiAgICAgIHZhciBaX01FTV9FUlJPUiA9IC00OwogICAgICB2YXIgWl9CVUZfRVJST1IgPSAtNTsKICAgICAgdmFyIFpfREVGTEFURUQgPSA4OwogICAgICB2YXIgSEVBRCA9IDE7CiAgICAgIHZhciBGTEFHUyA9IDI7CiAgICAgIHZhciBUSU1FID0gMzsKICAgICAgdmFyIE9TID0gNDsKICAgICAgdmFyIEVYTEVOID0gNTsKICAgICAgdmFyIEVYVFJBID0gNjsKICAgICAgdmFyIE5BTUUgPSA3OwogICAgICB2YXIgQ09NTUVOVCA9IDg7CiAgICAgIHZhciBIQ1JDID0gOTsKICAgICAgdmFyIERJQ1RJRCA9IDEwOwogICAgICB2YXIgRElDVCA9IDExOwogICAgICB2YXIgVFlQRSA9IDEyOwogICAgICB2YXIgVFlQRURPID0gMTM7CiAgICAgIHZhciBTVE9SRUQgPSAxNDsKICAgICAgdmFyIENPUFlfID0gMTU7CiAgICAgIHZhciBDT1BZID0gMTY7CiAgICAgIHZhciBUQUJMRSA9IDE3OwogICAgICB2YXIgTEVOTEVOUyA9IDE4OwogICAgICB2YXIgQ09ERUxFTlMgPSAxOTsKICAgICAgdmFyIExFTl8gPSAyMDsKICAgICAgdmFyIExFTiA9IDIxOwogICAgICB2YXIgTEVORVhUID0gMjI7CiAgICAgIHZhciBESVNUID0gMjM7CiAgICAgIHZhciBESVNURVhUID0gMjQ7CiAgICAgIHZhciBNQVRDSCA9IDI1OwogICAgICB2YXIgTElUID0gMjY7CiAgICAgIHZhciBDSEVDSyA9IDI3OwogICAgICB2YXIgTEVOR1RIID0gMjg7CiAgICAgIHZhciBET05FID0gMjk7CiAgICAgIHZhciBCQUQgPSAzMDsKICAgICAgdmFyIE1FTSA9IDMxOwogICAgICB2YXIgU1lOQyA9IDMyOwogICAgICB2YXIgRU5PVUdIX0xFTlMgPSA4NTI7CiAgICAgIHZhciBFTk9VR0hfRElTVFMgPSA1OTI7CiAgICAgIHZhciBNQVhfV0JJVFMgPSAxNTsKICAgICAgdmFyIERFRl9XQklUUyA9IE1BWF9XQklUUzsKICAgICAgZnVuY3Rpb24genN3YXAzMihxKSB7CiAgICAgICAgcmV0dXJuIChxID4+PiAyNCAmIDI1NSkgKyAocSA+Pj4gOCAmIDY1MjgwKSArICgocSAmIDY1MjgwKSA8PCA4KSArICgocSAmIDI1NSkgPDwgMjQpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIEluZmxhdGVTdGF0ZSgpIHsKICAgICAgICB0aGlzLm1vZGUgPSAwOwogICAgICAgIHRoaXMubGFzdCA9IGZhbHNlOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5oYXZlZGljdCA9IGZhbHNlOwogICAgICAgIHRoaXMuZmxhZ3MgPSAwOwogICAgICAgIHRoaXMuZG1heCA9IDA7CiAgICAgICAgdGhpcy5jaGVjayA9IDA7CiAgICAgICAgdGhpcy50b3RhbCA9IDA7CiAgICAgICAgdGhpcy5oZWFkID0gbnVsbDsKICAgICAgICB0aGlzLndiaXRzID0gMDsKICAgICAgICB0aGlzLndzaXplID0gMDsKICAgICAgICB0aGlzLndoYXZlID0gMDsKICAgICAgICB0aGlzLnduZXh0ID0gMDsKICAgICAgICB0aGlzLndpbmRvdyA9IG51bGw7CiAgICAgICAgdGhpcy5ob2xkID0gMDsKICAgICAgICB0aGlzLmJpdHMgPSAwOwogICAgICAgIHRoaXMubGVuZ3RoID0gMDsKICAgICAgICB0aGlzLm9mZnNldCA9IDA7CiAgICAgICAgdGhpcy5leHRyYSA9IDA7CiAgICAgICAgdGhpcy5sZW5jb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmRpc3Rjb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmxlbmJpdHMgPSAwOwogICAgICAgIHRoaXMuZGlzdGJpdHMgPSAwOwogICAgICAgIHRoaXMubmNvZGUgPSAwOwogICAgICAgIHRoaXMubmxlbiA9IDA7CiAgICAgICAgdGhpcy5uZGlzdCA9IDA7CiAgICAgICAgdGhpcy5oYXZlID0gMDsKICAgICAgICB0aGlzLm5leHQgPSBudWxsOwogICAgICAgIHRoaXMubGVucyA9IG5ldyB1dGlscy5CdWYxNigzMjApOwogICAgICAgIHRoaXMud29yayA9IG5ldyB1dGlscy5CdWYxNigyODgpOwogICAgICAgIHRoaXMubGVuZHluID0gbnVsbDsKICAgICAgICB0aGlzLmRpc3RkeW4gPSBudWxsOwogICAgICAgIHRoaXMuc2FuZSA9IDA7CiAgICAgICAgdGhpcy5iYWNrID0gMDsKICAgICAgICB0aGlzLndhcyA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZVJlc2V0S2VlcChzdHJtKSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgc3RybS50b3RhbF9pbiA9IHN0cm0udG90YWxfb3V0ID0gc3RhdGUudG90YWwgPSAwOwogICAgICAgIHN0cm0ubXNnID0gIiI7CiAgICAgICAgaWYgKHN0YXRlLndyYXApIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS53cmFwICYgMTsKICAgICAgICB9CiAgICAgICAgc3RhdGUubW9kZSA9I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ogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAod2luZG93Qml0cyA8IDApIHsKICAgICAgICAgIHdyYXAgPSAwOwogICAgICAgICAgd2luZG93Qml0cyA9IC13aW5kb3dCaXRzOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB3cmFwID0gKHdpbmRvd0JpdHMgPj4gNCkgKyAxOwogICAgICAgICAgaWYgKHdpbmRvd0JpdHMgPCA0OCkgewogICAgICAgICAgICB3aW5kb3dCaXRzICY9IDE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyAmJiAod2luZG93Qml0cyA8IDggfHwgd2luZG93Qml0cyA+IDE1KSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhdGUud2luZG93ICE9PSBudWxsICYmIHN0YXRlLndiaXRzICE9PSB3aW5kb3dCaXRzKSB7CiAgICAgICAgICBzdGF0ZS53aW5kb3cgPSBudWxsOwogICAgICAgIH0KICAgICAgICBzdGF0ZS53cmFwID0gd3JhcDsKICAgICAgICBzdGF0ZS53Yml0cyA9IHdpbmRvd0JpdHM7CiAgICAgICAgcmV0dXJuIGluZmxhdGVSZXNldChzdHJtKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlSW5pdDIoc3RybSwgd2luZG93Qml0cykgewogICAgICAgIHZhciByZXQ7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIGlmICghc3RybSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IG5ldyBJbmZsYXRlU3RhdGUoKTsKICAgICAgICBzdHJtLnN0YXRlID0gc3RhdGU7CiAgICAgICAgc3RhdGUud2luZG93ID0gbnVsbDsKICAgICAgICByZXQgPSBpbmZsYXRlUmVzZXQyKHN0cm0sIHdpbmRvd0JpdHMpOwogICAgICAgIGlmIChyZXQgIT09IFpfT0spIHsKICAgICAgICAgIHN0cm0uc3RhdGUgPSBudWxsOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmV0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVJbml0KHN0cm0pIHsKICAgICAgICByZXR1cm4gaW5mbGF0ZUluaXQyKHN0cm0sIERFRl9XQklUUyk7CiAgICAgIH0KICAgICAgdmFyIHZpcmdpbiA9IHRydWU7CiAgICAgIHZhciBsZW5maXg7CiAgICAgIHZhciBkaXN0Zml4OwogICAgICBmdW5jdGlvbiBmaXhlZHRhYmxlcyhzdGF0ZSkgewogICAgICAgIGlmICh2aXJnaW4pIHsKICAgICAgICAgIHZhciBzeW07CiAgICAgICAgICBsZW5maXggPSBuZXcgdXRpbHMuQnVmMzIoNTEyKTsKICAgICAgICAgIGRpc3RmaXggPSBuZXcgdXRpbHMuQnVmMzIoMzIpOwogICAgICAgICAgc3ltID0gMDsKICAgICAgICAgIHdoaWxlIChzeW0gPCAxNDQpIHsKICAgICAgICAgICAgc3RhdGUubGVuc1tzeW0rK10gPSA4OwogICAgICAgICAgfQogICAgICAgICAgd2hpbGUgKHN5bSA8IDI1NikgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDk7CiAgICAgICAgICB9CiAgICAgICAgICB3aGlsZSAoc3ltIDwgMjgwKSB7CiAgICAgICAgICAgIHN0YXRlLmxlbnNbc3ltKytdID0gNzsKICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzeW0gPCAyODgpIHsKICAgICAgICAgICAgc3RhdGUubGVuc1tzeW0rK10gPSA4OwogICAgICAgICAgfQogICAgICAgICAgaW5mbGF0ZV90YWJsZShMRU5TLCBzdGF0ZS5sZW5zLCAwLCAyODgsIGxlbmZpeCwgMCwgc3RhdGUud29yaywgeyBiaXRzOiA5IH0pOwogICAgICAgICAgc3ltID0gMDsKICAgICAgICAgIHdoaWxlIChzeW0gPCAzMikgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDU7CiAgICAgICAgICB9CiAgICAgICAgICBpbmZsYXRlX3RhYmxlKERJU1RTLCBzdGF0ZS5sZW5zLCAwLCAzMiwgZGlzdGZpeCwgMCwgc3RhdGUud29yaywgeyBiaXRzOiA1IH0pOwogICAgICAgICAgdmlyZ2luID0gZmFsc2U7CiAgICAgICAgfQogICAgICAgIHN0YXRlLmxlbmNvZGUgPSBsZW5maXg7CiAgICAgICAgc3RhdGUubGVuYml0cyA9IDk7CiAgICAgICAgc3RhdGUuZGlzdGNvZGUgPSBkaXN0Zml4OwogICAgICAgIHN0YXRlLmRpc3RiaXRzID0gNTsKICAgICAgfQogICAgICBmdW5jdGlvbiB1cGRhdGV3aW5kb3coc3RybSwgc3JjLCBlbmQsIGNvcHkpIHsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS53aW5kb3cgPT09IG51bGwpIHsKICAgICAgICAgIHN0YXRlLndzaXplID0gMSA8PCBzdGF0ZS53Yml0czsKICAgICAgICAgIHN0YXRlLnduZXh0ID0gMDsKICAgICAgICAgIHN0YXRlLndoYXZlID0gMDsKICAgICAgICAgIHN0YXRlLndpbmRvdyA9IG5ldyB1dGlscy5CdWY4KHN0YXRlLndzaXplKTsKICAgICAgICB9CiAgICAgICAgaWYgKGNvcHkgPj0gc3RhdGUud3NpemUpIHsKICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHN0YXRlLndpbmRvdywgc3JjLCBlbmQgLSBzdGF0ZS53c2l6ZSwgc3RhdGUud3NpemUsIDApOwogICAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgICAgc3RhdGUud2hhdmUgPSBzdGF0ZS53c2l6ZTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGlzdCA9IHN0YXRlLndzaXplIC0gc3RhdGUud25leHQ7CiAgICAgICAgICBpZiAoZGlzdCA+IGNvcHkpIHsKICAgICAgICAgICAgZGlzdCA9IGNvcHk7CiAgICAgICAgICB9CiAgICAgICAgICB1dGlscy5hcnJheVNldChzdGF0ZS53aW5kb3csIHNyYywgZW5kIC0gY29weSwgZGlzdCwgc3RhdGUud25leHQpOwogICAgICAgICAgY29weSAtPSBkaXN0OwogICAgICAgICAgaWYgKGNvcHkpIHsKICAgICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RhdGUud2luZG93LCBzcmMsIGVuZCAtIGNvcHksIGNvcHksIDApOwogICAgICAgICAgICBzdGF0ZS53bmV4dCA9IGNvcHk7CiAgICAgICAgICAgIHN0YXRlLndoYXZlID0gc3RhdGUud3NpemU7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzdGF0ZS53bmV4dCArPSBkaXN0OwogICAgICAgICAgICBpZiAoc3RhdGUud25leHQgPT09IHN0YXRlLndzaXplKSB7CiAgICAgICAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzdGF0ZS53aGF2ZSA8IHN0YXRlLndzaXplKSB7CiAgICAgICAgICAgICAgc3RhdGUud2hhdmUgKz0gZGlzdDsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlKHN0cm0sIGZsdXNoKSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIHZhciBpbnB1dCwgb3V0cHV0OwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBwdXQ7CiAgICAgICAgdmFyIGhhdmUsIGxlZnQ7CiAgICAgICAgdmFyIGhvbGQ7CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIF9pbiwgX291dDsKICAgICAgICB2YXIgY29weTsKICAgICAgICB2YXIgZnJvbTsKICAgICAgICB2YXIgZnJvbV9zb3VyY2U7CiAgICAgICAgdmFyIGhlcmUgPSAwOwogICAgICAgIHZhciBoZXJlX2JpdHMsIGhlcmVfb3AsIGhlcmVfdmFsOwogICAgICAgIHZhciBsYXN0X2JpdHMsIGxhc3Rfb3AsIGxhc3RfdmFsOwogICAgICAgIHZhciBsZW47CiAgICAgICAgdmFyIHJldDsKICAgICAgICB2YXIgaGJ1ZiA9IG5ldyB1dGlscy5CdWY4KDQpOwogICAgICAgIHZhciBvcHRzOwogICAgICAgIHZhciBuOwogICAgICAgIHZhciBvcmRlciA9IFsxNiwgMTcsIDE4LCAwLCA4LCA3LCA5LCA2LCAxMCwgNSwgMTEsIDQsIDEyLCAzLCAxMywgMiwgMTQsIDEsIDE1XTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUgfHwgIXN0cm0ub3V0cHV0IHx8ICFzdHJtLmlucHV0ICYmIHN0cm0uYXZhaWxfaW4gIT09IDApIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS5tb2RlID09PSBUWVBFKSB7CiAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRURPOwogICAgICAgIH0KICAgICAgICBwdXQgPSBzdHJtLm5leHRfb3V0OwogICAgICAgIG91dHB1dCA9IHN0cm0ub3V0cHV0OwogICAgICAgIGxlZnQgPSBzdHJtLmF2YWlsX291dDsKICAgICAgICBuZXh0ID0gc3RybS5uZXh0X2luOwogICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICBoYXZlID0gc3RybS5hdmFpbF9pbjsKICAgICAgICBob2xkID0gc3RhdGUuaG9sZDsKICAgICAgICBiaXRzID0gc3RhdGUuYml0czsKICAgICAgICBfaW4gPSBoYXZlOwogICAgICAgIF9vdXQgPSBsZWZ0OwogICAgICAgIHJldCA9IFpfT0s7CiAgICAgICAgaW5mX2xlYXZlOgogICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgIHN3aXRjaCAoc3RhdGUubW9kZSkgewogICAgICAgICAgICAgIGNhc2UgSEVBRDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFRE87CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUud3JhcCAmIDIgJiYgaG9sZCA9PT0gMzU2MTUpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSAwOwogICAgICAgICAgICAgICAgICBoYnVmWzBdID0gaG9sZCAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlsxXSA9IGhvbGQgPj4+IDggJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIyKHN0YXRlLmNoZWNrLCBoYnVmLCAyLCAwKTsKICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gRkxBR1M7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZmxhZ3MgPSAwOwogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5kb25lID0gZmFsc2U7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoIShzdGF0ZS53cmFwICYgMSkgfHwgKCgoaG9sZCAmIDI1NSkgPDwgOCkgKyAoaG9sZCA+PiA4KSkgJSAzMSkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbmNvcnJlY3QgaGVhZGVyIGNoZWNrIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoKGhvbGQgJiAxNSkgIT09IFpfREVGTEFURUQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAidW5rbm93biBjb21wcmVzc2lvbiBtZXRob2QiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA0OwogICAgICAgICAgICAgICAgYml0cyAtPSA0OwogICAgICAgICAgICAgICAgbGVuID0gKGhvbGQgJiAxNSkgKyA4OwogICAgICAgICAgICAgICAgaWYgKHN0YXRlLndiaXRzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLndiaXRzID0gbGVuOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChsZW4gPiBzdGF0ZS53Yml0cykgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIHdpbmRvdyBzaXplIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5kbWF4ID0gMSA8PCBsZW47CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSAxOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IGhvbGQgJiA1MTIgPyBESUNUSUQgOiBUWVBFOwogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgRkxBR1M6CiAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmZsYWdzID0gaG9sZDsKICAgICAgICAgICAgICAgIGlmICgoc3RhdGUuZmxhZ3MgJiAyNTUpICE9PSBaX0RFRkxBVEVEKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gInVua25vd24gY29tcHJlc3Npb24gbWV0aG9kIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1NzM0NCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJ1bmtub3duIGhlYWRlciBmbGFncyBzZXQiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQudGV4dCA9IGhvbGQgPj4gOCAmIDE7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1MTIpIHsKICAgICAgICAgICAgICAgICAgaGJ1ZlswXSA9IGhvbGQgJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhidWZbMV0gPSBob2xkID4+PiA4ICYgMjU1OwogICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IGNyYzMyMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRJTUU7CiAgICAgICAgICAgICAgY2FzZSBUSU1FOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLnRpbWUgPSBob2xkOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlsyXSA9IGhvbGQgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzNdID0gaG9sZCA+Pj4gMjQgJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIyKHN0YXRlLmNoZWNrLCBoYnVmLCA0LCAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gT1M7CiAgICAgICAgICAgICAgY2FzZSBPUzoKICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMTYpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC54ZmxhZ3MgPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLm9zID0gaG9sZCA+PiA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMjIoc3RhdGUuY2hlY2ssIGhidWYsIDIsIDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBFWExFTjsKICAgICAgICAgICAgICBjYXNlIEVYTEVOOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgMTAyNCkgewogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSBob2xkOwogICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZXh0cmFfbGVuID0gaG9sZDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1MTIpIHsKICAgICAgICAgICAgICAgICAgICBoYnVmWzBdID0gaG9sZCAmIDI1NTsKICAgICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IGNyYzMyMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZXh0cmEgPSBudWxsOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEVYVFJBOwogICAgICAgICAgICAgIGNhc2UgRVhUUkE6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiAxMDI0KSB7CiAgICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gaGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBoYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IHN0YXRlLmhlYWQuZXh0cmFfbGVuIC0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgICAgICAgaWYgKCFzdGF0ZS5oZWFkLmV4dHJhKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZXh0cmEgPSBuZXcgQXJyYXkoc3RhdGUuaGVhZC5leHRyYV9sZW4pOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RhdGUuaGVhZC5leHRyYSwgaW5wdXQsIG5leHQsIGNvcHksIGxlbik7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMjIoc3RhdGUuY2hlY2ssIGlucHV0LCBjb3B5LCBuZXh0KTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZSAtPSBjb3B5OwogICAgICAgICAgICAgICAgICAgIG5leHQgKz0gY29weTsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoc3RhdGUubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IE5BTUU7CiAgICAgICAgICAgICAgY2FzZSBOQU1FOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgMjA0OCkgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBjb3B5ID0gMDsKICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgIGxlbiA9IGlucHV0W25leHQgKyBjb3B5KytdOwogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkICYmIGxlbiAmJiBzdGF0ZS5sZW5ndGggPCA2NTUzNikgewogICAgICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5uYW1lICs9IFN0cmluZy5mcm9tQ2hhckNvZGUobGVuKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKGxlbiAmJiBjb3B5IDwgaGF2ZSk7CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIyKHN0YXRlLmNoZWNrLCBpbnB1dCwgY29weSwgbmV4dCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZSAtPSBjb3B5OwogICAgICAgICAgICAgICAgICBuZXh0ICs9IGNvcHk7CiAgICAgICAgICAgICAgICAgIGlmIChsZW4pIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLm5hbWUgPSBudWxsOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubGVuZ3RoID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBDT01NRU5UOwogICAgICAgICAgICAgIGNhc2UgQ09NTUVOVDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDQwOTYpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgY29weSA9IDA7CiAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICBsZW4gPSBpbnB1dFtuZXh0ICsgY29weSsrXTsKICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCAmJiBsZW4gJiYgc3RhdGUubGVuZ3RoIDwgNjU1MzYpIHsKICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuY29tbWVudCArPSBTdHJpbmcuZnJvbUNoYXJDb2RlKGxlbik7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9IHdoaWxlIChsZW4gJiYgY29weSA8IGhhdmUpOwogICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1MTIpIHsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IGNyYzMyMihzdGF0ZS5jaGVjaywgaW5wdXQsIGNvcHksIG5leHQpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUgLT0gY29weTsKICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5jb21tZW50ID0gbnVsbDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBIQ1JDOwogICAgICAgICAgICAgIGNhc2UgSENSQzoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoaG9sZCAhPT0gKHN0YXRlLmNoZWNrICYgNjU1MzUpKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaGVhZGVyIGNyYyBtaXNtYXRjaCI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmhjcmMgPSBzdGF0ZS5mbGFncyA+PiA5ICYgMTsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5kb25lID0gdHJ1ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgRElDVElEOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSB6c3dhcDMyKGhvbGQpOwogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBESUNUOwogICAgICAgICAgICAgIGNhc2UgRElDVDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oYXZlZGljdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gcHV0OwogICAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGxlZnQ7CiAgICAgICAgICAgICAgICAgIHN0cm0ubmV4dF9pbiA9IG5leHQ7CiAgICAgICAgICAgICAgICAgIHN0cm0uYXZhaWxfaW4gPSBoYXZlOwogICAgICAgICAgICAgICAgICBzdGF0ZS5ob2xkID0gaG9sZDsKICAgICAgICAgICAgICAgICAgc3RhdGUuYml0cyA9IGJpdHM7CiAgICAgICAgICAgICAgICAgIHJldHVybiBaX05FRURfRElDVDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IDE7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICBjYXNlIFRZUEU6CiAgICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfQkxPQ0sgfHwgZmx1c2ggPT09IFpfVFJFRVMpIHsKICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGNhc2UgVFlQRURPOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmxhc3QpIHsKICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgICBiaXRzIC09IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQ0hFQ0s7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzKSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxhc3QgPSBob2xkICYgMTsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAxOwogICAgICAgICAgICAgICAgYml0cyAtPSAxOwogICAgICAgICAgICAgICAgc3dpdGNoIChob2xkICYgMykgewogICAgICAgICAgICAgICAgICBjYXNlIDA6CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFNUT1JFRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgICAgICAgIGZpeGVkdGFibGVzKHN0YXRlKTsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOXzsKICAgICAgICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfVFJFRVMpIHsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAyOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSAyOwogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUQUJMRTsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAzOgogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYmxvY2sgdHlwZSI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAyOwogICAgICAgICAgICAgICAgYml0cyAtPSAyOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBTVE9SRUQ6CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gYml0cyAmIDc7CiAgICAgICAgICAgICAgICBiaXRzIC09IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoKGhvbGQgJiA2NTUzNSkgIT09IChob2xkID4+PiAxNiBeIDY1NTM1KSkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIHN0b3JlZCBibG9jayBsZW5ndGhzIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSBob2xkICYgNjU1MzU7CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENPUFlfOwogICAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX1RSRUVTKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBjYXNlIENPUFlfOgogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENPUFk7CiAgICAgICAgICAgICAgY2FzZSBDT1BZOgogICAgICAgICAgICAgICAgY29weSA9IHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgIGlmIChjb3B5KSB7CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gaGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBoYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gbGVmdCkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBsZWZ0OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KG91dHB1dCwgaW5wdXQsIG5leHQsIGNvcHksIHB1dCk7CiAgICAgICAgICAgICAgICAgIGhhdmUgLT0gY29weTsKICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBsZWZ0IC09IGNvcHk7CiAgICAgICAgICAgICAgICAgIHB1dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgVEFCTEU6CiAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE0KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm5sZW4gPSAoaG9sZCAmIDMxKSArIDI1NzsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA1OwogICAgICAgICAgICAgICAgYml0cyAtPSA1OwogICAgICAgICAgICAgICAgc3RhdGUubmRpc3QgPSAoaG9sZCAmIDMxKSArIDE7CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gNTsKICAgICAgICAgICAgICAgIGJpdHMgLT0gNTsKICAgICAgICAgICAgICAgIHN0YXRlLm5jb2RlID0gKGhvbGQgJiAxNSkgKyA0OwogICAgICAgICAgICAgICAgaG9sZCA+Pj49IDQ7CiAgICAgICAgICAgICAgICBiaXRzIC09IDQ7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubmxlbiA+IDI4NiB8fCBzdGF0ZS5uZGlzdCA+IDMwKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gInRvbyBtYW55IGxlbmd0aCBvciBkaXN0YW5jZSBzeW1ib2xzIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5oYXZlID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU5MRU5TOwogICAgICAgICAgICAgIGNhc2UgTEVOTEVOUzoKICAgICAgICAgICAgICAgIHdoaWxlIChzdGF0ZS5oYXZlIDwgc3RhdGUubmNvZGUpIHsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW29yZGVyW3N0YXRlLmhhdmUrK11dID0gaG9sZCAmIDc7CiAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAzOwogICAgICAgICAgICAgICAgICBiaXRzIC09IDM7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB3aGlsZSAoc3RhdGUuaGF2ZSA8IDE5KSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbnNbb3JkZXJbc3RhdGUuaGF2ZSsrXV0gPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubGVuY29kZSA9IHN0YXRlLmxlbmR5bjsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSA3OwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUubGVuYml0cyB9OwogICAgICAgICAgICAgICAgcmV0ID0gaW5mbGF0ZV90YWJsZShDT0RFUywgc3RhdGUubGVucywgMCwgMTksIHN0YXRlLmxlbmNvZGUsIDAsIHN0YXRlLndvcmssIG9wdHMpOwogICAgICAgICAgICAgICAgc3RhdGUubGVuYml0cyA9IG9wdHMuYml0czsKICAgICAgICAgICAgICAgIGlmIChyZXQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBjb2RlIGxlbmd0aHMgc2V0IjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5oYXZlID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBDT0RFTEVOUzsKICAgICAgICAgICAgICBjYXNlIENPREVMRU5TOgogICAgICAgICAgICAgICAgd2hpbGUgKHN0YXRlLmhhdmUgPCBzdGF0ZS5ubGVuICsgc3RhdGUubmRpc3QpIHsKICAgICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgICAgaGVyZSA9IHN0YXRlLmxlbmNvZGVbaG9sZCAmICgxIDw8IHN0YXRlLmxlbmJpdHMpIC0gMV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGhlcmVfdmFsIDwgMTYpIHsKICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbnNbc3RhdGUuaGF2ZSsrXSA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIGlmIChoZXJlX3ZhbCA9PT0gMTYpIHsKICAgICAgICAgICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyAyOwogICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYml0IGxlbmd0aCByZXBlYXQiOwogICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IHN0YXRlLmxlbnNbc3RhdGUuaGF2ZSAtIDFdOwogICAgICAgICAgICAgICAgICAgICAgY29weSA9IDMgKyAoaG9sZCAmIDMpOwogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IDI7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IDI7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChoZXJlX3ZhbCA9PT0gMTcpIHsKICAgICAgICAgICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyAzOwogICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IDA7CiAgICAgICAgICAgICAgICAgICAgICBjb3B5ID0gMyArIChob2xkICYgNyk7CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gMzsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gMzsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgbiA9IGhlcmVfYml0cyArIDc7CiAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgICAgbGVuID0gMDsKICAgICAgICAgICAgICAgICAgICAgIGNvcHkgPSAxMSArIChob2xkICYgMTI3KTsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA3OwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSA3OwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGF2ZSArIGNvcHkgPiBzdGF0ZS5ubGVuICsgc3RhdGUubmRpc3QpIHsKICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYml0IGxlbmd0aCByZXBlYXQiOwogICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB3aGlsZSAoY29weS0tKSB7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW3N0YXRlLmhhdmUrK10gPSBsZW47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubW9kZSA9PT0gQkFEKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmxlbnNbMjU2XSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGNvZGUgLS0gbWlzc2luZyBlbmQtb2YtYmxvY2siOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSA5OwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUubGVuYml0cyB9OwogICAgICAgICAgICAgICAgcmV0ID0gaW5mbGF0ZV90YWJsZShMRU5TLCBzdGF0ZS5sZW5zLCAwLCBzdGF0ZS5ubGVuLCBzdGF0ZS5sZW5jb2RlLCAwLCBzdGF0ZS53b3JrLCBvcHRzKTsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSBvcHRzLmJpdHM7CiAgICAgICAgICAgICAgICBpZiAocmV0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgbGl0ZXJhbC9sZW5ndGhzIHNldCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZGlzdGJpdHMgPSA2OwogICAgICAgICAgICAgICAgc3RhdGUuZGlzdGNvZGUgPSBzdGF0ZS5kaXN0ZHluOwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUuZGlzdGJpdHMgfTsKICAgICAgICAgICAgICAgIHJldCA9IGluZmxhdGVfdGFibGUoRElTVFMsIHN0YXRlLmxlbnMsIHN0YXRlLm5sZW4sIHN0YXRlLm5kaXN0LCBzdGF0ZS5kaXN0Y29kZSwgMCwgc3RhdGUud29yaywgb3B0cyk7CiAgICAgICAgICAgICAgICBzdGF0ZS5kaXN0Yml0cyA9IG9wdHMuYml0czsKICAgICAgICAgICAgICAgIGlmIChyZXQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZXMgc2V0IjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOXzsKICAgICAgICAgICAgICAgIGlmIChmbHVzaCA9PT0gWl9UUkVFUykgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgY2FzZSBMRU5fOgogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTjsKICAgICAgICAgICAgICBjYXNlIExFTjoKICAgICAgICAgICAgICAgIGlmIChoYXZlID49IDYgJiYgbGVmdCA+PSAyNTgpIHsKICAgICAgICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBsZWZ0OwogICAgICAgICAgICAgICAgICBzdHJtLm5leHRfaW4gPSBuZXh0OwogICAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX2luID0gaGF2ZTsKICAgICAgICAgICAgICAgICAgc3RhdGUuaG9sZCA9IGhvbGQ7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzOwogICAgICAgICAgICAgICAgICBpbmZsYXRlX2Zhc3Qoc3RybSwgX291dCk7CiAgICAgICAgICAgICAgICAgIHB1dCA9IHN0cm0ubmV4dF9vdXQ7CiAgICAgICAgICAgICAgICAgIG91dHB1dCA9IHN0cm0ub3V0cHV0OwogICAgICAgICAgICAgICAgICBsZWZ0ID0gc3RybS5hdmFpbF9vdXQ7CiAgICAgICAgICAgICAgICAgIG5leHQgPSBzdHJtLm5leHRfaW47CiAgICAgICAgICAgICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICAgICAgICAgICAgaGF2ZSA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgICAgICAgICAgIGhvbGQgPSBzdGF0ZS5ob2xkOwogICAgICAgICAgICAgICAgICBiaXRzID0gc3RhdGUuYml0czsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IFRZUEUpIHsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gLTE7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gMDsKICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUubGVuY29kZVtob2xkICYgKDEgPDwgc3RhdGUubGVuYml0cykgLSAxXTsKICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgIGhlcmVfb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGVyZV92YWwgPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICAgIGlmIChoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChoZXJlX29wICYmIChoZXJlX29wICYgMjQwKSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBsYXN0X2JpdHMgPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgIGxhc3Rfb3AgPSBoZXJlX29wOwogICAgICAgICAgICAgICAgICBsYXN0X3ZhbCA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUubGVuY29kZVtsYXN0X3ZhbCArICgoaG9sZCAmICgxIDw8IGxhc3RfYml0cyArIGxhc3Rfb3ApIC0gMSkgPj4gbGFzdF9iaXRzKV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChsYXN0X2JpdHMgKyBoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGxhc3RfYml0czsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgc3RhdGUuYmFjayArPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSBoZXJlX3ZhbDsKICAgICAgICAgICAgICAgIGlmIChoZXJlX29wID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMSVQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKGhlcmVfb3AgJiAzMikgewogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gLTE7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChoZXJlX29wICYgNjQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBsaXRlcmFsL2xlbmd0aCBjb2RlIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5leHRyYSA9IGhlcmVfb3AgJiAxNTsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU5FWFQ7CiAgICAgICAgICAgICAgY2FzZSBMRU5FWFQ6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZXh0cmEpIHsKICAgICAgICAgICAgICAgICAgbiA9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCArPSBob2xkICYgKDEgPDwgc3RhdGUuZXh0cmEpIC0gMTsKICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBiaXRzIC09IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrICs9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUud2FzID0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IERJU1Q7CiAgICAgICAgICAgICAgY2FzZSBESVNUOgogICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgIGhlcmUgPSBzdGF0ZS5kaXN0Y29kZVtob2xkICYgKDEgPDwgc3RhdGUuZGlzdGJpdHMpIC0gMV07CiAgICAgICAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICBoZXJlX29wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICBpZiAoaGVyZV9iaXRzIDw9IGJpdHMpIHsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoKGhlcmVfb3AgJiAyNDApID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGxhc3RfYml0cyA9IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgbGFzdF9vcCA9IGhlcmVfb3A7CiAgICAgICAgICAgICAgICAgIGxhc3RfdmFsID0gaGVyZV92YWw7CiAgICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICAgIGhlcmUgPSBzdGF0ZS5kaXN0Y29kZVtsYXN0X3ZhbCArICgoaG9sZCAmICgxIDw8IGxhc3RfYml0cyArIGxhc3Rfb3ApIC0gMSkgPj4gbGFzdF9iaXRzKV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChsYXN0X2JpdHMgKyBoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGxhc3RfYml0czsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgc3RhdGUuYmFjayArPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBpZiAoaGVyZV9vcCAmIDY0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgY29kZSI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUub2Zmc2V0ID0gaGVyZV92YWw7CiAgICAgICAgICAgICAgICBzdGF0ZS5leHRyYSA9IGhlcmVfb3AgJiAxNTsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBESVNURVhUOwogICAgICAgICAgICAgIGNhc2UgRElTVEVYVDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5leHRyYSkgewogICAgICAgICAgICAgICAgICBuID0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgbikgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgc3RhdGUub2Zmc2V0ICs9IGhvbGQgJiAoMSA8PCBzdGF0ZS5leHRyYSkgLSAxOwogICAgICAgICAgICAgICAgICBob2xkID4+Pj0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIGJpdHMgLT0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUub2Zmc2V0ID4gc3RhdGUuZG1heCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IE1BVENIOwogICAgICAgICAgICAgIGNhc2UgTUFUQ0g6CiAgICAgICAgICAgICAgICBpZiAobGVmdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBjb3B5ID0gX291dCAtIGxlZnQ7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUub2Zmc2V0ID4gY29weSkgewogICAgICAgICAgICAgICAgICBjb3B5ID0gc3RhdGUub2Zmc2V0IC0gY29weTsKICAgICAgICAgICAgICAgICAgaWYgKGNvcHkgPiBzdGF0ZS53aGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5zYW5lKSB7CiAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gc3RhdGUud25leHQpIHsKICAgICAgICAgICAgICAgICAgICBjb3B5IC09IHN0YXRlLnduZXh0OwogICAgICAgICAgICAgICAgICAgIGZyb20gPSBzdGF0ZS53c2l6ZSAtIGNvcHk7CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgZnJvbSA9IHN0YXRlLnduZXh0IC0gY29weTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoY29weSA+IHN0YXRlLmxlbmd0aCkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBzdGF0ZS53aW5kb3c7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgZnJvbSA9IHB1dCAtIHN0YXRlLm9mZnNldDsKICAgICAgICAgICAgICAgICAgY29weSA9IHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gbGVmdCkgewogICAgICAgICAgICAgICAgICBjb3B5ID0gbGVmdDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGxlZnQgLT0gY29weTsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCAtPSBjb3B5OwogICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICBvdXRwdXRbcHV0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tY29weSk7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIExJVDoKICAgICAgICAgICAgICAgIGlmIChsZWZ0ID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIG91dHB1dFtwdXQrK10gPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICBsZWZ0LS07CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBDSEVDSzoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCB8PSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIF9vdXQgLT0gbGVmdDsKICAgICAgICAgICAgICAgICAgc3RybS50b3RhbF9vdXQgKz0gX291dDsKICAgICAgICAgICAgICAgICAgc3RhdGUudG90YWwgKz0gX291dDsKICAgICAgICAgICAgICAgICAgaWYgKF9vdXQpIHsKICAgICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSBzdGF0ZS5mbGFncyA/IGNyYzMyMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBwdXQgLSBfb3V0KSA6IGFkbGVyMzIoc3RhdGUuY2hlY2ssIG91dHB1dCwgX291dCwgcHV0IC0gX291dCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgX291dCA9IGxlZnQ7CiAgICAgICAgICAgICAgICAgIGlmICgoc3RhdGUuZmxhZ3MgPyBob2xkIDogenN3YXAzMihob2xkKSkgIT09IHN0YXRlLmNoZWNrKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW5jb3JyZWN0IGRhdGEgY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTkdUSDsKICAgICAgICAgICAgICBjYXNlIExFTkdUSDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwICYmIHN0YXRlLmZsYWdzKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChob2xkICE9PSAoc3RhdGUudG90YWwgJiA0Mjk0OTY3Mjk1KSkgewogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImluY29ycmVjdCBsZW5ndGggY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IERPTkU7CiAgICAgICAgICAgICAgY2FzZSBET05FOgogICAgICAgICAgICAgICAgcmV0ID0gWl9TVFJFQU1fRU5EOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgQkFEOgogICAgICAgICAgICAgICAgcmV0ID0gWl9EQVRBX0VSUk9SOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgTUVNOgogICAgICAgICAgICAgICAgcmV0dXJuIFpfTUVNX0VSUk9SOwogICAgICAgICAgICAgIGNhc2UgU1lOQzoKICAgICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICBzdHJtLmF2YWlsX291dCA9IGxlZnQ7CiAgICAgICAgc3RybS5uZXh0X2luID0gbmV4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GF0ZS5tb2RlID09PSBMRU5fIHx8IHN0YXRlLm1vZGUgPT09IENPUFlfID8gMjU2IDogMCk7CiAgICAgICAgaWYgKChfaW4gPT09IDAgJiYgX291dCA9PT0gMCB8fCBmbHVzaCA9PT0gWl9GSU5JU0gpICYmIHJldCA9PT0gWl9PSykgewogICAgICAgICAgcmV0ID0gWl9CVUZfRVJST1I7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZUVuZChzdHJtKSB7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHZhciBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgaWYgKHN0YXRlLndpbmRvdykgewogICAgICAgICAgc3RhdGUud2luZG93ID0gbnVsbDsKICAgICAgICB9CiAgICAgICAgc3RybS5zdGF0ZSA9IG51bGw7CiAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZUdldEhlYWRlcihzdHJtLCBoZWFkKSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgaWYgKChzdGF0ZS53cmFwICYgMikgPT09IDApIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUuaGVhZCA9IGhlYWQ7CiAgICAgICAgaGVhZC5kb25lID0gZmFsc2U7CiAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZVNldERpY3Rpb25hcnkoc3RybSwgZGljdGlvbmFyeSkgewogICAgICAgIHZhciBkaWN0TGVuZ3RoID0gZGljdGlvbmFyeS5sZW5ndGg7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIHZhciBkaWN0aWQ7CiAgICAgICAgdmFyIHJldDsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS53cmFwICE9PSAwICYmIHN0YXRlLm1vZGUgIT09IERJQ1QpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IERJQ1QpIHsKICAgICAgICAgIGRpY3RpZCA9IDE7CiAgICAgICAgICBkaWN0aWQgPSBhZGxlcjMyKGRpY3RpZCwgZGljdGlvbmFyeSwgZGljdExlbmd0aCwgMCk7CiAgICAgICAgICBpZiAoZGljdGlkICE9PSBzdGF0ZS5jaGVjaykgewogICAgICAgICAgICByZXR1cm4gWl9EQVRBX0VSUk9SOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXQgPSB1cGRhdGV3aW5kb3coc3RybSwgZGljdGlvbmFyeSwgZGljdExlbmd0aCwgZGljdExlbmd0aCk7CiAgICAgICAgaWYgKHJldCkgewogICAgICAgICAgc3RhdGUubW9kZSA9IE1FTTsKICAgICAgICAgIHJldHVybiBaX01FTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUuaGF2ZWRpY3QgPSAxOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGV4cG9ydHMuaW5mbGF0ZVJlc2V0ID0gaW5mbGF0ZVJlc2V0OwogICAgICBleHBvcnRzLmluZmxhdGVSZXNldDIgPSBpbmZsYXRlUmVzZXQyOwogICAgICBleHBvcnRzLmluZmxhdGVSZXNldEtl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AgWl9TVFJFQU1fRU5EOiAxLAogICAgICAgIFpfTkVFRF9ESUNUOiAyLAogICAgICAgIFpfRVJSTk86IC0xLAogICAgICAgIFpfU1RSRUFNX0VSUk9SOiAtMiwKICAgICAgICBaX0RBVEFfRVJST1I6IC0zLAogICAgICAgIFpfQlVGX0VSUk9SOiAtNSwKICAgICAgICBaX05PX0NPTVBSRVNTSU9OOiAwLAogICAgICAgIFpfQkVTVF9TUEVFRDogMSwKICAgICAgICBaX0JFU1RfQ09NUFJFU1NJT046IDksCiAgICAgICAgWl9ERUZBVUxUX0NPTVBSRVNTSU9OOiAtMSwKICAgICAgICBaX0ZJTFRFUkVEOiAxLAogICAgICAgIFpfSFVGRk1BTl9PTkxZOiAyLAogICAgICAgIFpfUkxFOiAzLAogICAgICAgIFpfRklYRUQ6IDQsCiAgICAgICAgWl9ERUZBVUxUX1NUUkFURUdZOiAwLAogICAgICAgIFpfQklOQVJZOiAwLAogICAgICAgIFpfVEVYVDogMSwKICAgICAgICBaX1VOS05PV046IDIsCiAgICAgICAgWl9ERUZMQVRFRDogOAogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvZ3poZWFkZXIuanMKICB2YXIgcmVxdWlyZV9nemhlYWRlciA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9nemhlYWRlci5qcyIoZXhwb3J0cywgbW9kdWxlKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBmdW5jdGlvbiBHWmhlYWRlcigpIHsKICAgICAgICB0aGlzLnRleHQgPSAwOwogICAgICAgIHRoaXMudGltZSA9IDA7CiAgICAgICAgdGhpcy54ZmxhZ3MgPSAwOwogICAgICAgIHRoaXMub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mbGF0ZTIpKQogICAgICAgICAgcmV0dXJuIG5ldyBJbmZsYXRlMihvcHRpb25zKTsKICAgICAgICB0aGlzLm9wdGlvbnMgPSB1dGlscy5hc3NpZ24oewogICAgICAgICAgY2h1bmtTaXplOiAxNjM4NCwKICAgICAgICAgIHdpbmRvd0JpdHM6IDAsCiAgICAgICAgICB0bzogIiIKICAgICAgICB9LCBvcHRpb25zIHx8IHt9KTsKICAgICAgICB2YXIgb3B0ID0gdGhpcy5vcHRpb25zOwogICAgICAgIGlmIChvcHQucmF3ICYmIG9wdC53aW5kb3dCaXRzID49IDAgJiYgb3B0LndpbmRvd0JpdHMgPCAxNikgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgPSAtb3B0LndpbmRvd0JpdHM7CiAgICAgICAgICBpZiAob3B0LndpbmRvd0JpdHMgPT09IDApIHsKICAgICAgICAgICAgb3B0LndpbmRvd0JpdHMgPSAtMTU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChvcHQud2luZG93Qml0cyA+PSAwICYmIG9wdC53aW5kb3dCaXRzIDwgMTYgJiYgIShvcHRpb25zICYmIG9wdGlvbnMud2luZG93Qml0cykpIHsKICAgICAgICAgIG9wdC53aW5kb3dCaXRzICs9IDMyOwogICAgICAgIH0KICAgICAgICBpZiAob3B0LndpbmRvd0JpdHMgPiAxNSAmJiBvcHQud2luZG93Qml0cyA8IDQ4KSB7CiAgICAgICAgICBpZiAoKG9wdC53aW5kb3dCaXRzICYgMTUpID09PSAwKSB7CiAgICAgICAgICAgIG9wdC53aW5kb3dCaXRzIHw9IDE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLmVyciA9IDA7CiAgICAgICAgdGhpcy5tc2cgPSAiIjsKICAgICAgICB0aGlzLmVuZGVkID0gZmFsc2U7CiAgICAgICAgdGhpcy5jaHVua3MgPSBbXTsKICAgICAgICB0aGlzLnN0cm0gPSBuZXcgWlN0cmVhbSgpOwogICAgICAgIHRoaXMuc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgIHZhciBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZUluaXQyKHRoaXMuc3RybSwgb3B0LndpbmRvd0JpdHMpOwogICAgICAgIGlmIChzdGF0dXMgIT09IGMuWl9PSykgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKG1zZ1tzdGF0dXNdKTsKICAgICAgICB9CiAgICAgICAgdGhpcy5oZWFkZXIgPSBuZXcgR1poZWFkZXIoKTsKICAgICAgICB6bGliX2luZmxhdGUuaW5mbGF0ZUdldEhlYWRlcih0aGlzLnN0cm0sIHRoaXMuaGVhZGVyKTsKICAgICAgICBpZiAob3B0LmRpY3Rpb25hcnkpIHsKICAgICAgICAgIGlmICh0eXBlb2Ygb3B0LmRpY3Rpb25hcnkgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIG9wdC5kaWN0aW9uYXJ5ID0gc3RyaW5ncy5zdHJpbmcyYnVmKG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0gZWxzZSBpZiAodG9TdHJpbmcuY2FsbChvcHQuZGljdGlvbmFyeSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgICAgb3B0LmRpY3Rpb25hcnkgPSBuZXcgVWludDhBcnJheShvcHQuZGljdGlvbmFyeSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAob3B0LnJhdykgewogICAgICAgICAgICBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZVNldERpY3Rpb25hcnkodGhpcy5zdHJtLCBvcHQuZGljdGlvbmFyeSk7CiAgICAgICAgICAgIGlmIChzdGF0dXMgIT09IGMuWl9PSykgewogICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihtc2dbc3RhdHVzXSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgSW5mbGF0ZTIucHJvdG90eXBlLnB1c2ggPSBmdW5jd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ID0gc3RyaW5ncy51dGY4Ym9yZGVyKHN0cm0ub3V0cHV0LCBzdHJtLm5leHRfb3V0KTsKICAgICAgICAgICAgICAgIHRhaWwgPSBzdHJtLm5leHRfb3V0IC0gbmV4dF9vdXRfdXRmODsKICAgICAgICAgICAgICAgIHV0ZjhzdHIgPSBzdHJpbmdzLmJ1ZjJzdHJpbmcoc3RybS5vdXRwdXQsIG5leHRfb3V0X3V0ZjgpOwogICAgICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IHRhaWw7CiAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZSAtIHRhaWw7CiAgICAgICAgICAgICAgICBpZiAodGFpbCkgewogICAgICAgICAgICAgICAgICB1dGlscy5hcnJheVNldChzdHJtLm91dHB1dCwgc3RybS5vdXRwdXQsIG5leHRfb3V0X3V0ZjgsIHRhaWwsIDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgdGhpcy5vbkRhdGEodXRmOHN0cik7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgYWxsb3dCdWZFcnJvciA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKHN0cm0uYXZhaWxfaW4gPiAwIHx8IHN0cm0uYXZhaWxfb3V0ID09PSAwKSAmJiBzdGF0dXMgIT09IGMuWl9TVFJFQU1fRU5EKTsKICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfU1RSRUFNX0VORCkgewogICAgICAgICAgX21vZGUgPSBjLlpfRklOSVNIOwogICAgICAgIH0KICAgICAgICBpZiAoX21vZGUgPT09IGMuWl9GSU5JU0gpIHsKICAgICAgICAgIHN0YXR1cyA9IHpsaWJfaW5mbGF0ZS5pbmZsYXRlRW5kKHRoaXMuc3RybSk7CiAgICAgICAgICB0aGlzLm9uRW5kKHN0YXR1cyk7CiAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgIHJldHVybiBzdGF0dXMgPT09IGMuWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBjLlpfU1lOQ19GTFVTSCkgewogICAgICAgICAgdGhpcy5vbkVuZChjLlpfT0spOwogICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0cnVlOwogICAgICB9OwogICAgICBJbmZsYXRlMi5wcm90b3R5cGUub25EYXRhID0gZnVuY3Rpb24oY2h1bmspIHsKICAgICAgICB0aGlzLmNodW5rcy5wdXNoKGNodW5rKTsKICAgICAgfTsKICAgICAgSW5mbGF0ZTIucHJvdG90eXBlLm9uRW5kID0gZnVuY3Rpb24oc3RhdHVzKSB7CiAgICAgICAgaWYgKHN0YXR1cyA9PT0gYy5aX09LKSB7CiAgICAgICAgICBpZiAodGhpcy5vcHRpb25zLnRvID09PSAic3RyaW5nIikgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHRoaXMuY2h1bmtzLmpvaW4oIiIpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdGhpcy5yZXN1bHQgPSB1dGlscy5mbGF0dGVuQ2h1bmtzKHRoaXMuY2h1bmtzKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdGhpcy5jaHVua3MgPSBbXTsKICAgICAgICB0aGlzLmVyciA9IHN0YXR1czsKICAgICAgICB0aGlzLm1zZyA9IHRoaXMuc3RybS5tc2c7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGluZmxhdGUoaW5wdXQsIG9wdGlvbnMpI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gMTc4OTkyNzY2NiwKICAgICAgICA0MDg5MDE2NjQ4LAogICAgICAgIDIyMjcwNjEyMTQsCiAgICAgICAgNDUwNTQ4ODYxLAogICAgICAgIDE4NDMyNTg2MDMsCiAgICAgICAgNDEwNzU4MDc1MywKICAgICAgICAyMjExNjc3NjM5LAogICAgICAgIDMyNTg4Mzk5MCwKICAgICAgICAxNjg0Nzc3MTUyLAogICAgICAgIDQyNTExMjIwNDIsCiAgICAgICAgMjMyMTkyNjYzNiwKICAgICAgICAzMzU2MzM0ODcsCiAgICAgICAgMTY2MTM2NTQ2NSwKICAgICAgICA0MTk1MzAyNzU1LAogICAgICAgIDIzNjYxMTUzMTcsCiAgICAgICAgOTk3MDczMDk2LAogICAgICAgIDEyODE5NTM4ODYsCiAgICAgICAgMzU3OTg1NTMzMiwKICAgICAgICAyNzI0Njg4MjQyLAogICAgICAgIDEwMDY4ODgxNDUsCiAgICAgICAgMTI1ODYwNzY4NywKICAgICAgICAzNTI0MTAxNjI5LAogICAgICAgIDI3Njg5NDI0NDMsCiAgICAgICAgOTAxMDk3NzIyLAogICAgICAgIDExMTkwMDA2ODQsCiAgICAgICAgMzY4NjUxNzIwNiwKICAgICAgICAyODk4MDY1NzI4LAogICAgICAgIDg1MzA0NDQ1MSwKICAgICAgICAxMTcyMjY2MTAxLAogICAgICAgIDM3MDUwMTU3NTksCiAgICAgICAgMjg4MjYxNjY2NSwKICAgICAgICA2NTE3Njc5ODAsCiAgICAgICAgMTM3MzUwMzU0NiwKICAgICAgICAzMzY5NTU0MzA0LAogICAgICAgIDMyMTgxMDQ1OTgsCiAgICAgICAgNTY1NTA3MjUzLAogICAgICAgIDE0NTQ2MjE3MzEsCiAgICAgICAgMzQ4NTExMTcwNSwKICAgICAgICAzMDk5NDM2MzAzLAogICAgICAgIDY3MTI2Njk3NCwKICAgICAgICAxNTk0MTk4MDI0LAogICAgICAgIDMzMjI3MzA5MzAsCiAgICAgICAgMjk3MDM0NzgxMiwKICAgICAgICA3OTU4MzU1MjcsCiAgICAgICAgMTQ4MzIzMDIyNSwKICAgICAgICAzMjQ0MzY3Mjc1LAogICAgICAgIDMwNjAxNDk1NjUsCiAgICAgICAgMTk5NDE0NjE5MiwKICAgICAgICAzMTE1ODUzNCwKICAgICAgICAyNTYzOTA3NzcyLAogICAgICAgIDQwMjM3MTc5MzAsCiAgICAgICAgMTkwNzQ1OTQ2NSwKICAgICAgICAxMTI2MzcyMTUsCiAgICAgICAgMjY4MDE1MzI1MywKICAgICAgICAzOTA0NDI3MDU5LAogICAgICAgIDIwMTM3NzYyOTAsCiAgICAgICAgMjUxNzIyMDM2LAogICAgICAgIDI1MTcyMTUzNzQsCiAgICAgICAgMzc3NTgzMDA0MCwKICAgICAgICAyMTM3NjU2NzYzLAogICAgICAgIDE0MTM3NjgxMywKICAgICAgICAyNDM5Mjc3NzE5LAogICAgICAgIDM4NjUyNzEyOTcsCiAgICAgICAgMTgwMjE5NTQ0NCwKICAgICAgICA0NzY4NjQ4NjYsCiAgICAgICAgMjIzODAwMTM2OCwKICAgICAgICA0MDY2NTA4ODc4LAogICAgICAgIDE4MTIzNzA5MjUsCiAgICAgICAgNDUzMDkyNzMxLAogICAgICAgIDIxODE2MjUwMjUsCiAgICAgICAgNDExMTQ1MTIyMywKICAgICAgICAxNzA2MDg4OTAyLAogICAgICAgIDMxNDA0MjcwNCwKICAgICAgICAyMzQ0NTMyMjAyLAogICAgICAgIDQyNDAwMTc1MzIsCiAgICAgICAgMTY1ODY1ODI3MSwKICAgICAgICAzNjY2MTk5NzcsCiAgICAgICAgMjM2MjY3MDMyMywKICAgICAgICA0MjI0OTk0NDA1LAogICAgICAgIDEzMDM1MzU5NjAsCiAgICAgICAgOTg0OTYxNDg2LAogICAgICAgIDI3NDcwMDcwOTIsCiAgICAgICAgMzU2OTAzNzUzOCwKICAgICAgICAxMjU2MTcwODE3LAogICAgICAgIDEwMzc2MDQzMTEsCiAgICAgICAgMjc2NTIxMDczMywKICAgICAgICAzNTU0MDc5OTk1LAogICAgICAgIDExMzEwMTQ1MDYsCiAgICAgICAgODc5Njc5OTk2LAogICAgICAgIDI5MDkyNDM0NjIsCiAgICAgICAgMzY2Mzc3MTg1NiwKICAgICAgICAxMTQxMTI0NDY3LAogICAgICAgIDg1NTg0MjI3NywKICAgICAgICAyODUyODAxNjMxLAogICAgICAgIDM3MDg2NDg2NDksCiAgICAgICAgMTM0MjUzMzk0OCwKICAgICAgICA2NTQ0NTkzMDYsCiAgICAgICAgMzE4ODM5NjA0OCwKICAgICAgICAzMzczMDE1MTc0LAogICAgICAgIDE0NjY0Nzk5MDksCiAgICAgICAgNTQ0MTc5NjM1LAogICAgICAgIDMxMTA1MjM5MTMsCiAgICAgICAgMzQ2MjUyMjAxNSwKICAgICAgICAxNTkxNjcxMDU0LAogICAgICAgIDcwMjEzODc3NiwKICAgICAgICAyOTY2NDYwNDUwLAogICAgICAgIDMzNTI3OTk0MTIsCiAgICAgICAgMTUwNDkxODgwNywKICAgICAgICA3ODM1NTE4NzMsCiAgICAgICAgMzA4MjY0MDQ0MywKICAgICAgICAzMjMzNDQyOTg5LAogICAgICAgIDM5ODgyOTIzODQsCiAgICAgICAgMjU5NjI1NDY0NiwKICAgICAgICA2MjMxNzA2OCwKICAgICAgICAxOTU3ODEwODQyLAogICAgICAgIDM5Mzk4NDU5NDUsCiAgICAgICAgMjY0NzgxNjExMSwKICAgICAgICA4MTQ3MDk5NywKICAgICAgICAxOTQzODAzNTIzLAogICAgICAgIDM4MTQ5MTg5MzAsCiAgICAgICAgMjQ4OTU5NjgwNCwKICAgICAgICAyMjUyNzQ0MzAsCiAgICAgICAgMjA1Mzc5MDM3NiwKICAgICAgICAzODI2MTc1NzU1LAogICAgICAgIDI0NjY5MDYwMTMsCiAgICAgICAgMTY3ODE2NzQzLAogICAgICAgIDIwOTc2NTEzNzcsCiAgICAgICAgNDAyNzU1MjU4MCwKICAgICAgICAyMjY1NDkwMzg2LAogICAgICAgIDUwMzQ0NDA3MiwKICAgICAgICAxNzYyMDUwODE0LAogICAgICAgIDQxNTA0MTcyNDUsCiAgICAgICAgMjE1NDEyOTM1NSwKICAgICAgICA0MjY1MjIyMjUsCiAgICAgICAgMTg1MjUwNzg3OSwKICAgICAgICA0Mjc1MzEzNTI2LAogICAgICAgIDIzMTIzMTc5MjAsCiAgICAgICAgMjgyNzUzNjI2LAogICAgICAgIDE3NDI1NTU4NTIsCiAgICAgICAgNDE4OTcwODE0MywKICAgICAgICAyMzk0ODc3OTQ1LAogICAgICAgIDM5NzkxNzc2MywKICAgICAgICAxNjIyMTgzNjM3LAogICAgICAgIDM2MDQzOTA4ODgsCiAgICAgICAgMjcxNDg2NjU1OCwKICAgICAgICA5NTM3Mjk3MzIsCiAgICAgICAgMTM0MDA3NjYyNiwKICAgICAgICAzNTE4NzE5OTg1LAogICAgICAgIDI3OTczNjA5OTksCiAgICAgICAgMTA2ODgyODM4MSwKICAgICAgICAxMjE5NjM4ODU5LAogICAgICAgIDM2MjQ3NDE4NTAsCiAgICAgICAgMjkzNjY3NTE0OCwKICAgICAgICA5MDYxODU0NjIsCiAgICAgICAgMTA5MDgxMjUxMiwKICAgICAgICAzNzQ3NjcyMDAzLAogICAgICAgIDI4MjUzNzk2NjksCiAgICAgICAgODI5MzI5MTM1LAogICAgICAgIDExODEzMzUxNjEsCiAgICAgICAgMzQxMjE3NzgwNCwKICAgICAgICAzMTYwODM0ODQyLAogICAgICAgIDYyODA4NTQwOCwKICAgICAgICAxMzgyNjA1MzY2LAogICAgICAgIDM0MjMzNjkxMDksCiAgICAgICAgMzEzODA3ODQ2NywKICAgICAgICA1NzA1NjIyMzMsCiAgICAgICAgMTQyNjQwMDgxNSwKICAgICAgICAzMzE3MzE2NTQyLAogICAgICAgIDI5OTg3MzM2MDgsCiAgICAgICAgNzMzMjM5OTU0LAogICAgICAgIDE1NTUyNjE5NTYsCiAgICAgICAgMzI2ODkzNTU5MSwKICAgICAgICAzMDUwMzYwNjI1LAogICAgICAgIDc1MjQ1OTQwMywKICAgICAgICAxNTQxMzIwMjIxLAogICAgICAgIDI2MDcwNzE5MjAsCiAgICAgICAgMzk2NTk3MzAzMCwKICAgICAgICAxOTY5OTIyOTcyLAogICAgICAgIDQwNzM1NDk4LAogICAgICAgIDI2MTc4MzcyMjUsCiAgICAgICAgMzk0MzU3NzE1MSwKICAgICAgICAxOTEzMDg3ODc3LAogICAgICAgIDgzOTA4MzcxLAogICAgICAgIDI1MTIzNDE2MzQsCiAgICAgICAgMzgwMzc0MDY5MiwKICAgICAgICAyMDc1MjA4NjIyLAogICAgICAgIDIxMzI2MTExMiwKICAgICAgICAyNDYzMjcyNjAzLAogICAgICAgIDM4NTU5OTAyODUsCiAgICAgICAgMjA5NDg1NDA3MSwKICAgICAgICAxOTg5NTg4ODEsCiAgICAgICAgMjI2MjAyOTAxMiwKICAgICAgICA0MDU3MjYwNjEwLAogICAgICAgIDE3NTkzNTk5OTIsCiAgICAgICAgNTM0NDE0MTkwLAogICAgICAgIDIxNzY3MTg1NDEsCiAgICAgICAgNDEzOTMyOTExNSwKICAgICAgICAxODczODM2MDAxLAogICAgICAgIDQxNDY2NDU2NywKICAgICAgICAyMjgyMjQ4OTM0LAogICAgICAgIDQyNzkyMDAzNjgsCiAgICAgICAgMTcxMTY4NDU1NCwKICAgICAgICAyODUyODExMTYsCiAgICAgICAgMjQwNTgwMTcyNywKICAgICAgICA0MTY3MjE2NzQ1LAogICAgICAgIDE2MzQ0Njc3OTUsCiAgICAgICAgMzc2MjI5NzAxLAogICAgICAgIDI2ODUwNjc4OTYsCiAgICAgICAgMzYwODAwNzQwNiwKICAgICAgICAxMzA4OTE4NjEyLAogICAgICAgIDk1NjU0MzkzOCwKICAgICAgICAyODA4NTU1MTA1LAogICAgICAgIDM0OTU5NTgyNjMsCiAgICAgICAgMTIzMTYzNjMwMSwKICAgICAgICAxMDQ3NDI3MDM1LAogICAgICAgIDI5MzI5NTk4MTgsCiAgICAgICAgMzY1NDcwMzgzNiwKICAgICAgICAxMDg4MzU5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bnRzKSk7CiAgICAgIH0KICAgICAgY3JjMzIyLnNpZ25lZCA9IGZ1bmN0aW9uKCkgewogICAgICAgIHJldHVybiBfY3JjMzIuYXBwbHkobnVsbCwgYXJndW1lbnRzKTsKICAgICAgfTsKICAgICAgY3JjMzIyLnVuc2lnbmVkID0gZnVuY3Rpb24oKSB7CiAgICAgICAgcmV0dXJuIF9jcmMzMi5hcHBseShudWxsLCBhcmd1bWVudHMpID4+PiAwOwogICAgICB9OwogICAgICBtb2R1bGUuZXhwb3J0cyA9IGNyYzMyMjsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL29iamVjdC5lbnRyaWVzLXBvbnlmaWxsQDEuMC4xL25vZGVfbW9kdWxlcy9vYmplY3QuZW50cmllcy1wb255ZmlsbC9lbnRyaWVzLmpzCiAgdmFyIHJlcXVpcmVfZW50cmllcyA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9vYmplY3QuZW50cmllcy1wb255ZmlsbEAxLjAuMS9ub2RlX21vZHVsZXMvb2JqZWN0LmVudHJpZXMtcG9ueWZpbGwvZW50cmllcy5qcyIoZXhwb3J0cywgbW9kdWxlKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgaGFzID0gZnVuY3Rpb24ob2JqLCBwcm9wKSB7CiAgICAgICAgcmV0dXJuIE9iamVjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHkuY2FsbChvYmosIHByb3ApOwogICAgICB9OwogICAgICB2YXIgaXNFbnVtZXJhYmxlID0gZnVuY3Rpb24ob2JqLCBwcm9wKSB7CiAgICAgICAgcmV0dXJuIE9iamVjdC5wcm90b3R5cGUucHJvcGVydHlJc0VudW1lcmFibGUuY2FsbChvYmosIHByb3ApOwogICAgICB9OwogICAgICBmdW5jdGlvbiBlbnRyaWVzMihvYmopIHsKICAgICAgICBpZiAob2JqID09IG51bGw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U6IHRydWUKICAgICAgICAgIH0KICAgICAgICB9KTsKICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoc3ViQ2xhc3MsICJwcm90b3R5cGUiLCB7CiAgICAgICAgICB3cml0YWJsZTogZmFsc2UKICAgICAgICB9KTsKICAgICAgICBpZiAoc3VwZXJDbGFzcykKICAgICAgICAgIF9zZXRQcm90b3R5cGVPZihzdWJDbGFzcywgc3VwZXJDbGFzcyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mKG8pIHsKICAgICAgICBfZ2V0UHJvdG90eXBlT2YgPSBPYmplY3Quc2V0UHJvdG90eXBlT2YgPyBPYmplY3QuZ2V0UHJvdG90eXBlT2YuYmluZCgpIDogZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mMihvMikgewogICAgICAgICAgcmV0dXJuIG8yLl9fcHJvdG9fXyB8fCBPYmplY3QuZ2V0UHJvdG90eXBlT2YobzIpOwogICAgICAgIH07CiAgICAgICAgcmV0dXJuIF9nZXRQcm90b3R5cGVPZihvKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YobywgcCkgewogICAgICAgIF9zZXRQcm90b3R5cGVPZiA9IE9iamVjdC5zZXRQcm90b3R5cGVPZiA/IE9iamVjdC5zZXRQcm90b3R5cGVPZi5iaW5kKCkgOiBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YyKG8yLCBwMikgewogICAgICAgICAgbzIuX19wcm90b19fID0gcDI7CiAgICAgICAgICByZXR1cm4gbzI7CiAgICAgICAgfTsKICAgICAgICByZXR1cm4gX3NldFByb3RvdHlwZU9mKG8sIHApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9pc05hdGl2ZVJlZmxlY3RDb25zdHJ1Y3QoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ID09PSAidW5kZWZpbmVkIiB8fCAhUmVmbGVjdC5jb25zdHJ1Y3QpCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKFJlZmxlY3QuY29uc3RydWN0LnNoYW0pCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKHR5cGVvZiBQcm94eSA9PT0gImZ1bmN0aW9uIikKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIHRyeSB7CiAgICAgICAgICBCb29sZWFuLnByb3RvdHlwZS52YWx1ZU9mLmNhbGwoUmVmbGVjdC5jb25zdHJ1Y3QoQm9vbGVhbiwgW10sIGZ1bmN0aW9uKCkgewogICAgICAgICAgfSkpOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBfYXNzZXJ0VGhpc0luaXRpYWxpemVkKHNlbGYyKSB7CiAgICAgICAgaWYgKHNlbGYyID09PSB2b2lkIDApIHsKICAgICAgICAgIHRocm93IG5ldyBSZWZlcmVuY2VFcnJvcigidGhpcyBoYXNuJ3QgYmVlbiBpbml0aWFsaXNlZCAtIHN1cGVyKCkgaGFzbid0IGJlZW4gY2FsbGVkIik7CiAgICAgICAgfQogICAgICAgIHJldHVybiBzZWxmMjsKICAgICAgfQogICAgICBmdW5jdGlvbiBfcG9zc2libGVDb25zdHJ1Y3RvclJldHVybihzZWxmMiwgY2FsbCkgewogICAgICAgIGlmIChjYWxsICYmICh0eXBlb2YgY2FsbCA9PT0gIm9iamVjdCIgfHwgdHlwZW9mIGNhbGwgPT09ICJmdW5jdGlvbiIpKSB7CiAgICAgICAgICByZXR1cm4gY2FsbDsKICAgICAgICB9IGVsc2UgaWYgKGNhbGwgIT09IHZvaWQgMCkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiRGVyaXZlZCBjb25zdHJ1Y3RvcnMgbWF5IG9ubHkgcmV0dXJuIG9iamVjdCBvciB1bmRlZmluZWQiKTsKICAgICA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XR1cm4gb2JqZWN0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9nZXQoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ICE9PSAidW5kZWZpbmVkIiAmJiBSZWZsZWN0LmdldCkgewogICAgICAgICAgX2dldCA9IFJlZmxlY3QuZ2V0LmJpbmQoKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgX2dldCA9IGZ1bmN0aW9uIF9nZXQyKHRhcmdldCwgcHJvcGVydHksIHJlY2VpdmVyKSB7CiAgICAgICAgICAgIHZhciBiYXNlID0gX3N1cGVyUHJvcEJhc2UodGFyZ2V0LCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmICghYmFzZSkKICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIHZhciBkZXNjID0gT2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcihiYXNlLCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmIChkZXNjLmdldCkgewogICAgICAgICAgICAgIHJldHVybiBkZXNjLmdldC5jYWxsKGFyZ3VtZW50cy5sZW5ndGggPCAzID8gdGFyZ2V0IDogcmVjZWl2ZXIpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBkZXNjLnZhbHVlOwogICAgICAgICAgfTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIF9nZXQuYXBwbHkodGhpcywgYXJndW1lbnRzKTsKICAgICAgfQogICAgICB2YXIgRW1pdHRlciA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbigpIHsKICAgICAgICBmdW5jdGlvbiBFbWl0dGVyMigpIHsKICAgICAgICAgIF9jbGFzc0NhbGxDaGVjayh0aGlzLCBFbWl0dGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgImxpc3RlbmVycyIsIHsKICAgICAgICAgICAgdmFsdWU6IHt9LAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEVtaXR0ZXIyLCBbewogICAgICAgICAga2V5OiAiYWRkRXZlbnRMaXN0ZW5lciIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWRkRXZlbnRMaXN0ZW5lcih0eXBlLCBjYWxsYmFjaywgb3B0aW9ucykgewogICAgICAgICAgICBpZiAoISh0eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHRoaXMubGlzdGVuZXJzW3R5cGVdID0gW107CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5saXN0ZW5lcnNbdHlwZV0ucHVzaCh7CiAgICAgICAgICAgICAgY2FsbGJhY2ssCiAgICAgICAgICAgICAgb3B0aW9ucwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJyZW1vdmVFdmVudExpc3RlbmVyIiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiByZW1vdmVFdmVudExpc3RlbmVyKHR5cGUsIGNhbGxiYWNrKSB7CiAgICAgICAgICAgIGlmICghKHR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW3R5cGVdOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIGlmIChzdGFja1tpXS5jYWxsYmFjayA9PT0gY2FsbGJhY2spIHsKICAgICAgICAgICAgICAgIHN0YWNrLnNwbGljZShpLCAxKTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJkaXNwYXRjaEV2ZW50IiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiBkaXNwYXRjaEV2ZW50KGV2ZW50KSB7CiAgICAgICAgICAgIGlmICghKGV2ZW50LnR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW2V2ZW50LnR5cGVdOwogICAgICAgICAgICB2YXIgc3RhY2tUb0NhbGwgPSBzdGFjay5zbGljZSgpOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrVG9DYWxsLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIHZhciBsaXN0ZW5lciA9IHN0YWNrVG9DYWxsW2ldOwogICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICBsaXN0ZW5lci5jYWxsYmFjay5jYWxsKHRoaXMsIGV2ZW50KTsKICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICBQcm9taXNlLnJlc29sdmUoKS50aGVuKGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChsaXN0ZW5lci5vcHRpb25zICYmIGxpc3RlbmVyLm9wdGlvbnMub25jZSkgewogICAgICAgICAgICAgICAgdGhpcy5yZW1vdmVFdmVudExpc3RlbmVyKGV2ZW50LnR5cGUsIGxpc3RlbmVyLmNhbGxiYWNrKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuICFldmVudC5kZWZhdWx0UHJldmVudGVkOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gRW1pdHRlcjI7CiAgICAgIH0oKTsKICAgICAgdmFyIEFib3J0U2lnbmFsID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKF9FbWl0dGVyKSB7CiAgICAgICAgX2luaGVyaXRzKEFib3J0U2lnbmFsMiwgX0VtaXR0ZXIpOwogICAgICAgIHZhciBfc3VwZXIgPSBfY3JlYXRlU3VwZXIoQWJvcnRTaWduYWwyKTsKICAgICAgICBmdW5jdGlvbiBBYm9ydFNpZ25hbDIoKSB7CiAgICAgICAgICB2YXIgX3RoaXM7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRTaWduYWwyKTsKICAgICAgICAgIF90aGlzID0gX3N1cGVyLmNhbGwodGhpcyk7CiAgICAgICAgICBpZiAoIV90aGlzLmxpc3RlbmVycykgewogICAgICAgICAgICBFbWl0dGVyLmNhbGwoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcykpOwogICAgICAgICAgfQogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KF9hc3NlcnRUaGlzSW5pdGlhbGl6ZWQoX3RoaXMpLCAiYWJvcnRlZCIsIHsKICAgICAgICAgICAgdmFsdWU6IGZhbHNlLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgIm9uYWJvcnQiLCB7CiAgICAgICAgICAgIHZhbHVlOiBudWxsLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgInJlYXNvbiIsIHsKICAgICAgICAgICAgdmFsdWU6IHZvaWQgMCwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICByZXR1cm4gX3RoaXM7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhBYm9ydFNpZ25hbDIsIFt7CiAgICAgICAgICBrZXk6ICJ0b1N0cmluZyIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gdG9TdHJpbmcoKSB7CiAgICAgICAgICAgIHJldHVybiAiW29iamVjdCBBYm9ydFNpZ25hbF0iOwogICAgICAgICAgfQogICAgICAgIH0sIHsKICAgICAgICAgIGtleTogImRpc3BhdGNoRXZlbnQiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGRpc3BhdGNoRXZlbnQoZXZlbnQpIHsKICAgICAgICAgICAgaWYgKGV2ZW50LnR5cGUgPT09ICJhYm9ydCIpIHsKICAgICAgICAgICAgICB0aGlzLmFib3J0ZWQgPSB0cnVlOwogICAgICAgICAgICAgIGlmICh0eXBlb2YgdGhpcy5vbmFib3J0ID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgICAgICB0aGlzLm9uYWJvcnQuY2FsbCh0aGlzLCBldmVudCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIF9nZXQoX2dldFByb3RvdHlwZU9mKEFib3J0U2lnbmFsMi5wcm90b3R5cGUpLCAiZGlzcGF0Y2hFdmVudCIsIHRoaXMpLmNhbGwodGhpcywgZXZlbnQpOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gQWJvcnRTaWduYWwyOwogICAgICB9KEVtaXR0ZXIpOwogICAgICB2YXIgQWJvcnRDb250cm9sbGVyID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKCkgewogICAgICAgIGZ1bmN0aW9uIEFib3J0Q29udHJvbGxlcjIoKSB7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRDb250cm9sbGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgInNpZ25hbCIsIHsKICAgICAgICAgICAgdmFsdWU6IG5ldyBBYm9ydFNpZ25hbCgpLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEFib3J0Q29udHJvbGxlcjIsIFt7CiAgICAgICAgICBrZXk6ICJhYm9ydCIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWJvcnQocmVhc29uKSB7CiAgICAgICAgICAgIHZhciBldmVudDsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBldmVudCA9IG5ldyBFdmVudCgiYWJvcnQiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIGlmICh0eXBlb2YgZG9jdW1lbnQgIT09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICBpZiAoIWRvY3VtZW50LmNyZWF0ZUV2ZW50KSB7CiAgICAgICAgICAgICAgICAgIGV2ZW50ID0gZG9jdW1lbnQuY3JlYXRlRXZlbnRPYmplY3QoKTsKICAgICAgICAgICAgICAgICAgZXZlbnQudHlwZSA9ICJhYm9ydCI7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBldmVudCA9IGRvY3VtZW50LmNyZWF0ZUV2ZW50KCJFdmVudCIpOwogICAgICAgICAgICAgICAgICBldmVudC5pbml0RXZlbnQoImFib3J0IiwgZmFsc2UsIGZhbHNlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZXZlbnQgPSB7CiAgICAgICAgICAgICAgICAgIHR5cGU6ICJhYm9ydCIsCiAgICAgICAgICAgICAgICAgIGJ1YmJsZXM6IGZhbHNlLAogICAgICAgICAgICAgICAgICBjYW5jZWxhYmxlOiBmYWxzZQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIHNpZ25hbFJlYXNvbiA9IHJlYXNvbjsKICAgICAgICAgICAgaWYgKHNpZ25hbFJlYXNvbiA9PT0gdm9pZCAwKSB7CiAgICAgICAgICAgICAgaWYgKHR5cGVvZiBkb2N1bWVudCA9PT0gInVuZGVmaW5lZCIpIHsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbi5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRE9NRXhjZXB0aW9uKCJzaWduYWwgaXMgYWJvcnRlZCB3aXRob3V0IHJlYXNvbiIpOwogICAgICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgICAgc2lnbmFsUmVhc29uLm5hbWUgPSAiQWJvcnRFcnJvciI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuc2lnbmFsLnJlYXNvbiA9IHNpZ25hbFJlYXNvbjsKICAgICAgICAgICAgdGhpcy5zaWduYWwuZGlzcGF0Y2hFdmVudChldmVudCk7CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAidG9TdHJpbmciLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gIltv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c3QgPSBOYXRpdmVSZXF1ZXN0OwogICAgICAgIGlmIChSZXF1ZXN0ICYmICFSZXF1ZXN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eSgic2lnbmFsIikgfHwgX19GT1JDRV9JTlNUQUxMX0FCT1JUQ09OVFJPTExFUl9QT0xZRklMTCkgewogICAgICAgICAgUmVxdWVzdCA9IGZ1bmN0aW9uIFJlcXVlc3QyKGlucHV0LCBpbml0MikgewogICAgICAgICAgICB2YXIgc2lnbmFsOwogICAgICAgICAgICBpZiAoaW5pdDIgJiYgaW5pdDIuc2lnbmFsKSB7CiAgICAgICAgICAgICAgc2lnbmFsID0gaW5pdDIuc2lnbmFsOwogICAgICAgICAgICAgIGRlbGV0ZSBpbml0Mi5zaWduYWw7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIHJlcXVlc3QgPSBuZXcgTmF0aXZlUmVxdWVzdChpbnB1dCwgaW5pdDIpOwogICAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHJlcXVlc3QsICJzaWduYWwiLCB7CiAgICAgICAgICAgICAgICB3cml0YWJsZTogZmFsc2UsCiAgICAgICAgICAgICAgICBlbnVtZXJhYmxlOiBmYWxzZSwKICAgICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICAgIHZhbHVlOiBzaWduYWwKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gcmVxdWVzdDsKICAgICAgICAgIH07CiAgICAgICAgICBSZXF1ZXN0LnByb3RvdHlwZSA9IE5hdGl2ZVJlcXVlc3QucHJvdG90eXBlOwogICAgICAgIH0KICAgICAgICB2YXIgcmVhbEZldGNoID0gZmV0Y2gyOwogICAgICAgIHZhciBhYm9ydGFibGVGZXRjaCA9IGZ1bmN0aW9uIGFib3J0YWJsZUZldGNoMihpbnB1dCwgaW5pdDIpIHsKICAgICAgICAgIHZhciBzaWduYWwgPSBSZXF1ZXN0ICYmIFJlcXVlc3QucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoaW5wdXQpID8gaW5wdXQuc2lnbmFsIDogaW5pdDIgPyBpbml0Mi5zaWduYWwgOiB2b2lkIDA7CiAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgIHZhciBhYm9ydEVycm9yOwogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIGFib3J0RXJyb3IgPSBuZXcgRE9NRXhjZXB0aW9uKCJBYm9ydGVkIiwgIkFib3J0RXJyb3IiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgYWJvcnRFcnJvciA9IG5ldyBFcnJvcigiQWJvcnRlZCIpOwogICAgICAgICAgICAgIGFib3J0RXJyb3IubmFtZSA9ICJBYm9ydEVycm9yIjsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZWplY3QoYWJvcnRFcnJvcik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIGNhbmNlbGxhdGlvbiA9IG5ldyBQcm9taXNlKGZ1bmN0aW9uKF8sIHJlamVjdCkgewogICAgICAgICAgICAgIHNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsIGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmV0dXJuIHJlamVjdChhYm9ydEVycm9yKTsKICAgICAgICAgICAgICB9LCB7CiAgICAgICAgICAgICAgICBvbmNlOiB0cnVlCiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICBpZiAoaW5pdDIgJiYgaW5pdDIuc2lnbmFsKSB7CiAgICAgICAgICAgICAgZGVsZXRlIGluaXQyLnNpZ25hbDsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yYW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hYm9ydGVkISIpOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5zaWduYWxzLmFkZChzaWduYWwpOwogICAgICAgICAgaWYgKHNpZ25hbC5hYm9ydGVkKSB7CiAgICAgICAgICAgIHRoaXMuaGFuZGxlQWJvcnRlZChzaWduYWwpOwogICAgICAgICAgfSBlbHNlIGlmICh0eXBlb2Ygc2lnbmFsLmFkZEV2ZW50TGlzdGVuZXIgPT09ICJmdW5jdGlvbiIpIHsKICAgICAgICAgICAgc2lnbmFsLmFkZEV2ZW50TGlzdGVuZXIoImFib3J0IiwgKCkgPT4gewogICAgICAgICAgICAgIHRoaXMuaGFuZGxlQWJvcnRlZChzaWduYWwpOwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaGFuZGxlQWJvcnRlZChzaWduYWwpIHsKICAgICAgICAgIHRoaXMuc2lnbmFscy5kZWxldGUoc2lnbmFsKTsKICAgICAgICAgIGlmICh0aGlzLnNpZ25hbHMuc2l6ZSA9PT0gMCkgewogICAgICAgICAgICB0aGlzLmFib3J0Q29udHJvbGxlci5hYm9ydCgpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBnZXQgc2lnbmFsKCkgewogICAgICAgICAgcmV0dXJuIHRoaXMuYWJvcnRDb250cm9sbGVyLnNpZ25hbDsKICAgICAgICB9CiAgICAgICAgYWJvcnQoKSB7CiAgICAgICAgICB0aGlzLmFib3J0Q29udHJvbGxlci5hYm9ydCgpOwogICAgICAgIH0KICAgICAgfTsKICAgICAgZXhwb3J0cy5kZWZhdWx0ID0gQWdncmVnYXRlQWJvcnRDb250cm9sbGVyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vYWJvcnRhYmxlLXByb21pc2UtY2FjaGVAMS41LjAvbm9kZV9tb2R1bGVzL2Fib3J0YWJsZS1wcm9taXNlLWNhY2hlL2VzbS9BZ2dyZWdhdGVTdGF0dXNSZXBvcnRlci5qcwogIHZhciByZXF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ICAgICAgIGV2aWN0KGtleSwgZW50cnkpIHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmdldChrZXkpID09PSBlbnRyeSkgewogICAgICAgICAgICB0aGlzLmNhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmaWxsKGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjaykgewogICAgICAgICAgY29uc3QgYWJvcnRlciA9IG5ldyBBZ2dyZWdhdGVBYm9ydENvbnRyb2xsZXJfMS5kZWZhdWx0KCk7CiAgICAgICAgICBjb25zdCBzdGF0dXNSZXBvcnRlciA9IG5ldyBBZ2dyZWdhdGVTdGF0dXNSZXBvcnRlcl8xLmRlZmF1bHQoKTsKICAgICAgICAgIHN0YXR1c1JlcG9ydGVyLmFkZENhbGxiYWNrKHN0YXR1c0NhbGxiYWNrKTsKICAgICAgICAgIGNvbnN0IG5ld0VudHJ5ID0gewogICAgICAgICAgICBhYm9ydGVyLAogICAgICAgICAgICBwcm9taXNlOiB0aGlzLmZpbGxDYWxsYmFjayhkYXRhLCBhYm9ydGVyLnNpZ25hbCwgKG1lc3NhZ2UpID0+IHsKICAgICAgICAgICAgICBzdGF0dXNSZXBvcnRlci5jYWxsYmFjayhtZXNzYWdlKTsKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIHNldHRsZWQ6IGZhbHNlLAogICAgICAgICAgICBzdGF0dXNSZXBvcnRlciwKICAgICAgICAgICAgZ2V0IGFib3J0ZWQoKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuYWJvcnRlci5zaWduYWwuYWJvcnRlZDsKICAgICAgICAgICAgfQogICAgICAgICAgfTsKICAgICAgICAgIG5ld0VudHJ5LmFib3J0ZXIuYWRkU2lnbmFsKHNpZ25hbCk7CiAgICAgICAgICBuZXdFbnRyeS5hYm9ydGVyLnNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsICgpID0+IHsKICAgICAgICAgICAgaWYgKCFuZXdFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgdGhpcy5ldmljdChrZXksIG5ld0VudHJ5KTsKICAgICAgICAgICAgfQogICAgICAgICAgfSk7CiAgICAgICAgICBuZXdFbnRyeS5wcm9taXNlLnRoZW4oKCkgPT4gewogICAgICAgICAgICBuZXdFbnRyeS5zZXR0bGVkID0gdHJ1ZTsKICAgICAgICAgIH0sICgpID0+IHsKICAgICAgICAgICAgbmV3RW50cnkuc2V0dGxlZCA9IHRydWU7CiAgICAgICAgICAgIHRoaXMuZXZpY3Qoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgICB9KS5jYXRjaCgoZSkgPT4gewogICAgICAgICAgICBjb25zb2xlLmVycm9yKGUpOwogICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgfSk7CiAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIG5ld0VudHJ5KTsKICAgICAgICB9CiAgICAgICAgc3RhdGljIGNoZWNrU2luZ2xlUHJvbWlzZShwcm9taXNlLCBzaWduYWwpIHsKICAgICAgICAgIGZ1bmN0aW9uIGNoZWNrRm9yU2luZ2xlQWJvcnQoKSB7CiAgICAgICAgICAgIGlmIChzaWduYWwgJiYgc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICB0aHJvdyBPYmplY3QuYXNzaWduKG5ldyBFcnJvcigiYWJvcnRlZCIpLCB7IGNvZGU6ICJFUlJfQUJPUlRFRCIgfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBwcm9taXNlLnRoZW4oKHJlc3VsdCkgPT4gewogICAgICAgICAgICBjaGVja0ZvclNpbmdsZUFib3J0KCk7CiAgICAgICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgICAgICB9LCAoZXJyb3IpID0+IHsKICAgICAgICAgICAgY2hlY2tGb3JTaW5nbGVBYm9ydCgpOwogICAgICAgICAgICB0aHJvdyBlcnJvcjsKICAgICAgICAgI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AgICAgICAgICByZXR1cm4gQWJvcnRhYmxlUHJvbWlzZUNhY2hlMi5jaGVja1NpbmdsZVByb21pc2UoY2FjaGVFbnRyeS5wcm9taXNlLCBzaWduYWwpOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5maWxsKGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjayk7CiAgICAgICAgICByZXR1cm4gQWJvcnRhYmxlUHJvbWlzZUNhY2hlMi5jaGVja1NpbmdsZVByb21pc2UodGhpcy5jYWNoZS5nZXQoa2V5KS5wcm9taXNlLCBzaWduYWwpOwogICAgICAgIH0KICAgICAgICBkZWxldGUoa2V5KSB7CiAgICAgICAgICBjb25zdCBjYWNoZWRFbnRyeSA9IHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICBpZiAoY2FjaGVkRW50cnkpIHsKICAgICAgICAgICAgaWYgKCFjYWNoZWRFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgY2FjaGVkRW50cnkuYWJvcnRlci5hYm9ydCgpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuY2FjaGUuZGVsZXRlKGtleSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNsZWFyKCkgewogICAgICAgICAgY29uc3Qga2V5SXRlciA9IHRoaXMuY2FjaGUua2V5cygpOwogICAgICAgICAgbGV0IGRlbGV0ZUNvdW50ID0gMDsKICAgICAgICAgIGZvciAobGV0IHJlc3VsdCA9IGtleUl0ZXIubmV4dCgpOyAhcmVzdWx0LmRvbmU7IHJlc3VsdCA9IGtleUl0ZXIubmV4dCgpKSB7CiAgICAgICAgICAgIHRoaXMuZGVsZXRlKHJlc3VsdC52YWx1ZSk7CiAgICAgICAgICAgIGRlbGV0ZUNvdW50ICs9IDE7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gZGVsZXRlQ291bnQ7CiAgICAgICAgfQogICAgICB9OwogICAgICBleHBvcnRzLmRlZmF1bHQgPSBB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ogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9xdWljay1scnVAMi4wLjAvbm9kZV9tb2R1bGVzL3F1aWNrLWxydS9pbmRleC5qcyIoZXhwb3J0cywgbW9kdWxlKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgUXVpY2tMUlUzID0gY2xhc3MgewogICAgICAgIGNvbnN0cnVjdG9yKG9wdGlvbnMgPSB7fSkgewogICAgICAgICAgaWYgKCEob3B0aW9ucy5tYXhTaXplICYmIG9wdGlvbnMubWF4U2l6ZSA+IDApKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoImBtYXhTaXplYCBtdXN0IGJlIGEgbnVtYmVyIGdyZWF0ZXIgdGhhbiAwIik7CiAgICAgICAgICB9CiAgICAgICAgICB0aGlzLm1heFNpemUgPSBvcHRpb25zLm1heFNpemU7CiAgICAgICAgICB0aGlzLmNhY2hlID0gbmV3IE1hcCgpOwogICAgICAgICAgdGhpcy5vbGRDYWNoZSA9IG5ldyBNYXAoKTsKICAgICAgICAgIHRoaXMuX3NpemUgPSAwOwogICAgICAgIH0KICAgICAgICBfc2V0KGtleSwgdmFsdWUpIHsKICAgICAgICAgIHRoaXMuY2FjaGUuc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgdGhpcy5fc2l6ZSsrOwogICAgICAgICAgaWYgKHRoaXMuX3NpemUgPj0gdGhpcy5tYXhTaXplKSB7CiAgICAgICAgICAgIHRoaXMuX3NpemUgPSAwOwogICAgICAgICAgICB0aGlzLm9sZENhY2hlID0gdGhpcy5jYWNoZTsKICAgICAgICAgICAgdGhpcy5jYWNoZSA9IG5ldyBNYXAoKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZ2V0KGtleSkgewogICAgICAgICAgaWYgKHRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodGhpcy5vbGRDYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICBjb25zdCB2YWx1ZSA9IHRoaXMub2xkQ2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICAgIHRoaXMuX3NldChrZXksIHZhbHVlKTsKICAgICAgICAgICAgcmV0dXJuIHZhbHVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzZXQoa2V5LCB2YWx1ZSkgewogICAgICAgICAgaWYgKHRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgdGhpcy5jYWNoZS5zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLl9zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICB9CiAgICAgICAgaGFzKGtleSkgewogICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuaGFzKGtleSkgfHwgdGhpcy5vbGRDYWNoZS5oYXMoa2V5KTsKICAgICAgICB9CiAgICAgICAgcGVlayhrZXkpIHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzLmNhY2hlLmdldChrZXkpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHRoaXMub2xkQ2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXMub2xkQ2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRlbGV0ZShrZXkpIHsKICAgICAgICAgIGNvbnN0IGRlbGV0ZWQgPSB0aGlzLmNhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgaWYgKGRlbGV0ZWQpIHsKICAgICAgICAgICAgdGhpcy5fc2l6ZS0tOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHRoaXMub2xkQ2FjaGUuZGVsZXRlKGtleSkgfHwgZGVsZXRlZDsKICAgICAgICB9CiAgICAgICAgY2xlYXIoKSB7CiAgICAgICAgICB0aGlzLmNhY2hlLmNsZWFyKCk7CiAgICAgICAgICB0aGlzLm9sZENhY2hlLmNsZWFyKCk7CiAgICAgICAgICB0aGlzLl9zaXplID0gMDsKICAgICAgICB9CiAgICAgICAgKmtleXMoKSB7CiAgICAgICAgICBmb3IgKGNvbnN0IFtrZXldIG9mIHRoaXMpIHsKICAgICAgICAgICAgeWllbGQga2V5OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAqdmFsdWVzKCkgewogICAgICAgICAgZm9yIChjb25zdCBbLCB2YWx1ZV0gb2YgdGhpcykgewogICAgICAgICAgICB5aWVsZCB2YWx1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgKltTeW1ib2wuaXRlcmF0b3JdKCkgewogICAgICAgICAgZm9yIChjb25zdCBpdGVtIG9mIHRoaXMuY2FjaGUpIHsKICAgICAgICAgICAgeWllbGQgaXRlbTsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAoY29uc3QgaXRlbSBvZiB0aGlzLm9sZENhY2hlKSB7CiAgICAgICAgICAgIGNvbnN0IFtrZXldID0gaXRlbTsKICAgICAgICAgICAgaWYgKCF0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgICAgeWllbGQgaXRlbTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBnZXQgc2l6ZSgpIHsKICAgICAgICAgIGxldCBvbGRDYWNoZVNpemUgPSAwOwogICAgICAgICAgZm9yIChjb25zdCBrZXkgb2YgdGhpcy5vbGRDYWNoZS5rZXlzKCkpIHsKICAgICAgICAgICAgaWYgKCF0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgICAgb2xkQ2FjaGVTaXplKys7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiB0aG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E6ICJGb3JtRGF0YSIgaW4gc2VsZjIsCiAgICAgICAgICAgIGFycmF5QnVmZmVyOiAiQXJyYXlCdWZmZXIiIGluIHNlbGYyCiAgICAgICAgICB9OwogICAgICAgICAgZnVuY3Rpb24gaXNEYXRhVmlldyhvYmopIHsKICAgICAgICAgICAgcmV0dXJuIG9iaiAmJiBEYXRhVmlldy5wcm90b3R5cGUuaXNQcm90b3R5cGVPZihvYmopOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHN1cHBvcnQuYXJyYXlCdWZmZXIpIHsKICAgICAgICAgICAgdmFyIHZpZXdDbGFzc2VzID0gWwogICAgICAgICAgICAgICJbb2JqZWN0IEludDhBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IFVpbnQ4QXJyYXldIiwKICAgICAgICAgICAgICAiW29iamVjdCBVaW50OENsYW1wZWRBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEludDE2QXJyYXldIiwKICAgICAgICAgICAgICAiW29iamVjdCBVaW50MTZBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEludDMyQXJyYXldIiwKICAgICAgICAgICAgICAiW29iamVjdCBVaW50MzJBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEZsb2F0MzJBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEZsb2F0NjRBcnJheV0iCiAgICAgICAgICAgIF07CiAgICAgICAgICAgIHZhciBpc0FycmF5QnVmZmVyVmlldyA9IEFycmF5QnVmZmVyLmlzVmlldyB8fCBmdW5jdGlvbihvYmopIHsKICAgICAgICAgICAgICByZXR1cm4gb2JqICYmIHZpZXdDbGFzc2VzLmluZGV4T2YoT2JqZWN0LnByb3RvdHlwZS50b1N0cmluZy5jYWxsKG9iaikpID4gLTE7CiAgICAgICAgICAgIH07CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBub3JtYWxpemVOYW1lKG5hbWUpIHsKICAgICAgICAgICAgaWYgKHR5cGVvZiBuYW1lICE9PSAic3RyaW5nIikgewogICAgICAgICAgICAgIG5hbWUgPSBTdHJpbmcobmFtZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKC9bXmEtejAtOVwtIyQlJicqKy5eX2B8fl0vaS50ZXN0KG5hbWUpKSB7CiAgICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiSW52YWxpZCBjaGFyYWN0ZXIgaW4gaGVhZGVyIGZpZWxkIG5hbWUiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gbmFtZS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gbm9ybWFsaXplVmFsdWUodmFsdWUpIHsKICAgICAgICAgICAgaWYgKHR5cGVvZiB2YWx1ZSAhPT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICB2YWx1ZSA9IFN0cmluZyh2YWx1ZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIHZhbHVlOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gaXRlcmF0b3JGb3IoaXRlbXMpIHsKICAgICAgICAgICAgdmFyIGl0ZXJhdG9yID0gewogICAgICAgICAgICAgIG5leHQ6IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgdmFyIHZhbHVlID0gaXRlbXMuc2hpZnQoKTsKICAgICAgICAgICAgICAgIHJldHVybiB7IGRvbmU6IHZhbHVlID09PSB2b2lkIDAsIHZhbHVlIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9OwogICAgICAgICAgICBpZiAoc3VwcG9ydC5pdGVyYWJsZSkgewogICAgICAgICAgICAgIGl0ZXJhdG9yW1N5bWJvbC5pdGVyYXRvcl0gPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJldHVybiBpdGVyYXRvcjsKICAgICAgICAgICAgICB9OwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBpdGVyYXRvcjsKICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIEhlYWRlcnMoaGVhZGVycykgewogICAgICAgICAgICB0aGlzLm1hcCA9IHt9OwogICAgICAgICAgICBpZiAoaGVhZGVycyBpbnN0YW5jZW9mIEhlYWRlcnMpIHsKICAgICAgICAgICAgICBoZWFkZXJzLmZvckVhY2goZnVuY3Rpb24odmFsdWUsIG5hbWUpIHsKICAgICAgICAgICAgICAgIHRoaXMuYXBwZW5kKG5hbWUsIHZhbHVlKTsKICAgICAgICAgICAgICB9LCB0aGlzKTsKICAgICAgICAgICAgfSBlbHNlIGlmIChBcnJheS5pc0FycmF5KGhlYWRlcnMpKSB7CiAgICAgICAgICAgICAgaGVhZGVycy5mb3JFYWNoKGZ1bmN0aW9uKGhlYWRlcikgewogICAgICAgICAgICAgICAgdGhpcy5hcHBlbmQoaGVhZGVyWzBdLCBoZWFkZXJbMV0pOwogICAgICAgICAgICAgIH0sIHRoaXMpOwogICAgICAgICAgICB9IGVsc2UgaWYgKGhlYWRlcnMpIHsKICAgICAgICAgICAgICBPYmplY3QuZ2V0T3duUHJvcGVydHlOYW1lcyhoZWFkZXJzKS5mb3JFYWNoKGZ1bmN0aW9uKG5hbWUpIHsKICAgICAgICAgICAgICAgIHRoaXMuYXBwZW5kKG5hbWUsIGhlYWRlcnNbbmFtZV0pOwogICAgICAgICAgICAgIH0sIHRoaXMpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBIZWFkZXJzLnByb3RvdHlwZS5hcHBlbmQgPSBmdW5jdGlvbihuYW1lLCB2YWx1ZSkgewogICAgICAgICAgICBuYW1lID0gbm9ybWFsaXplTmFtZShuYW1lKTsKICAgICAgICAgICAgdmFsdWUgPSBub3JtYWxpemVWYWx1ZSh2YWx1ZSk7CiAgICAgICAgICAgIHZhciBvbGRWYWx1ZSA9IHRoaXMubWFwW25hbWVdOwogICAgICAgICAgICB0aGlzLm1hcFtuYW1lXSA9IG9sZFZhbHVlID8gb2xkVmFsdWUgKyAiLCAiICsgdmFsdWUgOiB2YWx1ZTsKICAgICAgICAgIH07CiAgICAgICAgICBIZWFkZXJzLnByb3RvdHlwZVsiZGVsZXRlIl0gPSBmdW5jdGlvbihuYW1lKSB7CiAgICAgICAgICAgIGRlbGV0ZSB0aGlzLm1hcFtub3JtYWxpemVOYW1lKG5hbWUpXTsKICAgICAgICAgIH07CiAgICAgICAgICBIZWFkZXJzLnByb3RvdHlwZS5nZXQgPSBmdW5jdGlvbihuYW1lKSB7CiAgICAgICAgICAgIG5hbWUgPSBub3JtYWxpemVOYW1lKG5hbWUpOwogICAgICAgICAgICByZXR1cm4gdGhpcy5oYXMobmFtZSkgPyB0aGlzLm1hcFtuYW1lXSA6IG51bGw7CiAgICAgICAgICB9OwogICAgICAgICAgSGVhZGVycy5wcm90b3R5cGUuaGFzID0gZnVuY3Rpb24obmFtZSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5tYXAuaGFzT3duUHJvcGVydHkobm9ybWFsaXplTmFtZShuYW1lKSk7CiAgICAgICAgICB9OwogICAgICAgICAgSGVhZGVycy5wcm90b3R5cGUuc2V0ID0gZnVuY3Rpb24obmFtZSwgdmFsdWUpIHsKICAgICAgICAgICAgdGhpcy5tYXBbbm9ybWFsaXplTmFtZShuYW1lKV0gPSBub3JtYWxpemVWYWx1ZSh2YWx1ZSk7CiAgICAgICAgICB9OwogICAgICAgICAgSGVhZGVycy5wcm90b3R5cGUuZm9yRWFjaCA9IGZ1bmN0aW9uKGNhbGxiYWNrLCB0aGlzQXJnKSB7CiAgICAgICAgICAgIGZvciAodmFyIG5hbWUgaW4gdGhpcy5tYXApIHsKICAgICAgICAgICAgICBpZiAodGhpcy5tYXAuaGFzT3duUHJvcGVydHkobmFtZSkpIHsKICAgICAgICAgICAgICAgIGNhbGxiYWNrLmNhbGwodGhpc0FyZywgdGhpcy5tYXBbbmFtZV0sIG5hbWUsIHRoaXMpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfTsKICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlLmtleXMgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgdmFyIGl0ZW1zID0gW107CiAgICAgICAgICAgIHRoaXMuZm9yRWFjaChmdW5jdGlvbih2YWx1ZSwgbmFtZSkgewogICAgICAgICAgICAgIGl0ZW1zLnB1c2gobmFtZSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaXRlcmF0b3JGb3IoaXRlbXMpOwogICAgICAgICAgfTsKICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlLnZhbHVlcyA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICB2YXIgaXRlbXMgPSBbXTsKICAgICAgICAgICAgdGhpcy5mb3JFYWNoKGZ1bmN0aW9uKHZhbHVlKSB7CiAgICAgICAgICAgICAgaXRlbXMucHVzaCh2YWx1ZSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaXRlcmF0b3JGb3IoaXRlbXMpOwogICAgICAgICAgfTsKICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlLmVudHJpZXMgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgdmFyIGl0ZW1zID0gW107CiAgICAgICAgICAgIHRoaXMuZm9yRWFjaChmdW5jdGlvbih2YWx1ZSwgbmFtZSkgewogICAgICAgICAgICAgIGl0ZW1zLnB1c2goW25hbWUsIHZhbHVlXSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaXRlcmF0b3JGb3IoaXRlbXMpOwogICAgICAgICAgfTsKICAgICAgICAgIGlmIChzdXBwb3J0Lml0ZXJhYmxlKSB7CiAgICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlW1N5bWJvbC5pdGVyYXRvcl0gPSBIZWFkZXJzLnByb3RvdHlwZS5lbnRyaWVzOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gY29uc3VtZWQoYm9keSkgewogICAgICAgICAgICBpZiAoYm9keS5ib2R5VXNlZCkgewogICAgICAgICAgICAgIHJldHVybiBQcm9taXNlLnJlamVjdChuZXcgVHlwZUVycm9yKCJBbHJlYWR5IHJlYWQiKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYm9keS5ib2R5VXNlZCA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBmaWxlUmVhZGVyUmVhZHkocmVhZGVyKSB7CiAgICAgICAgICAgIHJldHVybiBuZXcgUHJvbWlzZShmdW5jdGlvbihyZXNvbHZlLCByZWplY3QpIHsKICAgICAgICAgICAgICByZWFkZXIub25sb2FkID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICByZXNvbHZlKHJlYWRlci5yZXN1bHQpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgcmVhZGVyLm9uZXJyb3IgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJlamVjdChyZWFkZXIuZXJyb3IpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgIH0pOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gcmVhZEJsb2JBc0FycmF5QnVmZmVyKGJsb2IpIHsKICAgICAgICAgICAgdmFyIHJlYWRlciA9IG5ldyBGaWxlUmVhZGVyKCk7CiAgICAgICAgICAgIHZhciBwcm9taXNlID0gZmlsZVJlYWRlclJlYWR5KHJlYWRlcik7CiAgICAgICAgICAgIHJlYWRlci5yZWFkQXNBcnJheUJ1ZmZlcihibG9iKTsKICAgICAgICAgICAgcmV0dXJuIHByb21pc2U7CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiByZWFkQmxvYkFzVGV4dChibG9iKSB7CiAgICAgICAgICAgIHZhciByZWFkZXIgPSBuZXcgRmlsZVJlYWRlcigpOwogICAgICAgICAgICB2YXIgcHJvbWlzZSA9IGZpbGVSZWFkZXJSZWFkeShyZWFkZXIpOwogICAgICAgICAgICByZWFkZXIucmVhZEFzVGV4dChibG9iKTsKICAgICAgICAgICAgcmV0dXJuIHByb21pc2U7CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiByZWFkQXJyYXlCdWZmZXJBc1RleHQoYnVmKSB7CiAgICAgICAgICAgIHZhciB2aWV3ID0gbmV3IFVpbnQ4QXJyYXkoYnVmKTsKICAgICAgICAgICAgdmFyIGNoYXJzID0gbmV3IEFycmF5KHZpZXcubGVuZ3RoKTsKICAgICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCB2aWV3Lmxlbmd0aDsgaSsrKSB7CiAgICAgICAgICAgICAgY2hhcnNbaV0gPSBTdHJpbmcuZnJvbUNoYXJDb2RlKHZpZXdbaV0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBjaGFycy5qb2luKCIiKTsKICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIGJ1ZmZlckNsb25lKGJ1ZikgewogICAgICAgICAgICBpZiAoYnVmLnNsaWNlKSB7CiAgICAgICAgICAgICAgcmV0dXJuIGJ1Zi5zbGljZSgwKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICB2YXIgdmlldyA9IG5ldyBVaW50OEFycmF5KGJ1Zi5ieXRlTGVuZ3RoKTsKICAgICAgICAgICAgICB2aWV3LnNldChuZXcgVWludDhBcnJheShidWYpKTsKICAgICAgICAgICAgICByZXR1cm4gdmlldy5idWZmZXI7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIEJvZHkoKSB7CiAgICAgICAgICAgIHRoaXMuYm9keVVzZWQgPSBmYWxzZTsKICAgICAgICAgICAgdGhpcy5faW5pdEJvZHkgPSBmdW5jdGlvbihib2R5KSB7CiAgICAgICAgICAgICAgdGhpcy5fYm9keUluaXQgPSBib2R5OwogICAgICAgICAgICAgIGlmICghYm9keSkgewogICAgICAgICAgICAgICAgdGhpcy5fYm9keVRleHQgPSAiIjsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBib2R5ID09PSAic3RyaW5nIikgewogICAgICAgICAgICAgICAgdGhpcy5fYm9keVRleHQgPSBib2R5OwogICAgICAgICAgICAgIH0gZWxzZSBpZiAoc3VwcG9ydC5ibG9iICYmIEJsb2IucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlCbG9iID0gYm9keTsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKHN1cHBvcnQuZm9ybURhdGEgJiYgRm9ybURhdGEucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlGb3JtRGF0YSA9IGJvZHk7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdXBwb3J0LnNlYXJjaFBhcmFtcyAmJiBVUkxTZWFyY2hQYXJhbXMucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlUZXh0ID0gYm9keS50b1N0cmluZygpOwogICAgICAgICAgICAgIH0gZWxzZSBpZiAoc3VwcG9ydC5hcnJheUJ1ZmZlciAmJiBzdXBwb3J0LmJsb2IgJiYgaXNEYXRhVmlldyhib2R5KSkgewogICAgICAgICAgICAgICAgdGhpcy5fYm9keUFycmF5QnVmZmVyID0gYnVmZmVyQ2xvbmUoYm9keS5idWZmZXIpOwogICAgICAgICAgICAgICAgdGhpcy5fYm9keUluaXQgPSBuZXcgQmxvYihbdGhpcy5fYm9keUFycmF5QnVmZmVyXSk7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdXBwb3J0LmFycmF5QnVmZmVyICYmIChBcnJheUJ1ZmZlci5wcm90b3R5cGUuaXNQcm90b3R5cGVPZihib2R5KSB8fCBpc0FycmF5QnVmZmVyVmlldyhib2R5KSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlBcnJheUJ1ZmZlciA9IGJ1ZmZlckNsb25lKGJvZHkpOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0aGlzLl9ib2R5VGV4dCA9IGJvZHkgPSBPYmplY3QucHJvdG90eXBlLnRvU3RyaW5nLmNhbGwoYm9keSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmICghdGhpcy5oZWFkZXJzLmdldCgiY29udGVudC10eXBlIikpIHsKICAgICAgICAgICAgICAgIGlmICh0eXBlb2YgYm9keSA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICAgICAgdGhpcy5oZWFkZXJzLnNldCgiY29udGVudC10eXBlIiwgInRleHQvcGxhaW47Y2hhcnNldD1VVEYtOCIpOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmICh0aGlzLl9ib2R5QmxvYiAmJiB0aGlzLl9ib2R5QmxvYi50eXBlKSB7CiAgICAgICAgICAgICAgICAgIHRoaXMuaGVhZGVycy5zZXQoImNvbnRlbnQtdHlwZSIsIHRoaXMuX2JvZHlCbG9iLnR5cGUpOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdXBwb3J0LnNlYXJjaFBhcmFtcyAmJiBVUkxTZWFyY2hQYXJhbXMucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgICAgdGhpcy5oZWFkZXJzLnNldCgiY29udGVudC10eXBlIiwgImFwcGxpY2F0aW9uL3gtd3d3LWZvcm0tdXJsZW5jb2RlZDtjaGFyc2V0PVVURi04Iik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9OwogICAgICAgICAgICBpZiAoc3VwcG9ydC5ibG9iKSB7CiAgICAgICAgICAgICAgdGhpcy5ibG9iID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICB2YXIgcmVqZWN0ZWQgPSBjb25zdW1lZCh0aGlzKTsKICAgICAgICAgICAgICAgIGlmIChyZWplY3RlZCkgewogICAgICAgICAgICAgICAgICByZXR1cm4gcmVqZWN0ZWQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAodGhpcy5fYm9keUJsb2IpIHsKICAgICAgICAgICAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZSh0aGlzLl9ib2R5QmxvYik7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX2JvZHlBcnJheUJ1ZmZlcikgewogICAgICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZXNvbHZlKG5ldyBCbG9iKFt0aGlzLl9ib2R5QXJyYXlCdWZmZXJdKSk7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX2JvZHlGb3JtRGF0YSkgewogICAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImNvdWxkIG5vdCByZWFkIEZvcm1EYXRhIGJvZHkgYXMgYmxvYiIpOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZShuZXcgQmxvYihbdGhpcy5fYm9keVRleHRdKSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB0aGlzLmFycmF5QnVmZmVyID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICBpZiAodGhpcy5fYm9keUFycmF5QnVmZmVyKSB7CiAgICAgICAgICAgICAgICAgIHJldHVybiBjb25zdW1lZCh0aGlzKSB8fCBQcm9taXNlLnJlc29sdmUodGhpcy5fYm9keUFycmF5QnVmZmVyKTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLmJsb2IoKS50aGVuKHJlYWRCbG9iQXNBcnJheUJ1ZmZlcik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLnRleHQgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICB2YXIgcmVqZWN0ZWQgPSBjb25zdW1lZCh0aGlzKTsKICAgICAgICAgICAgICBpZiAocmVqZWN0ZWQpIHsKICAgICAgICAgICAgICAgIHJldHVybiByZWplY3RlZDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHRoaXMuX2JvZHlCbG9iKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gcmVhZEJsb2JBc1RleHQodGhpcy5fYm9keUJsb2IpOwogICAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5fYm9keUFycmF5QnVmZmVyKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZXNvbHZlKHJlYWRBcnJheUJ1ZmZlckFzVGV4dCh0aGlzLl9ib2R5QXJyYXlCdWZmZXIpKTsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX2JvZHlGb3JtRGF0YSkgewogICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJjb3VsZCBub3QgcmVhZCBGb3JtRGF0YSBib2R5IGFzIHRleHQiKTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZSh0aGlzLl9ib2R5VGV4dCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9OwogICAgICAgICAgICBpZiAoc3VwcG9ydC5mb3JtRGF0YSkgewogICAgICAgICAgICAgIHRoaXMuZm9ybURhdGEgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLnRleHQoKS50aGVuKGRlY29kZSk7CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLmpzb24gPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICByZXR1cm4gdGhpcy50ZXh0KCkudGhlbihKU09OLnBhcnNlKTsKICAgICAgICAgICAgfTsKICAgICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgICB9CiAgICAgICAgICB2YXIgbWV0aG9kcyA9IFsiREVMRVRFIiwgIkdFVCIsICJIRUFEIiwgIk9QVElPTlMiLCAiUE9TVCIsICJQVVQiXTsKICAgICAgICAgIGZ1bmN0aW9uIG5vcm1hbGl6ZU1ldGhvZChtZXRob2QpIHsKICAgICAgICAgICAgdmFyIHVwY2FzZWQgPSBtZXRob2QudG9VcHBlckNhc2UoKTsKICAgICAgICAgICAgcmV0dXJuIG1ldGhvZHMuaW5kZXhPZih1cGNhc2VkKSA+IC0xID8gdXBjYXNlZCA6IG1ldGhvZDsKICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIFJlcXVlc3QoaW5wdXQsIG9wdGlvbnMpIHsKICAgICAgICAgICAgb3B0aW9ucyA9IG9wdGlvbnMgfHwge307CiAgICAgICAgICAgIHZhciBib2R5ID0gb3B0aW9ucy5ib2R5OwogICAgICAgICAgICBpZiAoaW5wdXQgaW5zdGFuY2VvZiBSZXF1ZXN0KSB7CiAgICAgICAgICAgICAgaWYgKGlucHV0LmJvZHlVc2VkKSB7CiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJBbHJlYWR5IHJlYWQiKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgdGhpcy51cmwgPSBpbnB1dC51cmw7CiAgICAgICAgICAgICAgdGhpcy5jcmVkZW50aWFscyA9IGlucHV0LmNyZWRlbnRpYWxzOwogICAgICAgICAgICAgIGlmICghb3B0aW9ucy5oZWFkZXJzKSB7CiAgICAgICAgICAgICAgICB0aGlzLmhlYWRlcnMgPSBuZXcgSGVhZGVycyhpbnB1dC5oZWFkZXJzKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgdGhpcy5tZXRob2QgPSBpbnB1dC5tZXRob2Q7CiAgICAgICAgICAgICAgdGhpcy5tb2RlID0gaW5wdXQubW9kZTsKICAgICAgICAgICAgICB0aGlzLnNpZ25hbCA9IGlucHV0LnNpZ25hbDsKICAgICAgICAgICAgICBpZiAoIWJvZHkgJiYgaW5wdXQuX2JvZHlJbml0ICE9IG51bGwpIHsKICAgICAgICAgICAgICAgIGJvZHkgPSBpbnB1dC5fYm9keUluaXQ7CiAgICAgICAgICAgICAgICBpbnB1dC5ib2R5VXNlZCA9IHRydWU7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHRoaXMudXJsID0gU3RyaW5nKGlucHV0KTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLmNyZWRlbnRpYWxzID0gb3B0aW9ucy5jcmVkZW50aWFscyB8fCB0aGlzLmNyZWRlbnRpYWxzIHx8ICJzYW1lLW9yaWdpbiI7CiAgICAgICAgICAgIGlmIChvcHRpb25zLmhlYWRlcnMgfHwgIXRoaXMuaGVhZGVycykgewogICAgICAgICAgICAgIHRoaXMuaGVhZGVycyA9IG5ldyBIZWFkZXJzKG9wdGlvbnMuaGVhZGVycyk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5tZXRob2QgPSBub3JtYWxpemVNZXRob2Qob3B0aW9ucy5tZXRob2QgfHwgdGhpcy5tZXRob2QgfHwgIkdFVCIpOwogICAgICAgICAgICB0aGlzLm1vZGUgPSBvcHRpb25zLm1vZGUgfHwgdGhpcy5tb2RlIHx8IG51bGw7CiAgICAgICAgICAgIHRoaXMuc2lnbmFsID0gb3B0aW9ucy5zaWduYWwgfHwgdGhpcy5zaWduYWw7CiAgICAgICAgICAgIHRoaXMucmVmZXJyZXIgPSBudWxsOwogICAgICAgICAgICBpZiAoKHRoaXMubWV0aG9kID09PSAiR0VUIiB8fCB0aGlzLm1ldGhvZCA9PT0gIkhFQUQiKSAmJiBib2R5KSB7CiAgICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiQm9keSBub3QgYWxsb3dlZCBmb3IgR0VUIG9yIEhFQUQgcmVxdWVzdHMiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLl9pbml0Qm9keShib2R5KTsKICAgICAgICAgIH0KICAgICAgICAgIFJlcXVlc3QucHJvdG90eXBlLmNsb25lID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgIHJldHVybiBuZXcgUmVxdWVzdCh0aGlzLCB7IGJvZHk6IHRoaXMuX2JvZHlJbml0IH0pOwogICAgICAgICAgfTsKICAgICAgICAgIGZ1bmN0aW9uIGRlY29kZShib2R5KSB7CiAgICAgICAgICAgIHZhciBmb3JtID0gbmV3IEZvcm1EYXRhKCk7CiAgICAgICAgICAgIGJvZHkudHJpbSgpLnNwbGl0KCImIikuZm9yRWFjaChmdW5jdGlvbihieXRlcykgewogICAgICAgICAgICAgIGlmIChieXRlcykgewogICAgICAgICAgICAgICAgdmFyIHNwbGl0ID0gYnl0ZXMuc3BsaXQoIj0iKTsKICAgICAgICAgICAgICAgIHZhciBuYW1lID0gc3BsaXQuc2hpZnQoKS5yZXBsYWNlKC9cKy9nLCAiICIpOwogICAgICAgICAgICAgICAgdmFyIHZhbHVlID0gc3BsaXQuam9pbigiPSIpLnJlcGxhY2UoL1wrL2csICIgIik7CiAgICAgICAgICAgICAgICBmb3JtLmFwcGVuZChkZWNvZGVVUklDb21wb25lbnQobmFtZSksIGRlY29kZVVSSUNvbXBvbmVudCh2YWx1ZSkpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIHJldHVybiBmb3JtOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gcGFyc2VIZWFkZXJzKHJhd0hlYWRlcnMpIHsKICAgICAgICAgICAgdmFyIGhlYWRlcnMgPSBuZXcgSGVhZGVycygpOwogICAgICAgICAgICB2YXIgcHJlUHJvY2Vzc2VkSGVhZGVycyA9IHJhd0hlYWRlcnMucmVwbGFjZSgvXHI/XG5bXHQgXSsvZywgIiAiKTsKICAgICAgICAgICAgcHJlUHJvY2Vzc2VkSGVhZGVycy5zcGxpdCgvXHI/XG4vKS5mb3JFYWNoKGZ1bmN0aW9uKGxpbmUpIHsKICAgICAgICAgICAgICB2YXIgcGFydHMgPSBsaW5lLnNwbGl0KCI6Iik7CiAgICAgICAgICAgICAgdmFyIGtleSA9IHBhcnRzLnNoaWZ0KCkudHJpbSgpOwogICAgICAgICAgICAgIGlmIChrZXkpIHsKICAgICAgICAgICAgICAgIHZhciB2YWx1ZSA9IHBhcnRzLmpvaW4oIjoiKS50cmltKCk7CiAgICAgICAgICAgICAgICBoZWFkZXJzLmFwcGVuZChrZXksIHZhbHVlKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaGVhZGVyczsKICAgICAgICAgIH0KICAgICAgICAgIEJvZHkuY2FsbChSZXF1ZXN0LnByb3RvdHlwZSk7CiAgICAgICAgICBmdW5jdGlvbiBSZXNwb25zZShib2R5SW5pdCwgb3B0aW9ucykgewogICAgICAgICAgICBpZiAoIW9wdGlvbnMpIHsKICAgICAgICAgICAgICBvcHRpb25zID0ge307CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy50eXBlID0gImRlZmF1bHQiOwogICAgICAgICAgICB0aGlzLnN0YXR1cyA9IG9wdGlvbnMuc3RhdHVzID09PSB2b2lkIDAgPyAyMDAgOiBvcHRpb25zLnN0YXR1czsKICAgICAgICAgICAgdGhpcy5vayA9IHRoaXMuc3RhdHVzID49IDIwMCAmJiB0aGlzLnN0YXR1cyA8IDMwMDsKICAgICAgICAgICAgdGhpcy5zdGF0dXNUZXh0ID0gInN0YXR1c1RleHQiIGluIG9wdGlvbnMgPyBvcHRpb25zLnN0YXR1c1RleHQgOiAiT0siOwogICAgICAgICAgICB0aGlzLmhlYWRlcnMgPSBuZXcgSGVhZGVycyhvcHRpb25zLmhlYWRlcnMpOwogICAgICAgICAgICB0aGlzLnVybCA9IG9wdGlvbnMudXJsIHx8ICIiOwogICAgICAgICAgICB0aGlzLl9pbml0Qm9keShib2R5SW5pdCk7CiAgICAgICAgICB9CiAgICAgICAgICBCb2R5LmNhbGwoUmVzcG9uc2UucHJvdG90eXBlKTsKICAgICAgICAgIFJlc3BvbnNlLnByb3RvdHlwZS5jbG9uZSA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICByZXR1cm4gbmV3IFJlc3BvbnNlKHRoaXMuX2JvZHlJbml0LCB7CiAgICAgICAgICAgICAgc3RhdHVzOiB0aGlzLnN0YXR1cywKICAgICAgICAgICAgICBzdGF0dXNUZXh0OiB0aGlzLnN0YXR1c1RleHQsCiAgICAgICAgICAgICAgaGVhZGVyczogbmV3IEhlYWRlcnModGhpcy5oZWFkZXJzKSwKICAgICAgICAgICAgICB1cmw6IHRoaXMudXJsCiAgICAgICAgICAgIH0pOwogICAgICAgICAgfTsKICAgICAgICAgIFJlc3BvbnNlLmVycm9yID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgIHZhciByZXNwb25zZSA9IG5ldyBSZXNwb25zZShudWxsLCB7IHN0YXR1czogMCwgc3RhdHVzVGV4dDogIiIgfSk7CiAgICAgICAgICAgIHJlc3BvbnNlLnR5cGUgPSAiZXJyb3IiOwogICAgICAgICAgICByZXR1cm4gcmVzcG9uc2U7CiAgICAgICAgICB9OwogICAgICAgICAgdmFyIHJlZGlyZWN0U3RhdHVzZXMgPSBbMzAxLCAzMDIsIDMwMywgMzA3LCAzMDhdOwogICAgICAgICAgUmVzcG9uc2UucmVkaXJlY3QgPSBmdW5jdGlvbih1cmwsIHN0YXR1cykgewogICAgICAgICAgICBpZiAocmVkaXJlY3RTdGF0dXNlcy5pbmRleE9mKHN0YXR1cykgPT09IC0xKSB7CiAgICAgICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkludmFsaWQgc3RhdHVzIGNvZGUiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gbmV3IFJlc3BvbnNlKG51bGwsIHsgc3RhdHVzLCBoZWFkZXJzOiB7IGxvY2F0aW9uOiB1cmwgfSB9KTsKICAgICAgICAgIH07CiAgICAgICAgICBleHBvcnRzMi5ET01FeGNlcHRpb24gPSBzZWxmMi5ET01FeGNlcHRpb247CiAgICAgICAgICB0cnkgewogICAgICAgICAgICBuZXcgZXhwb3J0czIuRE9NRXhjZXB0aW9uKCk7CiAgICAgICAgICB9IGNhdGNoIChlcnIpIHsKICAgICAgICAgICAgZXhwb3J0czIuRE9NRXhjZXB0aW9uID0gZnVuY3Rpb24obWVzc2FnZSwgbmFtZSkgewogICAgICAgICAgICAgIHRoaXMubWVzc2FnZSA9IG1lc3NhZ2U7CiAgICAgICAgICAgICAgdGhpcy5uYW1lID0gbmFtZTsKICAgICAgICAgICAgICB2YXIgZXJyb3IgPSBFcnJvcihtZXNzYWdlKTsKICAgICAgICAgICAgICB0aGlzLnN0YWNrID0gZXJyb3Iuc3RhY2s7CiAgICAgICAgICAgIH07CiAgICAgICAgICAgIGV4cG9ydHMyLkRPTUV4Y2VwdGlvbi5wcm90b3R5cGUgPSBPYmplY3QuY3JlYXRlKEVycm9yLnByb3RvdHlwZSk7CiAgICAgICAgICAgIGV4cG9ydHMyLkRPTUV4Y2VwdGlvbi5wcm90b3R5cGUuY29uc3RydWN0b3IgPSBleHBvcnRzMi5ET01FeGNlcHRpb247CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBmZXRjaDIoaW5wdXQsIGluaXQyKSB7CiAgICAgICAgICAgIHJldHVybiBuZXcgUHJvbWlzZShmdW5jdGlvbihyZXNvbHZlLCByZWplY3QpIHsKICAgICAgICAgICAgICB2YXIgcmVxdWVzdCA9IG5ldyBSZXF1ZXN0KGlucHV0LCBpbml0Mik7CiAgICAgICAgICAgICAgaWYgKHJlcXVlc3Quc2lnbmFsICYmIHJlcXVlc3Quc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICAgIHJldHVybiByZWplY3QobmV3IGV4cG9ydHMyLkRPTUV4Y2VwdGlvbigiQWJvcnRlZCIsICJBYm9ydEVycm9yIikpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB2YXIgeGhyID0gbmV3IFhNTEh0dHBSZXF1ZXN0KCk7CiAgICAgICAgICAgICAgZnVuY3Rpb24gYWJvcnRYaHIoKSB7CiAgICAgICAgICAgICAgICB4aHIuYWJvcnQoKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgeGhyLm9ubG9hZCA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgdmFyIG9wdGlvbnMgPSB7CiAgICAgICAgICAgICAgICAgIHN0YXR1czogeGhyLnN0YXR1cywKICAgICAgICAgICAgICAgICAgc3RhdHVzVGV4dDogeGhyLnN0YXR1c1RleHQsCiAgICAgICAgICAgICAgICAgIGhlYWRlcnM6IHBhcnNlSGVhZGVycyh4aHIuZ2V0QWxsUmVzcG9uc2VIZWFkZXJzKCkgfHwgIiIpCiAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICAgICAgb3B0aW9ucy51cmwgPSAicmVzcG9uc2VVUkwiIGluIHhociA/IHhoci5yZXNwb25zZVVSTCA6IG9wdGlvbnMuaGVhZGVycy5nZXQoIlgtUmVxdWVzdC1VUkwiKTsKICAgICAgICAgICAgICAgIHZhciBib2R5ID0gInJlc3BvbnNlIiBpbiB4aHIgPyB4aHIucmVzcG9uc2UgOiB4aHIucmVzcG9uc2VUZXh0OwogICAgICAgICAgICAgICAgcmVzb2x2ZShuZXcgUmVzcG9uc2UoYm9keSwgb3B0aW9ucykpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgeGhyLm9uZXJyb3IgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJlamVjdChuZXcgVHlwZUVycm9yKCJOZXR3b3JrIHJlcXVlc3QgZmFpbGVkIikpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgeGhyLm9udGltZW91dCA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmVqZWN0KG5ldyBUeXBlRXJyb3IoIk5ldHdvcmsgcmVxdWVzdCBmYWlsZWQiKSk7CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB4aHIub25hYm9ydCA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmVqZWN0KG5ldyBleHBvcnRzMi5ET01FeGNlcHRpb24oIkFib3J0ZWQiLCAiQWJvcnRFcnJvciIpKTsKICAgICAgICAgICAgICB9OwogICAgICAgICAgICAgIHhoci5vcGVuKHJlcXVlc3QubWV0aG9kLCByZXF1ZXN0LnVybCwgdHJ1ZSk7CiAgICAgICAgICAgICAgaWYgKHJlcXVlc3QuY3JlZGVudGlhbHMgPT09ICJpbmNsdWRlIikgewogICAgICAgICAgICAgICAgeGhyLndpdGhDcmVkZW50aWFscyA9IHRydWU7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChyZXF1ZXN0LmNyZWRlbnRpYWxzID09PSAib21pdCIpIHsKICAgICAgICAgICAgICAgIHhoci53aXRoQ3JlZGVudGlhbHMgPSBmYWxzZTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKCJyZXNwb25zZVR5cGUiIGluIHhociAmJiBzdXBwb3J0LmJsb2IpIHsKICAgICAgICAgICAgICAgIHhoci5yZXNwb25zZVR5cGUgPSAiYmxvYiI7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHJlcXVlc3QuaGVhZGVycy5mb3JFYWNoKGZ1bmN0aW9uKHZhbHVlLCBuYW1lKSB7CiAgICAgICAgICAgICAgICB4aHIuc2V0UmVxdWVzdEhlYWRlcihuYW1lLCB2YWx1ZSk7CiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgaWYgKHJlcXVlc3Quc2lnbmFsKSB7CiAgICAgICAgICAgICAgICByZXF1ZXN0LnNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsIGFib3J0WGhyKTsKICAgICAgICAgICAgICAgIHhoci5vbnJlYWR5c3RhdGVjaGFuZ2UgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgICAgaWYgKHhoci5yZWFkeVN0YXRlID09PSA0KSB7CiAgICAgICAgICAgICAgICAgICAgcmVxdWVzdC5zaWduYWwucmVtb3ZlRXZlbnRMaXN0ZW5lcigiYWJvcnQiLCBhYm9ydFhocik7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHhoci5zZW5kKHR5cGVvZiByZXF1ZXN0Ll9ib2R5SW5pdCA9PT0gInVuZGVmaW5lZCIgPyBudWxsIDogcmVxdWVzdC5fYm9keUluaXQpOwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICAgIGZldGNoMi5wb2x5ZmlsbCA9IHRydWU7CiAgICAgICAgICBpZiAoIXNlbGYyLmZldGNoKSB7CiAgICAgICAgICAgIHNlbGYyLmZldGNoID0gZmV0Y2gyOwogICAgICAgICAgICBzZWxmMi5IZWFkZXJzID0gSGVhZGVyczsKICAgICAgICAgICAgc2VsZjIuUmVxdWVzdCA9IFJlcXVlc3Q7CiAgICAgICAgICAgIHNlbGYyLlJlc3BvbnNlID0gUmVzcG9uc2U7CiAgICAgICAgICB9CiAgICAgICAgICBleHBvcnRzMi5IZWFkZXJzID0gSGVhZGVyczsKICAgICAgICAgIGV4cG9ydHMyLlJlcXVlc3QgPSBSZXF1ZXN0OwogICAgICAgICAgZXhwb3J0czIuUmVzcG9uc2UgPSBSZXNwb25zZTsKICAgICAgICAgIGV4cG9ydHMyLmZldGNoID0gZmV0Y2gyOwogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KGV4cG9ydHMyLCAiX19lc01vZHVsZSIsIHsgdmFsdWU6IHRydWUgfSk7CiAgICAgICAgICByZXR1cm4gZXhwb3J0czI7CiAgICAgICAgfSh7fSk7CiAgICAgIH0pKHR5cGVvZiBzZWxmICE9PSAidW5kZWZpbmVkIiA/IHNlbGYgOiBleHBvcnRzKTsKICAgIH0KICB9KTsKCiAgLy8gc3JjL2RhdGEtZmV0Y2hlcnMvYmFtL2JhbS13b3JrZXIudHM/d29ya2V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b21wYXJlVG8obG93ZXN0KSA+IDApIHsKICAgICAgICBpZiAobGFzdENodW5rID09PSBudWxsKSB7CiAgICAgICAgICBtZXJnZWRDaHVua3MucHVzaChjaHVuayk7CiAgICAgICAgICBsYXN0Q2h1bmsgPSBjaHVuazsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKGNhbk1lcmdlQmxvY2tzKGxhc3RDaHVuaywgY2h1bmspKSB7CiAgICAgICAgICAgIGlmIChjaHVuay5tYXh2LmNvbXBhcmVUbyhsYXN0Q2h1bmsubWF4dikgPiAwKSB7CiAgICAgICAgICAgICAgbGFzdENodW5rLm1heHYgPSBjaHVuay5tYXh2OwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtZXJnZWRDaHVua3MucHVzaChjaHVuayk7CiAgICAgICAgICAgIGxhc3RDaHVuayA9IGNodW5rOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgfSk7CiAgICByZXR1cm4gbWVyZ2VkQ2h1bmtzOwogIH0KCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL0BnbW9kK2JhbUAxLjEuMTgvbm9kZV9tb2R1bGVzL0BnbW9kL2JhbS9lc20vYmFpLmpzCiAgdmFyIEJBSV9NQUdJQyA9IDIxNTc4MDUwOwogIGZ1bmN0aW9uIHJvdW5kRG93bihuLCBtdWx0aXBsZSkgewogICAgcmV0dXJuIG4gLSBuICUgbXVsdGlwbGU7CiAgfQogIGZ1bmN0aW9uIHJvdW5kVXAobiwgbXVsdGlwbGUpIHsKICAgIHJldHVybiBuIC0gbiAlIG11bHRpcGxlICsgbXVsdGlwbGU7CiAgfQogIHZhciBCQUkgPSBjbGFzcyBleHRlbmRzIEluZGV4RmlsZSB7CiAgICBwYXJzZVBzZXVkb0JpbihieXRlcywgb2Zmc2V0KSB7CiAgICAgIGNvbnN0IGxpbmVDb3VudCA9IGxvbmdUb051bWJlcihpbXBvcnRfbG9uZy5kZWZhdWx0LmZyb21CeXRlc0xFKEFycmF5LnByb3RvdHlwZS5zbGljZS5jYWxsKGJ5dGVzLCBvZmZzZXQgKyAxNiwgb2Zmc2V0ICsgMjQpLCB0cnVlKSk7CiAgICAgIHJldHVybiB7IGxpbmVDb3VudCB9OwogICAgfQogICAgYXN5bmMgbGluZUNvdW50KHJlZklkLCBvcHRzID0ge30pIHsKICAgICAgY29uc3QgcHJvbSA9IGF3YWl0IHRoaXMucGFyc2Uob3B0cyk7CiAgICAgIGNvbnN0IGluZGV4ID0gcHJvbS5pbmRpY2VzW3JlZklkXTsKICAgICAgaWYgKCFpbmRleCkgewogICAgICAgIHJldHVybiAtMTsKICAgICAgfQogICAgICBjb25zdCByZXQgPSBpbmRleC5zdGF0cyB8fCB7fTsKICAgICAgcmV0dXJuIHJldC5saW5lQ291bnQgPT09IHZvaWQgMCA/IC0xIDogcmV0LmxpbmVDb3VudDsKICAgIH0KICAgIGZldGNoQmFpKG9wdHMgPSB7fSkgewogICAgICBpZiAoIXRoaXMuYmFpUCkgewogICAgICAgIHRoaXMuYmFpUCA9IHRoaXMuZmlsZWhhbmRsZS5yZWFkRmlsZShvcHRzKS5jYXRjaCgoZSkgPT4gewogICAgICAgICAgdGhpcy5iYWlQID0gdm9pZCAwOwogICAgICAgICAgdGhyb3cgZTsKICAgICAgICB9KTsKICAgICAgfQogICAgICByZXR1cm4gdGhpcy5iYWlQOwogICAgfQogICAgYXN5bmMgX3BhcnNlKCkgewogICAgICBjb25zdCBkYXRhID0geyBiYWk6IHRydWUsIG1heEJsb2NrU2l6ZTogMSA8PCAxNiB9OwogICAgICBjb25zdCBieXRlcyA9IGF3YWl0IHRoaXMuZmV0Y2hCYWkoKTsKICAgICAgaWYgKGJ5dGVzLnJlYWRVSW50MzJMRSgwKSAhPT0gQkFJX01BR0lDKSB7CiAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJOb3QgYSBCQUkgZmlsZSIpOwogICAgICB9CiAgICAgIGRhdGEucmVmQ291bnQgPSBieXRlcy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ICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDQ7CiAgICAgICAgICAgIGNvbnN0IGNodW5rcyA9IG5ldyBBcnJheShjaHVua0NvdW50KTsKICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBjaHVua0NvdW50OyBrICs9IDEpIHsKICAgICAgICAgICAgICBjb25zdCB1ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgICBjb25zdCB2ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0ICsgOCk7CiAgICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgICB0aGlzLl9maW5kRmlyc3REYXRhKGRhdGEsIHUpOwogICAgICAgICAgICAgIGNodW5rc1trXSA9IG5ldyBDaHVuayh1LCB2LCBiaW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJpbkluZGV4W2Jpbl0gPSBjaHVua3M7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvbnN0IGxpbmVhckNvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgIGNvbnN0IGxpbmVhckluZGV4ID0gbmV3IEFycmF5KGxpbmVhckNvdW50KTsKICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbmVhckNvdW50OyBrICs9IDEpIHsKICAgICAgICAgIGxpbmVhckluZGV4W2tdID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgIGN1cnJPZmZzZXQgKz0gODsKICAgICAgICAgIHRoaXMuX2ZpbmRGaXJzdERhdGEoZGF0YSwgbGluZWFySW5kZXhba10pOwogICAgICAgIH0KICAgICAgICBkYXRhLmluZGljZXNbaV0gPSB7IGJpbkluZGV4LCBsaW5lYXJJbmRleCwgc3RhdHMgfTsKICAgICAgfQogICAgICByZXR1cm4gZGF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WFyIGluZGV4Iik7CiAgICAgIH0KICAgICAgbGV0IGN1cnJlbnRQb3MgPSBsaW5lYXJJbmRleFtzIC8gdl0uYmxvY2tQb3NpdGlvbjsKICAgICAgZm9yIChsZXQgaSA9IHMgLyB2LCBqID0gMDsgaSA8IGUgLyB2OyBpKyssIGorKykgewogICAgICAgIGRlcHRoc1tqXSA9IHsKICAgICAgICAgIHNjb3JlOiBsaW5lYXJJbmRleFtpICsgMV0uYmxvY2tQb3NpdGlvbiAtIGN1cnJlbnRQb3MsCiAgICAgICAgICBzdGFydDogaSAqIHYsCiAgICAgICAgICBlbmQ6IGkgKiB2ICsgdgogICAgICAgIH07CiAgICAgICAgY3VycmVudFBvcyA9IGxpbmVhckluZGV4W2kgKyAxXS5ibG9ja1Bvc2l0aW9uOwogICAgICB9CiAgICAgIHJldHVybiBkZXB0aHMubWFwKChkKSA9PiB7CiAgICAgICAgcmV0dXJuIHsgLi4uZCwgc2NvcmU6IGQuc2NvcmUgKiBzdGF0cy5saW5lQ291bnQgLyB0b3RhbFNpemUgfTsKICAgICAgfSk7CiAgICB9CiAgICByZWcyYmlucyhiZWcsIGVuZCkgewogICAgICBlbmQgLT0gMTsKICAgICAgcmV0dXJuIFsKICAgICAgICBbMCwgMF0sCiAgICAgICAgWzEgKyAoYmVnID4+IDI2KSwgMSArIChlbmQgPj4gMjYpXSwKICAgICAgICBbOSArIChiZWcgPj4gMjMpLCA5ICsgKGVuZCA+PiAyMyldLAogICAgICAgIFs3MyArIChiZWcgPj4gMjApLCA3MyArIChlbmQgPj4gMjApXSwKICAgICAgICBbNTg1ICsgKGJlZyA+PiAxNyksIDU4NSArIChlbmQgPj4gMTcpXSwKICAgICAgICBbNDY4MSArIChiZWcgPj4gMTQpLCA0NjgxICsgKGVuZCA+PiAxNCldCiAgICAgIF07CiAgICB9CiAgICBhc3luYyBibG9ja3NGb3JSYW5nZShyZWZJZCwgbWluLCBtYXgsIG9wdHMgPSB7fSkgewogICAgICBpZiAobWluIDwgMCkgewogICAgICAgIG1pbiA9IDA7CiAgICAgIH0KICAgICAgY29uc3QgaW5kZXhEYXRhID0gYXdhaXQgdGhpcy5wYXJzZShvcHRzKTsKICAgICAgaWYgKCFpbmRleERhdGEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3QgYmEgPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmICghYmEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3Qgb3ZlcmxhcHBpbmdCaW5zID0gdGhpcy5yZWcyYmlucyhtaW4sIG1heCk7CiAgICAgIGNvbnN0IGNodW5rcyA9IFtdOwogICAgICBmb3IgKGNvbnN0IFtzdGFydCwgZW5kXSBvZiBvdmVybGFwcGluZ0JpbnMpIHsKICAgICAgICBmb3IgKGxldCBiaW4gPSBzdGFydDsgYmluIDw9IGVuZDsgYmluKyspIHsKICAgICAgICAgIGlmIChiYS5iaW5JbmRleFtiaW5dKSB7CiAgICAgICAgICAgIGNvbnN0IGJpbkNodW5rcyA9IGJhLmJpbkluZGV4W2Jpbl07CiAgICAgICAgICAgIGZvciAobGV0IGMgPSAwOyBjIDwgYmluQ2h1bmtzLmxlbmd0aDsgKytjKSB7CiAgICAgICAgICAgICAgY2h1bmtzLnB1c2gobmV3IENodW5rKGJpbkNodW5rc1tjXS5taW52LCBiaW5DaHVua3NbY10ubWF4diwgYmluKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgY29uc3QgbmludHYgPSBiYS5saW5lYXJJbmRleC5sZW5ndGg7CiAgICAgIGxldCBsb3dlc3QgPSBudWxsOwogICAgICBjb25zdCBtaW5MaW4gPSBNYXRoLm1pbihtaW4gPj4gMTQsIG5pbnR2IC0gMSk7CiAgICAgIGNvbnN0IG1heExpbiA9IE1hdGgubWluKG1heCA+PiAxNCwgbmludHYgLSAxKTsKICAgICAgZm9yIChsZXQgaSA9IG1pbkx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XMuZmV0Y2guYmluZChnbG9iYWxUaGlzKTsKICAgICAgaWYgKCFmZXRjaDIpIHsKICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKGBubyBmZXRjaCBmdW5jdGlvbiBzdXBwbGllZCwgYW5kIG5vbmUgZm91bmQgaW4gZ2xvYmFsIGVudmlyb25tZW50YCk7CiAgICAgIH0KICAgICAgaWYgKG9wdHMub3ZlcnJpZGVzKSB7CiAgICAgICAgdGhpcy5iYXNlT3ZlcnJpZGVzID0gb3B0cy5vdmVycmlkZXM7CiAgICAgIH0KICAgICAgdGhpcy5mZXRjaEltcGxlbWVudGF0aW9uID0gZmV0Y2gyOwogICAgfQogICAgYXN5bmMgZmV0Y2goaW5wdXQsIGluaXQyKSB7CiAgICAgIGxldCByZXNwb25zZTsKICAgICAgdHJ5IHsKICAgICAgICByZXNwb25zZSA9IGF3YWl0IHRoaXMuZmV0Y2hJbXBsZW1lbnRhdGlvbihpbnB1dCwgaW5pdDIpOwogICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgaWYgKGAke2V9YC5pbmNsdWRlcygiRmFpbGVkIHRvIGZldGNoIikpIHsKICAgICAgICAgIGNvbnNvbGUud2FybihgZ2VuZXJpYy1maWxlaGFuZGxlOiByZWZldGNoaW5nICR7aW5wdXR9IHRvIGF0dGVtcHQgdG8gd29yayBhcm91bmQgY2hyb21lIENPUlMgaGVhZGVyIGNhY2hpbmcgYnVnYCk7CiAgICAgICAgICByZXNwb25zZSA9IGF3YWl0IHRoaXMuZmV0Y2hJbXBsZW1lbnRhdGlvbihpbnB1dCwgewogICAgICAgICAgICAuLi5pbml0MiwKICAgICAgICAgICAgY2FjaGU6ICJyZWxvYWQiCiAgICAgICAgICB9KTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdGhyb3cgZTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIHJlc3BvbnNlOwogICAgfQogICAgYXN5bmMgcmVhZChidWZmZXIsIG9mZnNldCA9IDAs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G9uc2Uuc3RhdHVzID09PSAyMDYpIHsKICAgICAgICBjb25zdCByZXNwb25zZURhdGEgPSBhd2FpdCB0aGlzLmdldEJ1ZmZlckZyb21SZXNwb25zZShyZXNwb25zZSk7CiAgICAgICAgY29uc3QgYnl0ZXNDb3BpZWQgPSByZXNwb25zZURhdGEuY29weShidWZmZXIsIG9mZnNldCwgMCwgTWF0aC5taW4obGVuZ3RoLCByZXNwb25zZURhdGEubGVuZ3RoKSk7CiAgICAgICAgY29uc3QgcmVzID0gcmVzcG9uc2UuaGVhZGVycy5nZXQoImNvbnRlbnQtcmFuZ2UiKTsKICAgICAgICBjb25zdCBzaXplTWF0Y2ggPSAvXC8oXGQrKSQvLmV4ZWMocmVzIHx8ICIiKTsKICAgICAgICBpZiAoc2l6ZU1hdGNoICYmIHNpemVNYXRjaFsxXSkgewogICAgICAgICAgdGhpcy5fc3RhdCA9IHsgc2l6ZTogcGFyc2VJbnQoc2l6ZU1hdGNoWzFdLCAxMCkgfTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHsgYnl0ZXNSZWFkOiBieXRlc0NvcGllZCwgYnVmZmVyIH07CiAgICAgIH0KICAgICAgaWYgKHJlc3BvbnNlLnN0YXR1cyA9PT0gMjAwKSB7CiAgICAgICAgdGhyb3cgbmV3IEVycm9yKCIke3RoaXMudXJsfSBmZXRjaCByZXR1cm5lZCBzdGF0dXMgMjAwLCBleHBlY3RlZCAyMDYiKTsKICAgICAgfQogICAgICB0aHJvdyBuZXcgRXJyb3IoYEhUVFAgJHtyZXNwb25zZS5zdGF0dXN9IGZldGNoaW5nICR7dGhpcy51cmx9YCk7CiAgICB9CiAgICBhc3luYyByZWFkRmlsZShvcHRpb25zID0ge30pIHsKICAgICAgbGV0IGVuY29kaW5nOwogICAgICBsZXQgb3B0czsKICAgICAgaWYgKHR5cGVvZiBvcHRpb25zID09PSAic3RyaW5nIikgewogICAgICAgIGVuY29kaW5nID0gb3B0aW9uczsKICAgICAgICBvcHRzID0ge307CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZW5jb2RpbmcgPSBvcHRpb25zLmVuY29kaW5nOwogICAgICAgIG9wdHMgPSBvcHRpb25zOwogICAgICAgIGRlbGV0ZSBvcHRzLmVuY29kaW5nOwogICAgICB9CiAgICAgIGNvbnN0IHsgaGVhZGVycyA9IHt9LCBzaWduYWwsIG92ZXJyaWRlcyA9IHt9IH0gPSBvcHRzOwogICAgICBjb25zdCBhcmdzID0gewogICAgICAgIGhlYWRlcnMsCiAgICAgICAgbWV0aG9kOiAiR0VUIiwKICAgICAgICByZWRpcmVjdDogImZvbGxvdyIsCiAgICAgICAgbW9kZTogImNvcnMiLAogICAgICAgIHNpZ25hbCwKICAgICAgICAuLi50aGlzLmJhc2VPdmVycmlkZXMsCiAgICAgICAgLi4ub3ZlcnJpZGVzCiAgICAgIH07CiAgICAgIGNvbnN0IHJlc3BvbnNlID0gYXdhaXQgdGhpcy5mZXRjaCh0aGlzLnVybCwgYXJncyk7CiAgICAgIGlmICghcmVzcG9uc2UpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImdlbmVyaWMtZmlsZWhhbmRsZSBmYWlsZWQgdG8gZmV0Y2giKTsKICAgICAgfQogICAgICBpZiAocmVzcG9uc2Uuc3RhdHVzICE9PSAyMDApIHsKICAgICAgICB0aHJvdyBPYmplY3QuYXNzaWduKG5ldyBFcnJvcihgSFRUUCAke3Jlc3BvbnNlLnN0YXR1c30gZmV0Y2hpbmcgJHt0aGlzLnVybH1gKSwgewogICAgICAgICAgc3RhdHVzOiByZXNwb25zZS5zdGF0dXMKICAgICAgICB9KTsKICAgICAgfQogICAgICBpZiAoZW5jb2RpbmcgPT09ICJ1dGY4IikgewogICAgICAgIHJldHVybiByZXNwb25zZS50ZXh0KCk7CiAgICAgIH0KICAgICAgaWYgKGVuY29kaW5nKSB7CiAgICAgICAgdGhyb3cgbmV3IEVycm9yKGB1bnN1cHBvcnRlZCBlbmNvZGluZzogJHtlbmNvZGluZ31gKT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5pdF9idWZmZXJfc2hpbSgpOwogIHZhciBpbXBvcnRfYnVmZmVyNCA9IF9fdG9Nb2R1bGUocmVxdWlyZV9idWZmZXIoKSk7CiAgdmFyIGltcG9ydF9wYWtvID0gX190b01vZHVsZShyZXF1aXJlX3Bha28oKSk7CiAgYXN5bmMgZnVuY3Rpb24gdW56aXAoaW5wdXREYXRhKSB7CiAgICB0cnkgewogICAgICBsZXQgc3RybTsKICAgICAgbGV0IHBvcyA9IDA7CiAgICAgIGxldCBpID0gMDsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGxldCB0b3RhbFNpemUgPSAwOwogICAgICBsZXQgaW5mbGF0b3I7CiAgICAgIGRvIHsKICAgICAgICBjb25zdCByZW1haW5pbmdJbnB1dCA9IGlucHV0RGF0YS5zdWJhcnJheShwb3MpOwogICAgICAgIGluZmxhdG9yID0gbmV3IGltcG9ydF9wYWtvLkluZmxhdGUoKTsKICAgICAgICAoeyBzdHJtIH0gPSBpbmZsYXRvcik7CiAgICAgICAgaW5mbGF0b3IucHVzaChyZW1haW5pbmdJbnB1dCwgaW1wb3J0X3Bha28uWl9TWU5DX0ZMVVNIKTsKICAgICAgICBpZiAoaW5mbGF0b3IuZXJyKSB7CiAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoaW5mbGF0b3IubXNnKTsKICAgICAgICB9CiAgICAgICAgcG9zICs9IHN0cm0ubmV4dF9pbjsKICAgICAgICBjaHVua3NbaV0gPSBpbmZsYXRvci5yZXN1bHQ7CiAgICAgICAgdG90YWxTaXplICs9IGNodW5rc1tpXS5sZW5ndGg7CiAgICAgICAgaSArPSAxOwogICAgICB9IHdoaWxlIChzdHJtLmF2YWlsX2luKTsKICAgICAgY29uc3QgcmVzdWx0ID0gbmV3IFVpbnQ4QXJyYXkodG90YWxTaXplKTsKICAgICAgZm9yIChsZXQgaTIgPSAwLCBvZmZzZXQgPSAwOyBpMiA8IGNodW5rcy5sZW5ndGg7IGkyKyspIHsKICAgICAgICByZ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bXBvcnRfcGFrby5aX1NZTkNfRkxVU0gpOwogICAgICAgIGlmIChpbmZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IG5ldyBFcnJvcihpbmZsYXRvci5tc2cpOwogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIyID0gaW5mbGF0b3IucmVzdWx0OwogICAgICAgIGNodW5rcy5wdXNoKGJ1ZmZlcjIpOwogICAgICAgIGxldCBsZW4gPSBidWZmZXIyLmxlbmd0aDsKICAgICAgICBjcG9zaXRpb25zLnB1c2goY3Bvcyk7CiAgICAgICAgZHBvc2l0aW9ucy5wdXNoKGRwb3MpOwogICAgICAgIGlmIChjaHVua3MubGVuZ3RoID09PSAxICYmIG1pbnYuZGF0YVBvc2l0aW9uKSB7CiAgICAgICAgICBjaHVua3NbMF0gPSBjaHVua3NbMF0uc3ViYXJyYXkobWludi5kYXRhUG9zaXRpb24pOwogICAgICAgICAgbGVuID0gY2h1bmtzWzBdLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgY29uc3Qgb3JpZ0Nwb3MgPSBjcG9zOwogICAgICAgIGNwb3MgKz0gc3RybS5uZXh0X2luOwogICAgICAgIGRwb3MgKz0gbGVuOwogICAgICAgIGlmIChvcmlnQ3BvcyA+PSBtYXh2LmJsb2NrUG9zaXRpb24pIHsKICAgICAgICAgIGNodW5rc1tpXSA9IGNodW5rc1tpXS5zdWJhcnJheSgwLCBtYXh2LmJsb2NrUG9zaXRpb24gPT09IG1pbnYuYmxvY2tQb3NpdGlvbiA/IG1heHYuZGF0YVBvc2l0aW9uIC0gbWludi5kYXRhUG9zaXRpb24gKyAxIDogbWF4di5kYXRhUG9zaXRpb24gKyAxKTsKICAgICAgICAgIGNwb3NpdGlvbnMucHVzaChjcG9zKTsKICAgICAgICAgIGRwb3NpdGlvbnMucHVzaChkcG9zKTsKICAgICAgICAgIHRvdGFsU2l6ZSArPSBjaHVua3NbaV0ubGVuZ3RoOwogICAgICAgICAgYnJlYWs7CiAgICAgICA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ucG0vQGdtb2QrYmFtQDEuMS4xOC9ub2RlX21vZHVsZXMvQGdtb2QvYmFtL2VzbS9jc2kuanMKICB2YXIgQ1NJMV9NQUdJQyA9IDIxNTgyNjU5OwogIHZhciBDU0kyX01BR0lDID0gMzgzNTk4NzU7CiAgZnVuY3Rpb24gbHNoaWZ0KG51bSwgYml0cykgewogICAgcmV0dXJuIG51bSAqIDIgKiogYml0czsKICB9CiAgZnVuY3Rpb24gcnNoaWZ0KG51bSwgYml0cykgewogICAgcmV0dXJuIE1hdGguZmxvb3IobnVtIC8gMiAqKiBiaXRzKTsKICB9CiAgdmFyIENTSSA9IGNsYXNzIGV4dGVuZHMgSW5kZXhGaWxlIHsKICAgIGNvbnN0cnVjdG9yKGFyZ3MpIHsKICAgICAgc3VwZXIoYXJncyk7CiAgICAgIHRoaXMubWF4QmluTnVtYmVyID0gMDsKICAgICAgdGhpcy5kZXB0aCA9IDA7CiAgICAgIHRoaXMubWluU2hpZnQgPSAwOwogICAgfQogICAgYXN5bmMgbGluZUNvdW50KHJlZklkKSB7CiAgICAgIGNvbnN0IGluZGV4RGF0YSA9IGF3YWl0IHRoaXMucGFyc2UoKTsKICAgICAgaWYgKCFpbmRleERhdGEpIHsKICAgICAgICByZXR1cm4gLTE7CiAgICAgIH0KICAgICAgY29uc3QgaWR4ID0gaW5kZXhEYXRhLmluZGljZXNbcmVmSWRdOwogICAgICBpZiAoIWlkeCkgewogICAgICAgIHJldHVybiAtMTsKICAgICAgfQogICAgICBjb25zdCB7IHN0YXRzIH0gPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmIChzdGF0cykgewogICAgICAgIHJldHVybiBzdGF0cy5saW5lQ291bnQ7CiAgICAgIH0KICAgICAgcmV0dXJuIC0xOwogICAgfQogICAgYXN5bmMgaW5kZXhDb3YoKSB7CiAgICAgIHJldHVybiBbXTsKICAgIH0KICAgIHBhcnNlQXV4RGF0YShieXRlcywgb2Zmc2V0LCBhdXhMZW5ndGg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wOyBpIDwgZGF0YS5yZWZDb3VudDsgaSArPSAxKSB7CiAgICAgICAgYXdhaXQgYWJvcnRCcmVha1BvaW50KG9wdHMuc2lnbmFsKTsKICAgICAgICBjb25zdCBiaW5Db3VudCA9IGJ5dGVzLnJlYWRJbnQzMkxFKGN1cnJPZmZzZXQpOwogICAgICAgIGN1cnJPZmZzZXQgKz0gNDsKICAgICAgICBjb25zdCBiaW5JbmRleCA9IHt9OwogICAgICAgIGxldCBzdGF0czsKICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IGJpbkNvdW50OyBqICs9IDEpIHsKICAgICAgICAgIGNvbnN0IGJpbiA9IGJ5dGVzLnJlYWRVSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgIGlmIChiaW4gPiB0aGlzLm1heEJpbk51bWJlcikgewogICAgICAgICAgICBzdGF0cyA9IHRoaXMucGFyc2VQc2V1ZG9CaW4oYnl0ZXMsIGN1cnJPZmZzZXQgKyA0KTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSA0ICsgOCArIDQgKyAxNiArIDE2OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY29uc3QgbG9mZnNldCA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCArIDQpOwogICAgICAgICAgICB0aGlzLl9maW5kRmlyc3REYXRhKGRhdGEsIGxvZmZzZXQpOwogICAgICAgICAgICBjb25zdCBjaHVua0NvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCArIDEyKTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgY29uc3QgY2h1bmtzID0gbmV3IEFycmF5KGNodW5rQ291bnQpOwogICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGNodW5rQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgICAgIGNvbnN0IHUgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgICAgIGN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gY2h1bmtzID0gW107CiAgICAgIGZvciAoY29uc3QgW3N0YXJ0LCBlbmRdIG9mIG92ZXJsYXBwaW5nQmlucykgewogICAgICAgIGZvciAobGV0IGJpbiA9IHN0YXJ0OyBiaW4gPD0gZW5kOyBiaW4rKykgewogICAgICAgICAgaWYgKGJhLmJpbkluZGV4W2Jpbl0pIHsKICAgICAgICAgICAgY29uc3QgYmluQ2h1bmtzID0gYmEuYmluSW5kZXhbYmluXTsKICAgICAgICAgICAgZm9yIChsZXQgYyA9IDA7IGMgPCBiaW5DaHVua3MubGVuZ3RoOyArK2MpIHsKICAgICAgICAgICAgICBjaHVua3MucHVzaChuZXcgQ2h1bmsoYmluQ2h1bmtzW2NdLm1pbnYsIGJpbkNodW5rc1tjXS5tYXh2LCBiaW4pKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gb3B0aW1pemVDaHVua3MoY2h1bmtzLCBuZXcgVmlydHVhbE9mZnNldCgwLCAwKSk7CiAgICB9CiAgICByZWcyYmlucyhiZWcsIGVuZCkgewogICAgICBiZWcgLT0gMTsKICAgICAgaWYgKGJlZyA8IDEpIHsKICAgICAgICBiZWcgPSAxOwogICAgICB9CiAgICAgIGlmIChlbmQgPiAyICoqIDUwKSB7CiAgICAgICAgZW5kID0gMiAqKiAzNDsKICAgICAgfQogICAgICBlbmQgLT0gMTsKICAgICAgbGV0IGwgPSAwOwogICAgICBsZXQgdCA9IDA7CiAgICAgIGxldCBzID0gdGhpcy5taW5TaGlmdCArIHRoaXMuZGVwdGggKiAzOwogICAgICBjb25zdCBiaW5zID0gW107CiAgICAgIGZvciAoOyBsIDw9IHRoaXMuZGVwdGg7IHMgLT0gMywgdCArPSBsc2hpZnQoMSwgbCAqIDMpLCBsICs9IDEpIHsKICAgICAgICBjb25zdCBiID0gdCArIHJzaGlmdChiZWcsIHMpOwogICAgICAgIGNvbnN0IGUgPSB0ICsgcnNoaWZ0KGVuZCwgcyk7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zmc2V0OwogICAgICB0aGlzLl9yZWZJRCA9IGJ5dGVBcnJheS5yZWFkSW50MzJMRShzdGFydCArIDQpOwogICAgICB0aGlzLmRhdGEuc3RhcnQgPSBieXRlQXJyYXkucmVhZEludDMyTEUoc3RhcnQgKyA4KTsKICAgICAgdGhpcy5mbGFncyA9IChieXRlQXJyYXkucmVhZEludDMyTEUoc3RhcnQgKyAxNikgJiA0Mjk0OTAxNzYwKSA+PiAxNjsKICAgIH0KICAgIGdldChmaWVsZCkgewogICAgICBpZiAodGhpc1tmaWVsZF0pIHsKICAgICAgICBpZiAodGhpcy5kYXRhW2ZpZWxkXSkgewogICAgICAgICAgcmV0dXJuIHRoaXMuZGF0YVtmaWVsZF07CiAgICAgICAgfQogICAgICAgIHRoaXMuZGF0YVtmaWVsZF0gPSB0aGlzW2ZpZWxkXSgpOwogICAgICAgIHJldHVybiB0aGlzLmRhdGFbZmllbGRdOwogICAgICB9CiAgICAgIHJldHVybiB0aGlzLl9nZXQoZmllbGQudG9Mb3dlckNhc2UoKSk7CiAgICB9CiAgICBlbmQoKSB7CiAgICAgIHJldHVybiB0aGlzLmdldCgic3RhcnQiKSArIHRoaXMuZ2V0KCJsZW5ndGhfb25fcmVmIik7CiAgICB9CiAgICBzZXFfaWQoKSB7CiAgICAgIHJldHVybiB0aGlzLl9yZWZJRDsKICAgIH0KICAgIF9nZXQoZmllbGQpIHsKICAgICAgaWYgKGZpZWxkIGluIHRoaXMuZGF0YSkgewogICAgICAgIHJldHVybiB0aGlzLmRhdGFbZmllbGRdOwogICAgICB9CiAgICAgIHRoaXMuZGF0YVtmaWVsZF0gPSB0aGlzLl9wYXJzZVRhZyhmaWVsZCk7CiAgICAgIHJldHVybiB0aGlzLmRhdGFbZmllbGRdOwogICAgfQogICAgX3RhZ3MoKSB7CiAgICAgIHRoaXMuX3BhcnNlQWxsVGFncygpOwogICAgICBsZXQgdGFncyA9IFsic2VxIl07CiAgICAgIGlmICghdGhpcy5pc1NlZ21lbnRVbm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bmcuZnJvbUNoYXJDb2RlKGJ5dGVBcnJheVtwICsgMl0pOwogICAgICAgIHAgKz0gMzsKICAgICAgICBsZXQgdmFsdWU7CiAgICAgICAgc3dpdGNoICh0eXBlKSB7CiAgICAgICAgICBjYXNlICJBIjoKICAgICAgICAgICAgdmFsdWUgPSBTdHJpbmcuZnJvbUNoYXJDb2RlKGJ5dGVBcnJheVtwXSk7CiAgICAgICAgICAgIHAgKz0gMTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBjYXNlICJpIjoKICAgICAgICAgICAgdmFsdWUgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBjYXNlICJJIjoKICAgICAgICAgICAgdmFsdWUgPSBieXRlQXJyYXkucmVhZFVJbnQzMkxFKHApOwogICAgICAgICAgICBwICs9IDQ7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgY2FzZSAiYyI6CiAgICAgICAgICAgIHZhbHVlID0gYnl0ZUFycmF5LnJlYWRJbnQ4KHApOwogICAgICAgICAgICBwICs9IDE7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgY2FzZSAiQyI6CiAgICAgICAgICAgIHZhbHVlID0gYnl0ZUFycmF5LnJlYWRVSW50OChwKTsKICAgICAgICAgICAgcCArPSAxOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIGNhc2UgInMiOgogICAgICAgICAgICB2YWx1ZSA9IGJ5dGVBcnJheS5yZWFkSW50MTZMRShwKTsKICAgICAgICAgICAgcCArPSAyOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIGNhc2UgIlMiOgogICAgICAgICAgICB2YWx1ZSA9IGJ5dGVBcnJheS5yZWFkVUludDE2TEUocCk7CiAgICAgICAgICAgIHAgKz0gMjsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBjYXNlICJmIjoKICAgICAgICAgICAgdmFsdWUgPSBieXRlQXJyYXkucmVhZEZsb2F0TEUocCk7CiAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBjYXNlICJaIjoKICAgICAgICAgIGNhc2UgIkgiOgogICAgICAgICAgICB2YWx1ZSA9ICIiOwogICAgICAgICAgICB3aGlsZSAocCA8PSBibG9ja0VuZCkgewogICAgICAgICAgICAgIGNvbnN0IGNjID0gYnl0ZUFycmF5W3ArK107CiAgICAgICAgICAgICAgaWYgKGNjID09PSAwKSB7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdmFsdWUgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShjYyk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgY2FzZSAiQiI6IHsKICAgICAgICAgICAgdmFsdWUgPSAiIjsKICAgICAgICAgICAgY29uc3QgY2MgPSBieXRlQXJyYXlbcCsrXTsKICAgICAgICAgICAgY29uc3QgQnR5cGUgPSBTdHJpbmcuZnJvbUNoYXJDb2RlKGNjKTsKICAgICAgICAgICAgY29uc3QgbGltaXQgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgaWYgKEJ0eXBlID09PSAiaSIpIHsKICAgICAgICAgICAgICBpZiAodGFnID09PSAiQ0ciKSB7CiAgICAgICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbWl0OyBrKyspIHsKICAgICAgICAgICAgICAgICAgY29uc3QgY2lnb3AgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgICAgICAgICAgIGNvbnN0IGxvcCA9IGNpZ29wID4+IDQ7CiAgICAgICAgICAgICAgICAgIGNvbnN0IG9wID0gQ0lHQVJfREVDT0RFUltjaWdvcCAmIDE1XTsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gbG9wICsgb3A7CiAgICAgICAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkSW50MzJMRShwKTsKICAgICAgICAgICAgICAgICAgaWYgKGsgKyAxIDwgbGltaXQpIHsKICAgICAgICAgICAgICAgICAgICB2YWx1ZSArPSAiLCI7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgcCArPSA0OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoQnR5cGUgPT09ICJJIikgewogICAgICAgICAgICAgIGlmICh0YWcgPT09ICJDRyIpIHsKICAgICAgICAgICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgbGltaXQ7IGsrKykgewogICAgICAgICAgICAgICAgICBjb25zdCBjaWdvcCA9IGJ5dGVBcnJheS5yZWFkVUludDMyTEUocCk7CiAgICAgICAgICAgICAgICAgIGNvbnN0IGxvcCA9IGNpZ29wID4+IDQ7CiAgICAgICAgICAgICAgICAgIGNvbnN0IG9wID0gQ0lHQVJfREVDT0RFUltjaWdvcCAmIDE1XTsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gbG9wICsgb3A7CiAgICAgICAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkVUludDMyTEUocCk7CiAgICAgICAgICAgICAgICAgIGlmIChrICsgMSA8IGxpbWl0KSB7CiAgICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gIiwiOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKEJ0eXBlID09PSAicyIpIHsKICAgICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbWl0OyBrKyspIHsKICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkSW50MTZMRShwKTsKICAgICAgICAgICAgICAgIGlmIChrICsgMSA8IGxpbWl0KSB7CiAgICAgICAgICAgICAgICAgIHZhbHVlICs9ICIsIjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHAgKz0gMjsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKEJ0eXBlID09PSAiUyIpIHsKICAgICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbWl0OyBrKyspIHsKICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkVUludDE2TEUocCk7CiAgICAgICAgICAgICAgICBpZiAoayArIDEgPCBsaW1pdCkgewogICAgICAgICAgICAgICAgICB2YWx1ZSArPSAiLCI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBwICs9IDI7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChCdHlwZSA9PT0gImMiKSB7CiAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICB2YWx1ZSArPSBieXRlQXJyYXkucmVhZEludDgocCk7CiAgICAgICAgICAgICAgICBpZiAoayArIDEgPCBsaW1pdCkgewogICAgICAgICAgICAgICAgICB2YWx1ZSArPSAiLCI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBwICs9IDE7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChCdHlwZSA9PT0gIkMiKSB7CiAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICB2YWx1ZSArPSBieXRlQXJyYXkucmVhZFVJbnQ4KHApOwogICAgICAgICAgICAgICAgaWYgKGsgKyAxIDwgbGltaXQpIHsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gIiwiOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcCArPSAxOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoQnR5cGUgPT09ICJmIikgewogICAgICAgICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgbGltaXQ7IGsrKykgewogICAgICAgICAgICAgICAgdmFsdWUgKz0gYnl0ZUFycmF5LnJlYWRGbG9hdExFKHApOwogICAgICAgICAgICAgICAgaWYgKGsgKyAxIDwgbGltaXQpIHsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gIiwiOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcCArPSA0OwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIGNvbnNvbGUud2FybihgVW5rbm93biBCQU0gdGFnIHR5cGUgJyR7dHlwZX0nLCB0YWdzIG1heSBiZSBpbmNvbXBsZXRlYCk7CiAgICAgICAgICAgIHZhbHVlID0gdm9pZCAwOwogICAgICAgICAgICBwID0gYmxvY2tFbmQ7CiAgICAgICAgfQogICAgICAgIHRoaXMuX3RhZ09mZnNldCA9IHA7CiAgICAgICAgdGhpcy5fdGFnTGlzdC5wdXNoKHRhZyk7CiAgICAgICAgaWYgKGxjVGFnID09PSB0YWdOYW1lKSB7CiAgICAgICAgICByZXR1cm4gdmFsdWU7CiAgICAgICAgfQogICAgICAgIHRoaXMuZGF0YVtsY1RhZ10g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yID0gIiI7CiAgICAgIGxldCBscmVmID0gMDsKICAgICAgbGV0IGNpZ29wID0gYnl0ZUFycmF5LnJlYWRJbnQzMkxFKHApOwogICAgICBsZXQgbG9wID0gY2lnb3AgPj4gNDsKICAgICAgbGV0IG9wID0gQ0lHQVJfREVDT0RFUltjaWdvcCAmIDE1XTsKICAgICAgaWYgKG9wID09PSAiUyIgJiYgbG9wID09PSBzZXFMZW4pIHsKICAgICAgICBwICs9IDQ7CiAgICAgICAgY2lnb3AgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgbG9wID0gY2lnb3AgPj4gNDsKICAgICAgICBvcCA9IENJR0FSX0RFQ09ERVJbY2lnb3AgJiAxNV07CiAgICAgICAgaWYgKG9wICE9PSAiTiIpIHsKICAgICAgICAgIGNvbnNvbGUud2FybigiQ0cgdGFnIHdpdGggbm8gTiB0YWciKTsKICAgICAgICB9CiAgICAgICAgdGhpcy5kYXRhLmxlbmd0aF9vbl9yZWYgPSBsb3A7CiAgICAgICAgcmV0dXJuIHRoaXMuZ2V0KCJDRyIpOwogICAgICB9IGVsc2UgewogICAgICAgIGZvciAobGV0IGMgPSAwOyBjIDwgbnVtQ2lnYXJPcHM7ICsrYykgewogICAgICAgICAgY2lnb3AgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgICBsb3AgPSBjaWdvcCA+PiA0OwogICAgICAgICAgb3AgPSBDSUdBUl9ERUNPREVSW2NpZ29wICYgMTVdOwogICAgICAgICAgY2lnYXIgKz0gbG9wICsgb3A7CiAgICAgICAgICBpZiAob3AgIT09ICJIIiAmJiBvcCAhPT0gIlMiICYmIG9wICE9PSAiSSIpIHsKICAgICAgICAgICAgbHJlZiArPSBsb3A7CiAgICAgICAgICB9CiAgICAgICAgICBwICs9IDQ7CiAgICAgICAgfQogICAgICAgIHRoaXMuZGF0YS5sZW5ndGhfb25fcmVmID0gbHJlZjsKICAgICAgICByZXR1cm4gY2lnYXI7CiAgICAgIH0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sKICAgICAgICBidWYgKz0gU0VRUkVUX0RFQ09ERVJbKHNiICYgMjQwKSA+PiA0XTsKICAgICAgICBpKys7CiAgICAgICAgaWYgKGkgPCBsZW4pIHsKICAgICAgICAgIGJ1ZiArPSBTRVFSRVRfREVDT0RFUltzYiAmIDE1XTsKICAgICAgICAgIGkrKzsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIGJ1ZjsKICAgIH0KICAgIGdldFBhaXJPcmllbnRhdGlvbigpIHsKICAgICAgaWYgKCF0aGlzLmlzU2VnbWVudFVubWFwcGVkKCkgJiYgIXRoaXMuaXNNYXRlVW5tYXBwZWQoKSAmJiB0aGlzLl9yZWZJRCA9PT0gdGhpcy5fbmV4dF9yZWZpZCgpKSB7CiAgICAgICAgY29uc3QgczEgPSB0aGlzLmlzUmV2ZXJzZUNvbXBsZW1lbnRlZCgpID8gIlIiIDogIkYiOwogICAgICAgIGNvbnN0IHMyID0gdGhpcy5pc01hdGVSZXZlcnNlQ29tcGxlbWVudGVkKCkgPyAiUiIgOiAiRiI7CiAgICAgICAgbGV0IG8xID0gIiAiOwogICAgICAgIGxldCBvMiA9ICIgIjsKICAgICAgICBpZiAodGhpcy5pc1JlYWQxKCkpIHsKICAgICAgICAgIG8xID0gIjEiOwogICAgICAgICAgbzIgPSAiMiI7CiAgICAgICAgfSBlbHNlIGlmICh0aGlzLmlzUmVhZDIoKSkgewogICAgICAgICAgbzEgPSAiMiI7CiAgICAgICAgICBvMiA9ICIxIjsKICAgICAgICB9CiAgICAgICAgY29uc3QgdG1wID0gW107CiAgICAgICAgY29uc3QgaXNpemUgPSB0aGlzLnRlbXBsYXRlX2xlbmd0aCgpOwogICAgICAgIGlmIChpc2l6ZSA+IDApIHsKICAgICAgICAgIHRtcFswXSA9IHMxOwogICAgICAgICAgdG1wWzFdID0gbzE7CiAgICAgICAgICB0bXBbMl0gPSBzMjsKICAgICAgICAgIHRtcFszXSA9IG8yOwogICAgICAgIH0gZWxzZSB7CiAgICA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XFfaWQoKSA9PT0gY2hySWQpIHsKICAgICAgICAgICAgaWYgKGZlYXR1cmUuZ2V0KCJzdGFydCIpID49IG1heCkgewogICAgICAgICAgICAgIGRvbmUgPSB0cnVlOwogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9IGVsc2UgaWYgKGZlYXR1cmUuZ2V0KCJlbmQiKSA+PSBtaW4pIHsKICAgICAgICAgICAgICByZWNzLnB1c2goZmVhdHVyZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZmVhdHMucHVzaChyZWNzKTsKICAgICAgICB5aWVsZCByZWNzOwogICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgIH0KICAgICAgY2hlY2tBYm9ydFNpZ25hbChvcHRzLnNpZ25hbCk7CiAgICAgIGlmICh2aWV3QXNQYWlycykgewogICAgICAgIHlpZWxkIHRoaXMuZmV0Y2hQYWlycyhjaHJJZCwgZmVhdHMsIG9wdHMpOwogICAgICB9CiAgICB9CiAgICBhc3luYyBmZXRjaFBhaXJzKGNocklkLCBmZWF0cywgb3B0cykgewogICAgICBjb25zdCB7IHBhaXJBY3Jvc3NDaHIgPSBmYWxzZSwgbWF4SW5zZXJ0U2l6ZSA9IDJlNSB9ID0gb3B0czsKICAgICAgY29uc3QgdW5tYXRlZFBhaXJzID0ge307CiAgICAgIGNvbnN0IHJlYWRJZHMgPSB7fTsKICAgICAgZmVhdHMubWFwKChyZXQpID0+IHsKICAgICAgICBjb25zdCByZWFkTmFtZXMgPSB7fTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHJldC5sZW5ndGg7IGkrKykgewogICAgICAgICAgY29uc3QgbmFtZSA9IHJldFtpXS5uYW1lKCk7CiAgICAgICAgICBjb25zdCBpZCA9IHJldFtpXS5pZCgpOwogICAgICAgICAgaWYgKCFyZWFkTmFtZXNbbmFtZV0pIHsKICAgICAgICAgICAgcmVhZE5hbWVzW25hbWVdID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHJlYWROYW1lc1tuYW1lXSsrOwogICAgICAgICAgcmVhZElkc1tpZF0gPSAxOwogICAgICAgIH0KICAgICAgICAoMCwgaW1wb3J0X29iamVjdC5kZWZhdWx0KShyZWFkTmFtZXMpLmZvckVhY2goKFtrLCB2XSkgPT4gewogICAgICAgICAgaWYgKHYgPT09IDEpIHsKICAgICAgICAgICAgdW5tYXRlZFBhaXJzW2tdID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICB9KTsKICAgICAgfSk7CiAgICAgIGNvbnN0IG1hdGVQcm9taXNlcyA9IFtdOwogICAgICBmZWF0cy5tYXAoKHJldCkgPT4gewogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgcmV0Lmxlbmd0aDsgaSsrKSB7CiAgICAgICAgICBjb25zdCBmID0gcmV0W2ldOwogICAgICAgICAgY29uc3QgbmFtZSA9IGYubmFtZSgpOwogICAgICAgICAgY29uc3Qgc3RhcnQgPSBmLmdldCgic3RhcnQiKTsKICAgICAgICAgIGNvbnN0IHBuZXh0ID0gZi5fbmV4dF9wb3MoKTsKICAgICAgICAgIGNvbnN0IHJuZXh0ID0gZi5fbmV4dF9yZWZpZCgpOwogICAgICAgICAgaWYgKHVubWF0ZWRQYWlyc1tuYW1lXSAmJiAocGFpckFjcm9zc0NociB8fCBybmV4dCA9PT0gY2hySWQgJiYgTWF0aC5hYnMoc3RhcnQgLSBwbmV4dCkgPCBtYXhJbnNlcnRTaXplKSkgewogICAgICAgICAgICBtYXRlUHJvbWlzZXMucHVzaCh0aGlzLmluZGV4LmJsb2Nrc0ZvclJhbmdlKHJuZXh0LCBwbmV4dCwgcG5leHQgKyAxLCBvcHRzKSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9KTsKICAgICAgY29uc3QgbWF0ZUNodW5rcyA9IGZsYXQoYXdhaXQgUHJvbWlzZS5hbGwobWF0ZVByb21pc2VzKSkuc29ydCgpLmZpbHR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nJlYWRJbnQzMkxFKGJsb2NrU3RhcnQpOwogICAgICAgIGNvbnN0IGJsb2NrRW5kID0gYmxvY2tTdGFydCArIDQgKyBibG9ja1NpemUgLSAxOwogICAgICAgIGlmIChkcG9zaXRpb25zKSB7CiAgICAgICAgICB3aGlsZSAoYmxvY2tTdGFydCArIGNodW5rLm1pbnYuZGF0YVBvc2l0aW9uID49IGRwb3NpdGlvbnNbcG9zKytdKSB7CiAgICAgICAgICB9CiAgICAgICAgICBwb3MtLTsKICAgICAgICB9CiAgICAgICAgaWYgKGJsb2NrRW5kIDwgYmEubGVuZ3RoKSB7CiAgICAgICAgICBjb25zdCBmZWF0dXJlID0gbmV3IEJhbVJlY29yZCh7CiAgICAgICAgICAgIGJ5dGVzOiB7CiAgICAgICAgICAgICAgYnl0ZUFycmF5OiBiYSwKICAgICAgICAgICAgICBzdGFydDogYmxvY2tTdGFydCwKICAgICAgICAgICAgICBlbmQ6IGJsb2NrRW5kCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGZpbGVPZmZzZXQ6IGNwb3NpdGlvbnMgPyBjcG9zaXRpb25zW3Bvc10gKiAoMSA8PCA4KSArIChibG9ja1N0YXJ0IC0gZHBvc2l0aW9uc1twb3NdKSArIGNodW5rLm1pbnYuZGF0YVBvc2l0aW9uICsgMSA6IGltcG9ydF9idWZmZXJfY3JjMzIuZGVmYXVsdC5zaWduZWQoYmEuc2xpY2UoYmxvY2tTdGFydCwgYmxvY2tFbmQpKQogICAgICAgICAgfSk7CiAgICAgICAgICBzaW5rLnB1c2goZmVhdHVyZSk7CiAgICAgICAgICBpZiAodGhpcy55aWVsZFRocmVhZFRpbWUgJiYgK0RhdGUubm93KCkgLSBsYXN0ID4gdGhpcy55aWVsZFRocmVhZFRpbWUpIHsKICAgICAgICAgICAgYXdhaXQgdGltZW91dCgxKTsKICAgICAgICAgICAgbGFzdCA9ICtEYXRlLm5vdygpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBibG9ja1N0YX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GtleSwgaXRlbSk7CiAgICB9CiAgICBfc2V0KGtleSwgdmFsdWUpIHsKICAgICAgdGhpcy5jYWNoZS5zZXQoa2V5LCB2YWx1ZSk7CiAgICAgIHRoaXMuX3NpemUrKzsKICAgICAgaWYgKHRoaXMuX3NpemUgPj0gdGhpcy5tYXhTaXplKSB7CiAgICAgICAgdGhpcy5fc2l6ZSA9IDA7CiAgICAgICAgdGhpcy5fZW1pdEV2aWN0aW9ucyh0aGlzLm9sZENhY2hlKTsKICAgICAgICB0aGlzLm9sZENhY2hlID0gdGhpcy5jYWNoZTsKICAgICAgICB0aGlzLmNhY2hlID0gbmV3IE1hcCgpOwogICAgICB9CiAgICB9CiAgICBfbW92ZVRvUmVjZW50KGtleSwgaXRlbSkgewogICAgICB0aGlzLm9sZENhY2hlLmRlbGV0ZShrZXkpOwogICAgICB0aGlzLl9zZXQoa2V5LCBpdGVtKTsKICAgIH0KICAgICpfZW50cmllc0FzY2VuZGluZygpIHsKICAgICAgZm9yIChjb25zdCBpdGVtIG9mIHRoaXMub2xkQ2FjaGUpIHsKICAgICAgICBjb25zdCBba2V5LCB2YWx1ZV0gPSBpdGVtOwogICAgICAgIGlmICghdGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgY29uc3QgZGVsZXRlZCA9IHRoaXMuX2RlbGV0ZUlmRXhwaXJlZChrZXksIHZhbHVlKTsKICAgICAgICAgIGlmIChkZWxldGVkID09PSBmYWxzZSkgewogICAgICAgICAgICB5aWVsZCBpdGVtOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmb3IgKGNvbnN0IGl0ZW0gb2YgdGhpcy5jYWNoZSkgewogICAgICAgIGNvbnN0IFtrZXksIHZhbHVlXSA9IGl0ZW07CiAgICAgICAgY29uc3QgZGVsZXRlZCA9IHRoaXMuX2RlbGV0ZUlmRXhwaXJlZChrZXksIHZhbHVlKTsKICAgICAgICBpZiAoZGVsZXRlZCA9PT0gZmFsc2UpIHsKICAgICAgIC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9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgd2hpbGUgKGxvIDwgaGkpIHsKICAgICAgICBjb25zdCBtaWQgPSBsbyArIGhpID4+PiAxOwogICAgICAgIGlmIChjb21wYXJlKGFbbWlkXSwgeCkgPCAwKQogICAgICAgICAgbG8gPSBtaWQgKyAxOwogICAgICAgIGVsc2UKICAgICAgICAgIGhpID0gbWlkOwogICAgICB9CiAgICAgIHJldHVybiBsbzsKICAgIH0KICAgIGZ1bmN0aW9uIHJpZ2h0KGEsIHgsIGxvLCBoaSkgewogICAgICBpZiAobG8gPT0gbnVsbCkKICAgICAgICBsbyA9IDA7CiAgICAgIGlmIChoaSA9PSBudWxsKQogICAgICAgIGhpID0gYS5sZW5ndGg7CiAgICAgIHdoaWxlIChsbyA8IGhpKSB7CiAgICAgICAgY29uc3QgbWlkID0gbG8gKyBoaSA+Pj4gMTsKICAgICAgICBpZiAoY29tcGFyZShhW21pZF0sIHgpID4gMCkKICAgICAgICAgIGhpID0gbWlkOwogICAgICAgIGVsc2UKICAgICAgICAgIGxvID0gbWlkICsgMTsKICAgICAgfQogICAgICByZXR1cm4gbG87CiAgICB9CiAgICBmdW5jdGlvbiBjZW50ZXIoYSwgeCwgbG8sIGhpKSB7CiAgICAgIGlmIChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgY29uc3QgaSA9IGxlZnQoYSwgeCwgbG8sIGhpIC0gMSk7CiAgICAgIHJldHVybiBpID4gbG8gJiYgZGVsdGEoYVtpIC0gMV0sIHgpID4gLWRlbHRhKGFbaV0sIHgpID8gaSAtIDEgOiBpOwogICAgfQogICAgcmV0dXJuIHsgbGVmdCwgY2VudGVyLCByaWdodCB9OwogIH0KICBmdW5jdGlvbiBhc2NlbmRpbmdDb21wYXJhdG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YgKG1kU3RyaW5nW2ldLm1hdGNoKC9bMC05XS9nKSkgewogICAgICAgIGN1cnJOdW0gPSBjdXJyTnVtICogMTAgKyArbWRTdHJpbmdbaV07CiAgICAgICAgZGVsZXRpb25FbmNvdW50ZXJlZCA9IGZhbHNlOwogICAgICB9IGVsc2UgaWYgKG1kU3RyaW5nW2ldID09PSAiXiIpIHsKICAgICAgICBkZWxldGlvbkVuY291bnRlcmVkID0gdHJ1ZTsKICAgICAgfSBlbHNlIHsKICAgICAgICBjdXJyUG9zICs9IGN1cnJOdW07CiAgICAgICAgaWYgKHVzZUNvdW50cykgewogICAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgICAgbGVuZ3RoOiBjdXJyTnVtLAogICAgICAgICAgICB0eXBlOiBtZFN0cmluZ1tpXQogICAgICAgICAgfSk7CiAgICAgICAgfSBlbHNlIGlmIChkZWxldGlvbkVuY291bnRlcmVkKSB7CiAgICAgICAgICBiYW1TZXFTaGlmdCAtPSAxOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzdWJzdGl0dXRpb25zLnB1c2goewogICAgICAgICAgICBwb3M6IGN1cnJQb3MsCiAgICAgICAgICAgIGJhc2U6IG1kU3RyaW5nW2ldLAogICAgICAgICAgICBsZW5ndGg6IDEsCiAgICAgICAgICAgIGJhbVNlcVNoaWZ0CiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgY3Vyck51bSA9IDA7CiAgICAgICAgY3VyclBvcyArPSAxOwogICAgICB9CiAgICB9CiAgICByZXR1cm4gc3Vic3RpdHV0aW9uczsKICB9CiAgZnVuY3Rpb24gZ2V0U3Vic3RpdHV0aW9ucyhzZWdtZW50LCBzZXEpIHsKICAgIGxldCBzdWJzdGl0dXRpb25zID0gW107CiAgICBsZXQgc29mdENsaXBwaW5nQXRSZWFkU3RhcnQgPSBudWxsOwogICAgaWYgKHNlZ21lbnQuY2lnYXIpIHsKICAgICAgY29uc3QgY2lnYXJTdWJzID0gcGFyc2VNRChzZWdtZW50LmNpZ2FyLCB0cnVlKTsKICAgICAgbGV0IGN1cnJQb3MgPSAwOwogICAgICBmb3IgKGNvbnN0IHN1YiBvZiBjaWdhclN1YnMpIHsKICAgICAgICBpZiAoc3ViLnR5cGUgPT09ICJYIikgewogICAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgICAgcG9zOiBjdXJyUG9zLAogICAgICAgICAgICBsZW5ndGg6IHN1Yi5sZW5ndGgsCiAgICAgICAgICAgIHR5cGU6ICJYIgogICAgICAgICAgfSk7CiAgICAgICAgICBjdXJyUG9zICs9IHN1Yi5sZW5ndGg7CiAgICAgICAgfSBlbHNlIGlmIChzdWIudHlwZSA9PT0gIkkiKSB7CiAgICAgICAgICBzdWJzdGl0dXRpb25zLnB1c2goewogICAgICAgICAgICBwb3M6IGN1cnJQb3MsCiAgICAgICAgICAgIGxlbmd0aDogc3ViLmxlbmd0aCwKICAgICAgICAgICAgdHlwZTogIkkiCiAgICAgICAgICB9KTsKICAgICAgICB9IGVsc2UgaWYgKHN1Yi50eXBlID09PSAiRCIpIHsKICAgICAgICAgIHN1YnN0aXR1dGlvbnMucHVzaCh7CiAgICAgICAgICAgIHBvczogY3VyclBvcywKICAgICAgICAgICAgbGVuZ3RoOiBzdWIubGVuZ3RoLAogICAgICAgICAgICB0eXBlOiAiRCIKICAgICAgICAgIH0pOwogICAgICAgICAgY3VyclBvcyArPSBzdWIubGVuZ3RoOwogICAgICAgIH0gZWxzZSBpZiAoc3ViLnR5cGUgPT09ICJOIikgewogICAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgICAgcG9zOiBjdXJyUG9zLAogICAgICAgICAgICBsZW5ndGg6IHN1Yi5sZW5ndGgsCiAgICAgICAgICAgIHR5cGU6ICJOIgogICAgICAgICAgfSk7CiAgICAgICAgICBjdXJyUG9zICs9IHN1Yi5sZW5ndGg7CiAgICAgICAgfSBlbHNlIGlmIChzdWIudHlwZSA9PT0gIj0iIHx8IHN1Yi50eXBlID09PSAiTSIpIHsKICAgICAgICAgIGN1cnJQb3MgKz0gc3ViLmxlbmd0aDsKICAgICAgICB9IGVsc2UgewogICAgICAgIH0KICAgICAgfQogICAgICBjb25zdCBmaXJzdFN1YiA9IGNpZ2FyU3Vic1swXTsKICAgICAgY29uc3QgbGFzdFN1YiA9IGNpZ2FyU3Vic1tjaWdhclN1YnMubGVuZ3RoIC0gMV07CiAgICAgIGlmIChmaXJzdFN1Yi50eXBlID09PSAiUyIpIHsKICAgICAgICBzb2Z0Q2xpcHBpbmdBdFJlYWRTdGFydCA9IGZpcnN0U3ViOwogICAgICAgIHN1YnN0aXR1dGlvbnMucHVzaCh7CiAgICAgICAgICBwb3M6IC1maXJzdFN1Yi5sZW5ndGgsCiAgICAgICAgICB0eXBlOiAiUyIsCiAgICAgICAgICBsZW5ndGg6IGZpcnN0U3ViLmxlbmd0aAogICAgICAgIH0pOwogICAgICB9CiAgICAgIGlmIChsYXN0U3ViLnR5cGUgPT09ICJTIikgewogICAgICAgIHN1YnN0aXR1dGlvbnMucHVzaCh7CiAgICAgICAgICBwb3M6IHNlZ21lbnQuZW5kIC0gc2VnbWVudC5zdGFydCwKICAgICAgICAgIGxlbmd0aDogbGFzdFN1Yi5sZW5ndGgsCiAgICAgICAgICB0eXBlOiAiUyIKICAgICAgICB9KTsKICAgICAgfQogICAgICBpZiAoZmlyc3RTdWIudHlwZSA9PT0gIkgiKSB7CiAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgIHBvczogLWZpcnN0U3ViLmxlbmd0aCwKICAgICAgICAgIHR5cGU6ICJIIiwKICAgICAgICAgIGxlbmd0aDogZmlyc3RTdWIubGVuZ3RoCiAgICAgICAgfSk7CiAgICAgIH0KICAgICAgaWYgKGxhc3RTdWIudHlwZSA9PT0gIkgiKSB7CiAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgIHBvczogc2Vn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HRpbGVWYWx1ZXMuc2V0KGAke3VpZH0uJHt6fS4ke3h9YCwgdGlsZVZhbHVlcy5nZXQoYCR7dWlkfS4ke3p9LiR7eH1gKS5jb25jYXQobWFwcGVkUmVjb3JkcykpOwogICAgICAgICAgICByZXR1cm4gW107CiAgICAgICAgICB9KSk7CiAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBQcm9taXNlLmFsbChyZWNvcmRQcm9taXNlcykudGhlbigodmFsdWVzKSA9PiB7CiAgICAgIHJldHVybiB2YWx1ZXMuZmxhdCgpOwogICAgfSk7CiAgfTsKICB2YXIgZmV0Y2hUaWxlc0RlYm91bmNlZCA9IGFzeW5jICh1aWQsIHRpbGVJZHMpID0+IHsKICAgIGNvbnN0IHRpbGVzID0ge307CiAgICBjb25zdCB2YWxpZFRpbGVJZHMgPSBbXTsKICAgIGNvbnN0IHRpbGVQcm9taXNlcyA9IFtdOwogICAgZm9yIChjb25zdCB0aWxlSWQgb2YgdGlsZUlkcykgewogICAgICBjb25zdCBwYXJ0cyA9IHRpbGVJZC5zcGxpdCgiLiIpOwogICAgICBjb25zdCB6ID0gcGFyc2VJbnQocGFydHNbMF0sIDEwKTsKICAgICAgY29uc3QgeCA9IHBhcnNlSW50KHBhcnRzWzFdLCAxMCk7CiAgICAgIGlmIChOdW1iZXIuaXNOYU4oeCkgfHwgTnVtYmVyLmlzTmFOKHopKSB7CiAgICAgICAgY29uc29sZS53YXJuKCJJbnZhbGlkIHRpbGUgem9vbSBvciBwb3NpdGlvbjoiLCB6LCB4KTsKICAgICAgICBjb250aW51ZTsKICAgICAgfQogICAgICB2YWxpZFRpbGVJZHMucHVzaCh0aWxlSWQpOwogICAgICB0aWxlUHJvbWlzZXMucHVzaCh0aWxlKHVpZCwgeiwgeCkpOwogICAgfQogICAgcmV0dXJuIFByb21pc2UuYWxsKHRpbGVQcm9taXNlcykudGhlbigodmFsdWVzKSA9PiB7CiAgICAgIHZhbHVlcy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sIGIpID0+ICthLnN0YXJ0IC0gK2Iuc3RhcnQpOwogICAgICAgIGNvbnN0IGluc2VydFNpemUgPSBNYXRoLm1heCgwLCArci5zdGFydCAtICtsLmVuZCk7CiAgICAgICAgY29uc3QgbGFyZ2VJbnNlcnRTaXplID0gaW5zZXJ0U2l6ZSA+PSBtYXhJbnNlcnRTaXplOwogICAgICAgIGxldCBzdlR5cGU7CiAgICAgICAgaWYgKCFsYXJnZUluc2VydFNpemUpIHsKICAgICAgICAgIHN2VHlwZSA9ICJub3JtYWwgcmVhZCI7CiAgICAgICAgfSBlbHNlIGlmIChsLnN0cmFuZCA9PT0gIisiICYmIHIuc3RyYW5kID09PSAiLSIpIHsKICAgICAgICAgIHN2VHlwZSA9ICJkZWxldGlvbiAoKy0pIjsKICAgICAgICB9IGVsc2UgaWYgKGwuc3RyYW5kID09PSAiKyIgJiYgci5zdHJhbmQgPT09ICIrIikgewogICAgICAgICAgc3ZUeXBlID0gImludmVyc2lvbiAoKyspIjsKICAgICAgICB9IGVsc2UgaWYgKGwuc3RyYW5kID09PSAiLSIgJiYgci5zdHJhbmQgPT09ICItIikgewogICAgICAgICAgc3ZUeXBlID0gImludmVyc2lvbiAoLS0pIjsKICAgICAgICB9IGVsc2UgaWYgKGwuc3RyYW5kID09PSAiLSIgJiYgci5zdHJhbmQgPT09ICIrIikgewogICAgICAgICAgc3ZUeXBlID0gImR1cGxpY2F0aW9uICgtKykiOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzdlR5cGUgPSBgKCR7bC5zdHJhbmR9JHtyLnN0cmFuZH0pYDsKICAgICAgICB9CiAgICAgICAgW3JlYWQsIG1hdGVdLmZvckVhY2goKGQpID0+IHsKICAgICAgICAgIGQuZm91bmRNYXRlID0gdHJ1ZTsKICAgICAgICAgIGQuaW5zZXJ0U2l6ZSA9IGluc2VydFNpemU7CiAgICAgICAgICBkLmxhcmdlSW5zZXJ0U2l6ZSA9IGxhcmdlSW5zZXJ0U2l6ZTsKICAg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BzdWIubGVuZ3RoOwogICAgICAgIGlmIChzZWdtZW50LnN0YXJ0IDwgZG9uICYmIGFjYyA8IHNlZ21lbnQuZW5kKSB7CiAgICAgICAgICBjb25zdCBqID0ganVuY3Rpb25zLmZpbmQoKGQpID0+IGQuc3RhcnQgPT09IGRvbiAmJiBkLmVuZCA9PT0gYWNjKTsKICAgICAgICAgIGlmIChqKSB7CiAgICAgICAgICAgIGouc2NvcmUgKz0gMTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGp1bmN0aW9ucy5wdXNoKHsgc3RhcnQ6IGRvbiwgZW5kOiBhY2MsIHNjb3JlOiAxIH0pOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfSk7CiAgICB9KTsKICAgIHJldHVybiBqdW5jdGlvbnMuZmlsdGVyKChkKSA9PiBkLnNjb3JlID49IG1pbkNvdmVyYWdlKTsKICB9OwogIHZhciB0aWxlRnVuY3Rpb25zID0gewogICAgaW5pdCwKICAgIHRpbGVzZXRJbmZvLAogICAgZmV0Y2hUaWxlc0RlYm91bmNlZCwKICAgIHRpbGUsCiAgICBnZXRUYWJ1bGFyRGF0YQogIH07CiAgZXhwb3NlKHRpbGVGdW5jdGlvbnMpOwp9KSgpOwovKiEKICogVGhlIGJ1ZmZlciBtb2R1bGUgZnJvbSBub2RlLmpzLCBmb3IgdGhlIGJyb3dzZXIuCiAqCiAqIEBhdXRob3IgICBGZXJvc3MgQWJvdWtoYWRpamVoIDxodHRwczovL2Zlcm9zcy5vcmc+CiAqIEBsaWNlbnNlICBNSVQKICovCi8qISBpZWVlNzU0LiBCU0QtMy1DbGF1c2UgTGljZW5zZS4gRmVyb3NzIEFib3VraGFkaWplaCA8aHR0cHM6Ly9mZXJvc3Mub3JnL29wZW5zb3VyY2U+ICovCg==",sle=typeof window<"u"&&window.Blob&&new Blob([atob(a2e)],{type:"text/javascript;charset=utf-8"});function mgg(){const e=sle&&(window.URL||window.webkitURL).createObjectURL(sle);try{return e?new Worker(e):new Worker("data:application/javascript;base64,"+a2e,{type:"module"})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const fgg=200;class BH{constructor(g,I){rt(this,"dataConfig",{}),rt(this,"uid"),rt(this,"fetchTimeout"),rt(this,"toFetch"),rt(this,"MAX_TILE_WIDTH",2e4),rt(this,"worker"),rt(this,"track"),this.uid=g.libraries.slugid.nice(),this.toFetch=new Set;const{url:i,indexUrl:n,assembly:C,...r}=I;this.worker=JT(new mgg).then(async o=>{const a=Object.entries(bI(C).size);return await o.init(this.uid,{url:i,indexUrl:n},a,r),o})}async tilesetInfo(g){(await this.worker).tilesetInfo(this.uid).then(g)}fetchTilesDebounced(g,I){var i;const{toFetch:n}=this,C=I[0].split(".")[0],r=n.size?[...n][0].split(".")[0]:null;if(C!==r){for(const o of this.toFetch)(i=this.track)==null||i.fetching.delete(o);this.toFetch.clear()}I.forEach(o=>this.toFetch.add(o)),this.fetchTimeout&&clearTimeout(this.fetchTimeout),this.fetchTimeout=setTimeout(()=>{this.sendFetch(g,[...this.toFetch]),this.toFetch.clear()},fgg)}async sendFetch(g,I){(await this.worker).fetchTilesDebounced(this.uid,I).then(g)}async getTabularData(g){const I=await(await this.worker).getTabularData(this.uid,g);return JSON.parse(new TextDecoder().decode(I))}}rt(BH,"config",{type:"bam"});const A2e="KCgpID0+IHsKICB2YXIgX19jcmVhdGUgPSBPYmplY3QuY3JlYXRlOwogIHZhciBfX2RlZlByb3AgPSBPYmplY3QuZGVmaW5lUHJvcGVydHk7CiAgdmFyIF9fZ2V0T3duUHJvcERlc2MgPSBPYmplY3QuZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9yOwogIHZhciBfX2dldE93blByb3BOYW1lcyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eU5hbWVzOwogIHZhciBfX2dldFByb3RvT2YgPSBPYmplY3QuZ2V0UHJvdG90eXBlT2Y7CiAgdmFyIF9faGFzT3duUHJvcCA9IE9iamVjdC5wcm90b3R5cGUuaGFzT3du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gICAgICBhcnJbY3VyQnl0ZSsrXSA9IHRtcCAmIDI1NTsKICAgICAgICB9CiAgICAgICAgaWYgKHBsYWNlSG9sZGVyc0xlbiA9PT0gMikgewogICAgICAgICAgdG1wID0gcmV2TG9va3VwW2I2NC5jaGFyQ29kZUF0KGkyKV0gPDwgMiB8IHJldkxvb2t1cFtiNjQuY2hhckNvZGVBdChpMiArIDEpXSA+PiA0OwogICAgICAgICAgYXJyW2N1ckJ5dGUrK10gPSB0bXAgJiAyNTU7CiAgICAgICAgfQogICAgICAgIGlmIChwbGFjZUhvbGRlcnNMZW4gPT09IDEpIHsKICAgICAgICAgIHRtcCA9IHJldkxvb2t1cFtiNjQuY2hhckNvZGVBdChpMildIDw8IDEwIHwgcmV2TG9va3VwW2I2NC5jaGFyQ29kZUF0KGkyICsgMSldIDw8IDQgfCByZXZMb29rdXBbYjY0LmNoYXJDb2RlQXQoaTIgKyAyKV0gPj4gMjsKICAgICAgICAgIGFycltjdXJCeXRlKytdID0gdG1wID4+IDggJiAyNTU7CiAgICAgICAgICBhcnJbY3VyQnl0ZSsrXSA9IHRtcCAmIDI1NTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGFycjsKICAgICAgfQogICAgICBmdW5jdGlvbiB0cmlwbGV0VG9CYXNlNjQobnVtKSB7CiAgICAgICAgcmV0dXJuIGxvb2t1cFtudW0gPj4gMTggJiA2M10gKyBsb29rdXBbbnVtID4+IDEyICYgNjNdICsgbG9va3VwW251bSA+PiA2ICYgNjNdICsgbG9va3VwW251bSAmIDYzXTsKICAgICAgfQogICAgICBmdW5jdGlvbiBlbmNvZGVDaHVuayh1aW50OCwgc3RhcnQsIGVuZCkgewogICAgICAgIHZhciB0bXA7CiAgICAgICAgdmFyIG91dHB1dCA9IFtdOwogICAgICAgIGZvciAodmFyIGkyID0gc3RhcnQ7IGkyIDwgZW5kOyBpMiArPSAzKSB7CiAgICAgICAgICB0bXAgPSAodWludDhbaTJdIDw8IDE2ICYgMTY3MTE2ODAp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A2M10gKyBsb29rdXBbdG1wIDw8IDIgJiA2M10gKyAiPSIpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcGFydHMuam9pbigiIik7CiAgICAgIH0KICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL2llZWU3NTRAMS4yLjEvbm9kZV9tb2R1bGVzL2llZWU3NTQvaW5kZXguanMKICB2YXIgcmVxdWlyZV9pZWVlNzU0ID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL2llZWU3NTRAMS4yLjEvbm9kZV9tb2R1bGVzL2llZWU3NTQvaW5kZXguanMiKGV4cG9ydHMyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgZXhwb3J0czIucmVhZCA9IGZ1bmN0aW9uKGJ1ZmZlciwgb2Zmc2V0LCBpc0xFLCBtTGVuLCBuQnl0ZXMpIHsKICAgICAgICB2YXIgZSwgbTsKICAgICAgICB2YXIgZUxlbiA9IG5CeXRlcyAqIDggLSBtTGVuIC0gMTsKICAgICAgICB2YXIgZU1heCA9ICgxIDw8IGVMZW4pIC0gMTsKICAgICAgICB2YXIgZUJpYXMgPSBlTWF4ID4+IDE7CiAgICAgICAgdmFyIG5CaXRzID0gLTc7CiAgICAgICAgdmFyIGkgPSBpc0xFID8gbkJ5dGVzIC0gMSA6IDA7CiAgICAgICAgdmFyIGQgPSBpc0xFID8gLTEgOiAxOwogICAgICAgIHZhciBzID0gYnVmZmVyW29mZnNldCArIGldOwogICAgICAgIGkgKz0gZDsKICAgICAgICBlID0gcyAmICgxIDw8IC1uQml0cykgLSAxOwogICAgICAgIHMgPj49IC1uQml0czsKICAgICAgICBuQml0cyArPSBlTGVuOwogICAgICAgIGZvciAoOyBuQml0cyA+IDA7IGUgPSBlICogMjU2ICsgYnVmZmVyW29mZnNldCArIGldLCBpICs9IGQsIG5CaXRzIC09IDgpIHsKICAgICAgICB9CiAgICAgICAgbSA9IGUgJiAoMSA8P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PCAwID8gMSA6IDA7CiAgICAgICAgdmFsdWUgPSBNYXRoLmFicyh2YWx1ZSk7CiAgICAgICAgaWYgKGlzTmFOKHZhbHVlKSB8fCB2YWx1ZSA9PT0gSW5maW5pdHkpIHsKICAgICAgICAgIG0gPSBpc05hTih2YWx1ZSkgPyAxIDogMDsKICAgICAgICAgIGUgPSBlTWF4OwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBlID0gTWF0aC5mbG9vcihNYXRoLmxvZyh2YWx1ZSkgLyBNYXRoLkxOMik7CiAgICAgICAgICBpZiAodmFsdWUgKiAoYyA9IE1hdGgucG93KDIsIC1lKSkgPCAxKSB7CiAgICAgICAgICAgIGUtLTsKICAgICAgICAgICAgYyAqPSAyOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGUgKyBlQmlhcyA+PSAxKSB7CiAgICAgICAgICAgIHZhbHVlICs9IHJ0IC8gYzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHZhbHVlICs9IHJ0ICogTWF0aC5wb3coMiwgMSAtIGVCaWFzKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh2YWx1ZSAqIGMgPj0gMikgewogICAgICAgICAgICBlKys7CiAgICAgICAgICAgIGMgLz0gMjsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChlICsgZUJpYXMgPj0gZU1heCkgewogICAgICAgICAgICBtID0gMDsKICAgICAgICAgICAgZSA9IGVNYXg7CiAgICAgICAgICB9IGVsc2UgaWYgKGUgKyBlQmlhcyA+PSAxKSB7CiAgICAgICAgICAgIG0gPSAodmFsdWUgKiBjIC0gMSkgKiBNYXRoLnBvdygyLCBtTGVuKTsKICAgICAgICAgICAgZSA9IGUgKyBlQmlhczsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG0gPSB2YWx1ZSAqIE1hdGgucG93KDIsIGVCaWFzIC0gMSkgKiBNYXRoLnBvdygyLCBtTGVuKTsKICAgICAgICAgICAgZSA9IDA7CiAgICAgICAgIC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XJuIGZhbHNlOwogICAgICAgIH0KICAgICAgfQogICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoQnVmZmVyMTAucHJvdG90eXBlLCAicGFyZW50IiwgewogICAgICAgIGVudW1lcmFibGU6IHRydWUsCiAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHsKICAgICAgICAgIGlmICghQnVmZmVyMTAuaXNCdWZmZXIodGhpcykpCiAgICAgICAgICAgIHJldHVybiB2b2lkIDA7CiAgICAgICAgICByZXR1cm4gdGhpcy5idWZmZXI7CiAgICAgICAgfQogICAgICB9KTsKICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KEJ1ZmZlcjEwLnByb3RvdHlwZSwgIm9mZnNldCIsIHsKICAgICAgICBlbnVtZXJhYmxlOiB0cnVlLAogICAgICAgIGdldDogZnVuY3Rpb24oKSB7CiAgICAgICAgICBpZiAoIUJ1ZmZlcjEwLmlzQnVmZmVyKHRoaXMpKQogICAgICAgICAgICByZXR1cm4gdm9pZCAwOwogICAgICAgICAgcmV0dXJuIHRoaXMuYnl0ZU9mZnNldDsKICAgICAgICB9CiAgICAgIH0pOwogICAgICBmdW5jdGlvbiBjcmVhdGVCdWZmZXIobGVuZ3RoKSB7CiAgICAgICAgaWYgKGxlbmd0aCA+IEtfTUFYX0xFTkdUSCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoJ1RoZSB2YWx1ZSAiJyArIGxlbmd0aCArICciIGlzIGludmFsaWQgZm9yIG9wdGlvbiAic2l6ZSInKTsKICAgICAgICB9CiAgICAgICAgY29uc3QgYnVmID0gbmV3IFVpbnQ4QXJyYXkobGVuZ3RoKTsKICAgICAgICBPYmplY3Quc2V0UHJvdG90eXBlT2YoYnVmLCBCdWZmZXIxMC5wcm90b3R5cGUpOwogICAgICAgIHJldHVybiBidWY7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gQnVmZmVyMTAoYXJnLCBlbmNvZGluZ09yT2Zmc2V0LCBsZW5ndGgpI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sgc2l6ZSArICciIGlzIGludmFsaWQgZm9yIG9wdGlvbiAic2l6ZSInKTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYWxsb2Moc2l6ZSwgZmlsbCwgZW5jb2RpbmcpIHsKICAgICAgICBhc3NlcnRTaXplKHNpemUpOwogICAgICAgIGlmIChzaXplIDw9IDApIHsKICAgICAgICAgIHJldHVybiBjcmVhdGVCdWZmZXIoc2l6ZSk7CiAgICAgICAgfQogICAgICAgIGlmIChmaWxsICE9PSB2b2lkIDApIHsKICAgICAgICAgIHJldHVybiB0eXBlb2YgZW5jb2RpbmcgPT09ICJzdHJpbmciID8gY3JlYXRlQnVmZmVyKHNpemUpLmZpbGwoZmlsbCwgZW5jb2RpbmcpIDogY3JlYXRlQnVmZmVyKHNpemUpLmZpbGwoZmlsbCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBjcmVhdGVCdWZmZXIoc2l6ZSk7CiAgICAgIH0KICAgICAgQnVmZmVyMTAuYWxsb2MgPSBmdW5jdGlvbihzaXplLCBmaWxsLCBlbmNvZGluZykgewogICAgICAgIHJldHVybiBhbGxvYyhzaXplLCBmaWxsLCBlbmNvZGluZyk7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGFsbG9jVW5zYWZlKHNpemUpIHsKICAgICAgICBhc3NlcnRTaXplKHNpemUpOwogICAgICAgIHJldHVybiBjcmVhdGVCdWZmZXIoc2l6ZSA8IDAgPyAwIDogY2hlY2tlZChzaXplKSB8IDApOwogICAgICB9CiAgICAgIEJ1ZmZlcjEwLmFsbG9jVW5zYWZlID0gZnVuY3Rpb24oc2l6ZSkgewogICAgICAgIHJldHVybiBhbGxvY1Vuc2FmZShzaXplKTsKICAgICAgfTsKICAgICAgQnVmZmVyMTAuYWxsb2NVbnNhZmVTbG93ID0gZnVuY3Rpb24oc2l6ZSkgewogICAgICAgIHJldHVybiBhbGxvY1Vuc2FmZShzaXplKTsKICAgICAgfTsKICAgICAgZnVuY3Rpb24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dHlwZSBCdWZmZXIgb3IgVWludDhBcnJheScpOwogICAgICAgIH0KICAgICAgICBpZiAoYSA9PT0gYikKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIGxldCB4ID0gYS5sZW5ndGg7CiAgICAgICAgbGV0IHkgPSBiLmxlbmd0aDsKICAgICAgICBmb3IgKGxldCBpID0gMCwgbGVuID0gTWF0aC5taW4oeCwgeSk7IGkgPCBsZW47ICsraSkgewogICAgICAgICAgaWYgKGFbaV0gIT09IGJbaV0pIHsKICAgICAgICAgICAgeCA9IGFbaV07CiAgICAgICAgICAgIHkgPSBiW2ldOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHggPCB5KQogICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgIGlmICh5IDwgeCkKICAgICAgICAgIHJldHVybiAxOwogICAgICAgIHJldHVybiAwOwogICAgICB9OwogICAgICBCdWZmZXIxMC5pc0VuY29kaW5nID0gZnVuY3Rpb24gaXNFbmNvZGluZyhlbmNvZGluZykgewogICAgICAgIHN3aXRjaCAoU3RyaW5nKGVuY29kaW5nKS50b0xvd2VyQ2FzZSgpKSB7CiAgICAgICAgICBjYXNlICJoZXgiOgogICAgICAgICAgY2FzZSAidXRmOCI6CiAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICBjYXNlICJhc2NpaSI6CiAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgY2FzZSAiYmluYXJ5IjoKICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgIGNhc2UgInVjcy0yIjoKICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIEJ1ZmZlcjEwLmNvbmNhdCA9IGZ1bmN0aW9uIGNvbmNhdChsaXN0LCBsZW5ndGgpIHsKICAgICAgICBpZiAoIUFycmF5LmlzQXJyYXkobGlzdCkpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJyJsaXN0IiBhcmd1bWVudCBtdXN0IGJlIGFuIEFycmF5IG9mIEJ1ZmZlcnMnKTsKICAgICAgICB9CiAgICAgICAgaWYgKGxpc3QubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gQnVmZmVyMTAuYWxsb2MoMCk7CiAgICAgICAgfQogICAgICAgIGxldCBpOwogICAgICAgIGlmIChsZW5ndGggPT09IHZvaWQgMCkgewogICAgICAgICAgbGVuZ3RoID0gMDsKICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBsaXN0Lmxlbmd0aDsgKytpKSB7CiAgICAgICAgICAgIGxlbmd0aCArPSBsaXN0W2ldLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY29uc3QgYnVmZmVyID0gQnVmZmVyMTAuYWxsb2NVbnNhZmUobGVuZ3RoKTsKICAgICAgICBsZXQgcG9zID0gMDsKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbGlzdC5sZW5ndGg7ICsraSkgewogICAgICAgICAgbGV0IGJ1ZiA9IGxpc3RbaV07CiAgICAgICAgICBpZiAoaXNJbnN0YW5jZShidWYsIFVpbnQ4QXJyYXkpKSB7CiAgICAgICAgICAgIGlmIChwb3MgKyBidWYubGVuZ3RoID4gYnVmZmVyLmxlbmd0aCkgewogICAgICAgICAgICAgIGlmICghQnVmZmVyMTAuaXNCdWZmZXIoYnVmKSkKICAgICAgICAgICAgICAgIGJ1ZiA9IEJ1ZmZlcjEwLmZyb20oYnVmKTsKICAgICAgICAgICAgICBidWYuY29weShidWZmZXIsIHBvcyk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgVWludDhBcnJheS5w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W5ndGggPiAyICYmIGFyZ3VtZW50c1syXSA9PT0gdHJ1ZTsKICAgICAgICBpZiAoIW11c3RNYXRjaCAmJiBsZW4gPT09IDApCiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICBsZXQgbG93ZXJlZENhc2UgPSBmYWxzZTsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsZW47CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhUb0J5dGVzKHN0cmluZykubGVuZ3RoOwogICAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gKiAyOwogICAgICAgICAgICBjYXNlICJoZXgiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gPj4+IDE7CiAgICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICAgICAgcmV0dXJuIGJhc2U2NFRvQnl0ZXMoc3RyaW5nKS5sZW5ndGg7CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgaWYgKGxvd2VyZWRDYXNlKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gbXVzdE1hdGNoID8gLTEgOiB1dGY4VG9CeXRlcyhzdHJpbmcpLmxlbmd0aDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgZW5jb2RpbmcgPSAoIiIgKyBlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgICAgICBsb3dlcmVkQ2FzZSA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIEJ1ZmZlcjEwLmJ5dGVMZW5ndGggPSBieXRlTGVuZ3RoOwogICAgICBmdW5jdGlvbiBzbG93VG9TdHJpbmcoZW5jb2RpbmcsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgbG93ZXJlZENhc2UgPSBmYWxzZTsKICAgICAgICBpZiAoc3RhcnQgPT09IHZvaWQgMCB8fCBzdGFydCA8IDApIHsKICAgICAgICAgIHN0YXJ0ID0gMDsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0ID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA9PT0gdm9pZCAwIHx8IGVuZCA+IHRoaXMubGVuZ3RoKSB7CiAgICAgICAgICBlbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA8PSAwKSB7CiAgICAgICAgICByZXR1cm4gIiI7CiAgICAgICAgfQogICAgICAgIGVuZCA+Pj49IDA7CiAgICAgICAgc3RhcnQgPj4+PSAwOwogICAgICAgIGlmIChlbmQgPD0gc3RhcnQpIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgaWYgKCFlbmNvZGluZykKICAgICAgICAgIGVuY29kaW5nID0gInV0ZjgiOwogICAgICAgIHdoaWxlICh0cnVlKSB7CiAgICAgICAgICBzd2l0Y2ggKGVuY29kaW5nKSB7CiAgICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICAgICAgcmV0dXJuIGhleFNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJ1dGY4IjoKICAgICAgICAgICAgY2FzZSAidXRmLTgiOgogICAgICAgICAgICAgIHJldHVybiB1dGY4U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgICAgICByZXR1cm4gYXNjaWlTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAibGF0aW4xIjoKICAgICAgICAgICAgY2FzZSAiYmluYXJ5IjoKICAgICAgICAgICAgICByZXR1cm4gbGF0aW4xU2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICAgICAgcmV0dXJuIGJhc2U2NFNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICAgIHJldHVybiB1dGYxNmxlU2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgaWYgKGxvd2VyZWRDYXNlKQogICAgICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiVW5rbm93biBlbmNvZGluZzogIiArIGVuY29kaW5nKTsKICAgICAgICAgICAgICBlbmNvZGluZyA9IChlbmNvZGluZyArICIiKS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgICAgIGxvd2VyZWRDYXNlID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLl9pc0J1ZmZlciA9IHRydWU7CiAgICAgIGZ1bmN0aW9uIHN3YXAoYiwgbiwgbSkgewogICAgICAgIGNvbnN0IGkgPSBiW25dOwogICAgICAgIGJbbl0gPSBiW21dOwogICAgICAgIGJbbV0gPSBpOwogICAgICB9CiAgICAgIEJ1ZmZlcjEwLnByb3RvdHlwZS5zd2FwMTYgPSBmdW5jdGlvbiBzd2FwMTYoKSB7CiAgICAgICAgY29uc3QgbG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nQgPSAwOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kID09PSB2b2lkIDApIHsKICAgICAgICAgIGVuZCA9IHRhcmdldCA/IHRhcmdldC5sZW5ndGggOiAwOwogICAgICAgIH0KICAgICAgICBpZiAodGhpc1N0YXJ0ID09PSB2b2lkIDApIHsKICAgICAgICAgIHRoaXNTdGFydCA9IDA7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzRW5kID09PSB2b2lkIDApIHsKICAgICAgICAgIHRoaXNFbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0IDwgMCB8fCBlbmQgPiB0YXJnZXQubGVuZ3RoIHx8IHRoaXNTdGFydCA8IDAgfHwgdGhpc0VuZCA+IHRoaXMubGVuZ3RoKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigib3V0IG9mIHJhbmdlIGluZGV4Iik7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzU3RhcnQgPj0gdGhpc0VuZCAmJiBzdGFydCA+PSBlbmQpIHsKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICBpZiAodGhpc1N0YXJ0ID49IHRoaXNFbmQpIHsKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0ID49IGVuZCkgewogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgfQogICAgICAgIHN0YXJ0ID4+Pj0gMDsKICAgICAgICBlbmQgPj4+PSAwOwogICAgICAgIHRoaXNTdGFydCA+Pj49IDA7CiAgICAgICAgdGhpc0VuZCA+Pj49IDA7CiAgICAgICAgaWYgKHRoaXMgPT09IHRhcmdldCkKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIGxldCB4ID0gdGhpc0VuZCAtIHRoaXNTdGFydDsKICAgICAgICBsZXQgeSA9IGVuZCAtIHN0YXJ0OwogICAgICAgIGNvbnN0IGxlbiA9IE1hdGgubWluKHgsIHkpOwogICA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c2V0OwogICAgICAgIGlmIChudW1iZXJJc05hTihieXRlT2Zmc2V0KSkgewogICAgICAgICAgYnl0ZU9mZnNldCA9IGRpciA/IDAgOiBidWZmZXIubGVuZ3RoIC0gMTsKICAgICAgICB9CiAgICAgICAgaWYgKGJ5dGVPZmZzZXQgPCAwKQogICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggKyBieXRlT2Zmc2V0OwogICAgICAgIGlmIChieXRlT2Zmc2V0ID49IGJ1ZmZlci5sZW5ndGgpIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgIGVsc2UKICAgICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggLSAxOwogICAgICAgIH0gZWxzZSBpZiAoYnl0ZU9mZnNldCA8IDApIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIGJ5dGVPZmZzZXQgPSAwOwogICAgICAgICAgZWxzZQogICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAic3RyaW5nIikgewogICAgICAgICAgdmFsID0gQnVmZmVyMTAuZnJvbSh2YWwsIGVuY29kaW5nKTsKICAgICAgICB9CiAgICAgICAgaWYgKEJ1ZmZlcjEwLmlzQnVmZmVyKHZhbCkpIHsKICAgICAgICAgIGlmICh2YWwubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBhcnJheUluZGV4T2YoYnVmZmVyLCB2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nLCBkaXIpOwogICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHZhbCA9PT0gIm51bWJlciIpIHsKICAgICAgICAgIHZhbCA9IHZhbCAmIDI1NTsKICAgICAgICAgIGlmICh0eXBlb2YgVWludDhBcnJheS5wcm90b3R5cGUuaW5kZXhPZiA9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ewogICAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpbmRleFNpemUgPSAyOwogICAgICAgICAgICBhcnJMZW5ndGggLz0gMjsKICAgICAgICAgICAgdmFsTGVuZ3RoIC89IDI7CiAgICAgICAgICAgIGJ5dGVPZmZzZXQgLz0gMjsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcmVhZChidWYsIGkyKSB7CiAgICAgICAgICBpZiAoaW5kZXhTaXplID09PSAxKSB7CiAgICAgICAgICAgIHJldHVybiBidWZbaTJdOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmV0dXJuIGJ1Zi5yZWFkVUludDE2QkUoaTIgKiBpbmRleFNpemUpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBsZXQgaTsKICAgICAgICBpZiAoZGlyKSB7CiAgICAgICAgICBsZXQgZm91bmRJbmRleCA9IC0xOwogICAgICAgICAgZm9yIChpID0gYnl0ZU9mZnNldDsgaSA8IGFyckxlbmd0aDsgaSsrKSB7CiAgICAgICAgICAgIGlmIChyZWFkKGFyciwgaSkgPT09IHJlYWQodmFsLCBmb3VuZEluZGV4ID09PSAtMSA/IDAgOiBpIC0gZm91bmRJbmRleCkpIHsKICAgICAgICAgICAgICBpZiAoZm91bmRJbmRleCA9PT0gLTEpCiAgICAgICAgICAgICAgICBmb3VuZEluZGV4ID0gaTsKICAgICAgICAgICAgICBpZiAoaSAtIGZvdW5kSW5kZXggKyAxID09PSB2YWxMZW5ndGgpCiAgICAgICAgICAgICAgICByZXR1cm4gZm91bmRJbmRleCAqIGluZGV4U2l6ZTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBpZiAoZm91bmRJbmRleCAhPT0gLTEpCiAgICAgICAgICAgICAgICBpIC09IGkgLSBmb3VuZEluZGV4OwogICAgICAgICAgICAgIGZvdW5kSW5kZXggPSAtMTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogIC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9uIGxhc3RJbmRleE9mKHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcpIHsKICAgICAgICByZXR1cm4gYmlkaXJlY3Rpb25hbEluZGV4T2YodGhpcywgdmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZmFsc2UpOwogICAgICB9OwogICAgICBmdW5jdGlvbiBoZXhXcml0ZShidWYsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpIHsKICAgICAgICBvZmZzZXQgPSBOdW1iZXIob2Zmc2V0KSB8fCAwOwogICAgICAgIGNvbnN0IHJlbWFpbmluZyA9IGJ1Zi5sZW5ndGggLSBvZmZzZXQ7CiAgICAgICAgaWYgKCFsZW5ndGgpIHsKICAgICAgICAgIGxlbmd0aCA9IHJlbWFpbmluZzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgbGVuZ3RoID0gTnVtYmVyKGxlbmd0aCk7CiAgICAgICAgICBpZiAobGVuZ3RoID4gcmVtYWluaW5nKSB7CiAgICAgICAgICAgIGxlbmd0aCA9IHJlbWFpbmluZzsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY29uc3Qgc3RyTGVuID0gc3RyaW5nLmxlbmd0aDsKICAgICAgICBpZiAobGVuZ3RoID4gc3RyTGVuIC8gMikgewogICAgICAgICAgbGVuZ3RoID0gc3RyTGVuIC8gMjsKICAgICAgICB9CiAgICAgICAgbGV0IGk7CiAgICAgICAgZm9yIChpID0gMDsgaSA8IGxlbmd0aDsgKytpKSB7CiAgICAgICAgICBjb25zdCBwYXJzZWQgPSBwYXJzZUludChzdHJpbmcuc3Vic3RyKGkgKiAyLCAyKSwgMTYpOwogICAgICAgICAgaWYgKG51bWJlcklzTmFOKHBhcnNlZCkpCiAgICAgICAgICAgIHJldHVybiBpOwogICAgICAgICAgYnVmW29mZnNldCArIGldID0gcGFyc2VkOwogICAgICAgIH0KICAgICAgICByZXR1cm4gaTsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGY4V3JpdGUoYnVmL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pZiAoIWVuY29kaW5nKQogICAgICAgICAgZW5jb2RpbmcgPSAidXRmOCI7CiAgICAgICAgbGV0IGxvd2VyZWRDYXNlID0gZmFsc2U7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBzd2l0Y2ggKGVuY29kaW5nKSB7CiAgICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICAgICAgcmV0dXJuIGhleFdyaXRlKHRoaXMsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpOwogICAgICAgICAgICBjYXNlICJ1dGY4IjoKICAgICAgICAgICAgY2FzZSAidXRmLTgiOgogICAgICAgICAgICAgIHJldHVybiB1dGY4V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgICAgY2FzZSAibGF0aW4xIjoKICAgICAgICAgICAgY2FzZSAiYmluYXJ5IjoKICAgICAgICAgICAgICByZXR1cm4gYXNjaWlXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHVjczJXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgIC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ZSA+IDE5MSA/IDIgOiAxOwogICAgICAgICAgaWYgKGkgKyBieXRlc1BlclNlcXVlbmNlIDw9IGVuZCkgewogICAgICAgICAgICBsZXQgc2Vjb25kQnl0ZSwgdGhpcmRCeXRlLCBmb3VydGhCeXRlLCB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICBzd2l0Y2ggKGJ5dGVzUGVyU2VxdWVuY2UpIHsKICAgICAgICAgICAgICBjYXNlIDE6CiAgICAgICAgICAgICAgICBpZiAoZmlyc3RCeXRlIDwgMTI4KSB7CiAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IGZpcnN0Qnl0ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICAgIHNlY29uZEJ5dGUgPSBidWZbaSArIDFdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4KSB7CiAgICAgICAgICAgICAgICAgIHRlbXBDb2RlUG9pbnQgPSAoZmlyc3RCeXRlICYgMzEpIDw8IDYgfCBzZWNvbmRCeXRlICYgNjM7CiAgICAgICAgICAgICAgICAgIGlmICh0ZW1wQ29kZVBvaW50ID4gMTI3KSB7CiAgICAgICAgICAgICAgICAgICAgY29kZVBvaW50ID0gdGVtcENvZGVQb2ludDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSAzOgogICAgICAgICAgICAgICAgc2Vjb25kQnl0ZSA9IGJ1ZltpICsgMV07CiAgICAgICAgICAgICAgICB0aGlyZEJ5dGUgPSBidWZbaSArIDJdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmICh0aGlyZEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAxNSkgPDwgMTIgfCAoc2Vjb25kQnl0ZSAmIDYzKSA8PCA2IHwgdGhpcmRCeXRlICYgNjM7CiAgICAgICAgICAgICAgICAgIGlmICh0ZW1wQ29kZVBvaW50ID4gMjA0NyAmJiAodGVtcENvZGVQb2ludCA8IDU1Mjk2IHx8IHRlbXBDb2RlUG9pbnQgPiA1NzM0MykpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIDQ6CiAgICAgICAgICAgICAgICBzZWNvbmRCeXRlID0gYnVmW2kgKyAxXTsKICAgICAgICAgICAgICAgIHRoaXJkQnl0ZSA9IGJ1ZltpICsgMl07CiAgICAgICAgICAgICAgICBmb3VydGhCeXRlID0gYnVmW2kgKyAzXTsKICAgICAgICAgICAgICAgIGlmICgoc2Vjb25kQnl0ZSAmIDE5MikgPT09IDEyOCAmJiAodGhpcmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmIChmb3VydGhCeXRlICYgMTkyKSA9PT0gMTI4KSB7CiAgICAgICAgICAgICAgICAgIHRlbXBDb2RlUG9pbnQgPSAoZmlyc3RCeXRlICYgMTUpIDw8IDE4IHwgKHNlY29uZEJ5dGUgJiA2MykgPDwgMTIgfCAodGhpcmRCeXRlICYgNjMpIDw8IDYgfCBmb3VydGhCeXRlICYgNjM7CiAgICAgICAgICAgICAgICAgIGlmICh0ZW1wQ29kZVBvaW50ID4gNjU1MzUgJiYgdGVtcENvZGVQb2ludCA8IDExMTQxMTIpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChjb2RlUG9pbnQgPT09IG51bGwpIHsKICAgICAgICAgICAgY29kZVBvaW50ID0gNjU1MzM7CiAgICAgICAgICAgIGJ5dGVzUGVyU2VxdWVuY2UgPSAxOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPiA2NTUzNSkgewogICAgICAgICAgICBjb2RlUG9pbnQgLT0gNjU1MzY7CiAgICAgICAgICAgIHJlcy5wdXNoKGNvZGVQb2ludCA+Pj4gMTAgJiAxMDIzIHwgNTUyOTYpOwogICAgICAgICAgICBjb2RlUG9pbnQgPSA1NjMyMCB8IGNvZGVQb2ludCAmIDEwMjM7CiAgICAgICAgICB9CiAgICAgICAgICByZXMucHVzaChjb2RlUG9pbnQpOwogICAgICAgICAgaSArPSBieXRlc1BlclNlcXVlbmNlOwogICAgICAgIH0KICAgICAgICByZXR1cm4gZGVjb2RlQ29kZVBvaW50c0FycmF5KHJlcyk7CiAgICAgIH0KICAgICAgdmFyIE1BWF9BUkdVTUVOVFNfTEVOR1RIID0gNDA5NjsKICAgICAgZnVuY3Rpb24gZGVjb2RlQ29kZVBvaW50c0FycmF5KGNvZGVQb2ludHMpIHsKICAgICAgICBjb25zdCBsZW4gPSBjb2RlUG9pbnRzLmxlbmd0aDsKICAgICAgICBpZiAobGVuIDw9IE1BWF9BUkdVTUVOVFNfTEVOR1RIKSB7CiAgICAgICAgICByZXR1cm4gU3RyaW5nLmZyb21DaGFyQ29kZS5hcHBseShTdHJpbmcsIGNvZGVQb2ludHMpOwogICAgICAgIH0KICAgICAgICBsZXQgcmVzID0gIiI7CiAgICAgICAgbGV0IGkgPSAwOwogICAgICAgIHdoaWxlIChpIDwgbGVuKSB7CiAgICAgICAgICByZXMgKz0gU3RyaW5nLmZyb21DaGFyQ29kZS5hcHBseShTdHJpbmcsIGNvZGVQb2ludHMuc2xpY2UoaSwgaSArPSBNQVhfQVJHVU1FTlRTX0xFTkdUSCkpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmVzOwogICAgICB9CiAgICAg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dXRmMTZsZVNsaWNlKGJ1Ziwgc3RhcnQsIGVuZCkgewogICAgICAgIGNvbnN0IGJ5dGVzID0gYnVmLnNsaWNlKHN0YXJ0LCBlbmQpOwogICAgICAgIGxldCByZXMgPSAiIjsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGJ5dGVzLmxlbmd0aCAtIDE7IGkgKz0gMikgewogICAgICAgICAgcmVzICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnl0ZXNbaV0gKyBieXRlc1tpICsgMV0gKiAyNTYpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmVzOwogICAgICB9CiAgICAgIEJ1ZmZlcjEwLnByb3RvdHlwZS5zbGljZSA9IGZ1bmN0aW9uIHNsaWNlKHN0YXJ0LCBlbmQpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBzdGFydCA9IH5+c3RhcnQ7CiAgICAgICAgZW5kID0gZW5kID09PSB2b2lkIDAgPyBsZW4gOiB+fmVuZDsKICAgICAgICBpZiAoc3RhcnQgPCAwKSB7CiAgICAgICAgICBzdGFydCArPSBsZW47CiAgICAgICAgICBpZiAoc3RhcnQgPCAwKQogICAgICAgICAgICBzdGFydCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChzdGFydCA+IGxlbikgewogICAgICAgICAgc3RhcnQgPSBsZW47CiAgICAgICAgfQogICAgICAgIGlmIChlbmQgPCAwKSB7CiAgICAgICAgICBlbmQgKz0gbGVuOwogICAgICAgICAgaWYgKGVuZCA8IDApCiAgICAgICAgICAgIGVuZCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChlbmQgPiBsZW4pIHsKICAgICAgICAgIGVuZCA9IGxlbjsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA8IHN0YXJ0KQogICAgICAgICAgZW5kID0gc3RhcnQ7CiAgICAgICAgY29uc3QgbmV3QnVmID0gdGhpcy5zdWJhcnJheShzdGFydCwgZW5kKTsKICAgICAgICBPYm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AgICAgICB2YWwgKz0gdGhpc1tvZmZzZXQgKyAtLWldICogbXVsOwogICAgICAgIH0KICAgICAgICBtdWwgKj0gMTI4OwogICAgICAgIGlmICh2YWwgPj0gbXVsKQogICAgICAgICAgdmFsIC09IE1hdGgucG93KDIsIDggKiBieXRlTGVuZ3RoMik7CiAgICAgICAgcmV0dXJuIHZhbDsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnJlYWRJbnQ4ID0gZnVuY3Rpb24gcmVhZEludDgob2Zmc2V0LCBub0Fzc2VydCkgewogICAgICAgIG9mZnNldCA9IG9mZnNldCA+Pj4gMDsKICAgICAgICBpZiAoIW5vQXNzZXJ0KQogICAgICAgICAgY2hlY2tPZmZzZXQob2Zmc2V0LCAxLCB0aGlzLmxlbmd0aCk7CiAgICAgICAgaWYgKCEodGhpc1tvZmZzZXRdICYgMTI4KSkKICAgICAgICAgIHJldHVybiB0aGlzW29mZnNldF07CiAgICAgICAgcmV0dXJuICgyNTUgLSB0aGlzW29mZnNldF0gKyAxKSAqIC0xOwogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUucmVhZEludDE2TEUgPSBmdW5jdGlvbiByZWFkSW50MTZMRShvZmZzZXQsIG5vQXNzZXJ0KSB7CiAgICAgICAgb2Zmc2V0ID0gb2Zmc2V0ID4+PiAwOwogICAgICAgIGlmICghbm9Bc3NlcnQpCiAgICAgICAgICBjaGVja09mZnNldChvZmZzZXQsIDIsIHRoaXMubGVuZ3RoKTsKICAgICAgICBjb25zdCB2YWwgPSB0aGlzW29mZnNldF0gfCB0aGlzW29mZnNldCArIDFdIDw8IDg7CiAgICAgICAgcmV0dXJuIHZhbCAmIDMyNzY4ID8gdmFsIHwgNDI5NDkwMTc2MCA6IHZhbDsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnJlYWRJbnQxNkJFID0gZnVuY3Rpb24gcmVhZEludDE2QkUob2Zmc2V0LCBub0Fzc2VydCkgewogICA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vbiIpIHsKICAgICAgICAgIHRoaXMuY29weVdpdGhpbih0YXJnZXRTdGFydCwgc3RhcnQsIGVuZCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIFVpbnQ4QXJyYXkucHJvdG90eXBlLnNldC5jYWxsKHRhcmdldCwgdGhpcy5zdWJhcnJheShzdGFydCwgZW5kKSwgdGFyZ2V0U3RhcnQpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gbGVuOwogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUuZmlsbCA9IGZ1bmN0aW9uIGZpbGwodmFsLCBzdGFydCwgZW5kLCBlbmNvZGluZykgewogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAic3RyaW5nIikgewogICAgICAgICAgaWYgKHR5cGVvZiBzdGFydCA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgZW5jb2RpbmcgPSBzdGFydDsKICAgICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgICAgICBlbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIGVuZCA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgZW5jb2RpbmcgPSBlbmQ7CiAgICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGVuY29kaW5nICE9PSB2b2lkIDAgJiYgdHlwZW9mIGVuY29kaW5nICE9PSAic3RyaW5nIikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJlbmNvZGluZyBtdXN0IGJlIGEgc3RyaW5nIik7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodHlwZW9mIGVuY29kaW5nID09PSAic3RyaW5nIiAmJiAhQnVmZmVyMTAuaXNFbmNvZGluZyhlbmNvZGluZykpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiVW5rbm93biBlbmNvZGluZzogIiArIGVuY29kaW5nKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh2YWwubGVuZ3RoID09PSAxKSB7CiAgICAgICAgICAgIGNvbnN0IGNvZGUgPSB2YWwuY2hhckNvZGVBdCgwKTsKICAgICAgICAgICAgaWYgKGVuY29kaW5nID09PSAidXRmOCIgJiYgY29kZSA8IDEyOCB8fCBlbmNvZGluZyA9PT0gImxhdGluMSIpIHsKICAgICAgICAgICAgICB2YWwgPSBjb2RlOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgdmFsID0gdmFsICYgMjU1OwogICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHZhbCA9PT0gImJvb2xlYW4iKSB7CiAgICAgICAgICB2YWwgPSBOdW1iZXIodmFsKTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0IDwgMCB8fCB0aGlzLmxlbmd0aCA8IHN0YXJ0IHx8IHRoaXMubGVuZ3RoIDwgZW5kKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiT3V0IG9mIHJhbmdlIGluZGV4Iik7CiAgICAgICAgfQogICAgICAgIGlmIChlbmQgPD0gc3RhcnQpIHsKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIH0KICAgICAgICBzdGFydCA9IHN0YXJ0ID4+PiAwOwogICAgICAgIGVuZCA9IGVuZCA9PT0gdm9pZCAwID8gdGhpcy5sZW5ndGggOiBlbmQgPj4+IDA7CiAgICAgICAgaWYgKCF2YWwpCiAgICAgICAgICB2YWwgPSAwOwogICAgICAgIGxldCBpOwogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgZm9yIChpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgICB0aGlzW2ldID0gdmFsOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBjb25zdCBieXRlcyA9IEJ1ZmZlcjEwLmlzQnVmZmVyKHZhbCkgPyB2YWwgOiBCdWZmZXIxMC5mcm9tKHZhbCwgZW5jb2RpbmcpOwogICAgICAgICAgY29uc3QgbGVuID0gYnl0ZXMubGVuZ3RoOwogICAgICAgICAgaWYgKGxlbiA9PT0gMCkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCdUaGUgdmFsdWUgIicgKyB2YWwgKyAnIiBpcyBpbnZhbGlkIGZvciBhcmd1bWVudCAidmFsdWUiJyk7CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgZW5kIC0gc3RhcnQ7ICsraSkgewogICAgICAgICAgICB0aGlzW2kgKyBzdGFydF0gPSBieXRlc1tpICUgbGVuXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgIH07CiAgICAgIHZhciBlcnJvcnMgPSB7fTsKICAgICAgZnVuY3Rpb24gRShzeW0sIGdldE1lc3NhZ2UsIEJhc2UpIHsKICAgICAgICBlcnJvcnNbc3ltXSA9IGNsYXNzIE5vZGVFcnJvciBleHRlbmRzIEJhc2UgewogICAgICAgICAgY29uc3RydWN0b3IoKSB7CiAgICAgICAgICAgIHN1cGVyKCk7CiAgICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eSh0aGlzLCAibWVzc2FnZSIsIHsKICAgICAgICAgICAgICB2YWx1ZTogZ2V0TWVzc2FnZS5hcHBseSh0aGlzLCBhcmd1bWVudHMpLAogICAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlLAogICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgICB9KTsKICAgICAgICAgICAgdGhpcy5uYW1lID0gYCR7dGhpcy5uYW1lfSBbJHtzeW19XWA7CiAgICAgICAgICAgIHRoaXMuc3RhY2s7CiAgICAgICAgICAgIGRlbGV0ZSB0aGlzLm5hbWU7CiAgICAgICAgICB9CiAgICAgICAgICBnZXQgY29kZSgpIHsKICAgICAgICAgICAgcmV0dXJuIHN5bTsKICAgICAgICAgIH0KICAgICAgICAgIHNldCBjb2RlKHZhbHVlKSB7CiAgICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eSh0aGlzLCAiY29kZSIsIHsKICAgICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUsCiAgICAgICAgICAgICAgZW51bWVyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICB2YWx1ZSwKICAgICAgICAgICAgICB3cml0YWJsZTogdHJ1ZQogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICAgIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gYCR7dGhpcy5uYW1lfSBbJHtzeW19XTogJHt0aGlzLm1lc3NhZ2V9YDsKICAgICAgICAgIH0KICAgICAgICB9OwogICAgICB9CiAgICAgIEUoIkVSUl9CVUZGRVJfT1VUX09GX0JPVU5EUyIsIGZ1bmN0aW9uKG5hbWUpIHsKICAgICAgICBpZiAobmFtZSkgewogICAgICAgICAgcmV0dXJuIGAke25hbWV9IGlzIG91dHNpZGUgb2YgYnVmZmVyIGJvdW5kc2A7CiAgICAgICAgfQogICAgICAgIHJldHVybiAiQXR0ZW1wdCB0byBhY2Nlc3MgbWVtb3J5IG91dHNpZGUgYnVmZmVyIGJvdW5kcyI7CiAgICAgIH0sIFJhbmdlRXJyb3IpOwogICAgICBFKCJFUlJfSU5WQUxJRF9BUkdfVFlQRSIsIGZ1bmN0aW9uKG5hbWUsIGFjdHVhbCkgewogICAgICAgIHJldHVybiBgVGhlICIke25hbWV9IiBhcmd1bWVudCBtdXN0IGJlIG9mIHR5cGUgbnVtYmVyLiBSZWNlaXZlZCB0eXBlICR7dHlwZW9mIGFjdHVhbH1gOwogICAgICB9LCBUeXBlRXJyb3IpOwogICAgICBFKCJFUlJfT1VUX09GX1JBTkdFIiwgZnVuY3Rpb24oc3RyLCByYW5nZSwgaW5wdXQpIHsKICAgICAgIC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gICAgIHJldHVybiBgJHt2YWwuc2xpY2UoMCwgaSl9JHtyZXN9YDsKICAgICAgfQogICAgICBmdW5jdGlvbiBjaGVja0JvdW5kcyhidWYsIG9mZnNldCwgYnl0ZUxlbmd0aDIpIHsKICAgICAgICB2YWxpZGF0ZU51bWJlcihvZmZzZXQsICJvZmZzZXQiKTsKICAgICAgICBpZiAoYnVmW29mZnNldF0gPT09IHZvaWQgMCB8fCBidWZbb2Zmc2V0ICsgYnl0ZUxlbmd0aDJdID09PSB2b2lkIDApIHsKICAgICAgICAgIGJvdW5kc0Vycm9yKG9mZnNldCwgYnVmLmxlbmd0aCAtIChieXRlTGVuZ3RoMiArIDEpKTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gY2hlY2tJbnRCSSh2YWx1ZSwgbWluLCBtYXgsIGJ1Ziwgb2Zmc2V0LCBieXRlTGVuZ3RoMikgewogICAgICAgIGlmICh2YWx1ZSA+IG1heCB8fCB2YWx1ZSA8IG1pbikgewogICAgICAgICAgY29uc3QgbiA9IHR5cGVvZiBtaW4gPT09ICJiaWdpbnQiID8gIm4iIDogIiI7CiAgICAgICAgICBsZXQgcmFuZ2U7CiAgICAgICAgICBpZiAoYnl0ZUxlbmd0aDIgPiAzKSB7CiAgICAgICAgICAgIGlmIChtaW4gPT09IDAgfHwgbWluID09PSBCaWdJbnQoMCkpIHsKICAgICAgICAgICAgICByYW5nZSA9IGA+PSAwJHtufSBhbmQgPCAyJHtufSAqKiAkeyhieXRlTGVuZ3RoMiArIDEpICogOH0ke259YDsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICByYW5nZSA9IGA+PSAtKDIke259ICoqICR7KGJ5dGVMZW5ndGgyICsgMSkgKiA4IC0gMX0ke259KSBhbmQgPCAyICoqICR7KGJ5dGVMZW5ndGgyICsgMSkgKiA4IC0gMX0ke259YDsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmFuZ2UgPS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C05QS1aYS16LV9dL2c7CiAgICAgIGZ1bmN0aW9uIGJhc2U2NGNsZWFuKHN0cikgewogICAgICAgIHN0ciA9IHN0ci5zcGxpdCgiPSIpWzBdOwogICAgICAgIHN0ciA9IHN0ci50cmltKCkucmVwbGFjZShJTlZBTElEX0JBU0U2NF9SRSwgIiIpOwogICAgICAgIGlmIChzdHIubGVuZ3RoIDwgMikKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB3aGlsZSAoc3RyLmxlbmd0aCAlIDQgIT09IDApIHsKICAgICAgICAgIHN0ciA9IHN0ciArICI9IjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHN0cjsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGY4VG9CeXRlcyhzdHJpbmcsIHVuaXRzKSB7CiAgICAgICAgdW5pdHMgPSB1bml0cyB8fCBJbmZpbml0eTsKICAgICAgICBsZXQgY29kZVBvaW50OwogICAgICAgIGNvbnN0IGxlbmd0aCA9IHN0cmluZy5sZW5ndGg7CiAgICAgICAgbGV0IGxlYWRTdXJyb2dhdGUgPSBudWxsOwogICAgICAgIGNvbnN0IGJ5dGVzID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBsZW5ndGg7ICsraSkgewogICAgICAgICAgY29kZVBvaW50ID0gc3RyaW5nLmNoYXJDb2RlQXQoaSk7CiAgICAgICAgICBpZiAoY29kZVBvaW50ID4gNTUyOTUgJiYgY29kZVBvaW50IDwgNTczNDQpIHsKICAgICAgICAgICAgaWYgKCFsZWFkU3Vycm9nYXRlKSB7CiAgICAgICAgICAgICAgaWYgKGNvZGVQb2ludCA+IDU2MzE5KSB7CiAgICAgICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKGkgKyAxID09PSBsZW5ndGgpIHsKICAgICAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBsZWFkU3Vycm9nYXRlID0gY29kZVBvaW50OwogICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChjb2RlUG9pbnQgPCA1NjMyMCkgewogICAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICAgICAgbGVhZFN1cnJvZ2F0ZSA9IGNvZGVQb2ludDsKICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBjb2RlUG9pbnQgPSAobGVhZFN1cnJvZ2F0ZSAtIDU1Mjk2IDw8IDEwIHwgY29kZVBvaW50IC0gNTYzMjApICsgNjU1MzY7CiAgICAgICAgICB9IGVsc2UgaWYgKGxlYWRTdXJyb2dhdGUpIHsKICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICB9CiAgICAgICAgICBsZWFkU3Vycm9nYXRlID0gbnVsbDsKICAgICAgICAgIGlmIChjb2RlUG9pbnQgPCAxMjgpIHsKICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAxKSA8IDApCiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGJ5dGVzLnB1c2goY29kZVBvaW50KTsKICAgICAgICAgIH0gZWxzZSBpZiAoY29kZVBvaW50IDwgMjA0OCkgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDIpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQgPj4gNiB8IDE5MiwgY29kZVBvaW50ICYgNjMgfCAxMjgpOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPCA2NTUzNikgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQgPj4gMTIgfCAyMjQsIGNvZGVQb2ludCA+PiA2ICYgNjMgfCAxMjgsIGNvZGVQb2ludCAmIDYzIHwgMTI4KTsKICAgICAgICAgIH0gZWxzZSBpZiAoY29kZVBvaW50IDwgMTExNDExMikgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDQpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQgPj4gMTggfCAyNDAsIGNvZGVQb2ludCA+PiAxMiAmIDYzIHwgMTI4LCBjb2RlUG9pbnQgPj4gNiAmIDYzIHwgMTI4LCBjb2RlUG9pbnQgJiA2MyB8IDEyOCk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoIkludmFsaWQgY29kZSBwb2ludCIpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gYnl0ZXM7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXNjaWlUb0J5dGVzKHN0cikgewogICAgICAgIGNvbnN0IGJ5dGVBcnJheSA9IFtdOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgc3RyLmxlbmd0aDsgKytpKSB7CiAgICAgICAgICBieXRlQXJyYXkucHVzaChzdHIuY2hhckNvZGVBdChpKSAmIDI1NSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBieXRlQXJyYXk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdXRmMTZsZVRvQnl0ZXMoc3RyLCB1bml0cykgewogICAgICAgIGxldCBjLCBoaSwgbG87CiAgICAgICAgY29uc3QgYnl0ZUFycmF5ID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBzdHIubGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGlmICgodW5pdHMgLT0gMikgPCAwKQogICAgICAgICAgICBicmVhazsKICAgICAgICAgIGMgPSBzdHIuY2hhckNvZGVBdChpKTsKICAgICAgICAgIGhpID0gYyA+PiA4OwogICAgICAgICAgbG8gPSBjICUgMjU2OwogICAgICAgICAgYnl0ZUFycmF5LnB1c2gobG8pOwogICAgICAgICAgYnl0ZUFycmF5LnB1c2goaGkpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gYnl0ZUFycmF5OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJhc2U2NFRvQnl0ZXMoc3RyKSB7CiAgICAgICAgcmV0dXJuIGJhc2U2NC50b0J5dGVBcnJheShiYXNlNjRjbGVhbihzdHIpKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBibGl0QnVmZmVyKHNyYywgZHN0LCBvZmZzZXQsIGxlbmd0aCkgewogICAgICAgIGxldCBpOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsZW5ndGg7ICsraSkgewogICAgICAgICAgaWYgKGkgKyBvZmZzZXQgPj0gZHN0Lmxlbmd0aCB8fCBpID49IHNyYy5sZW5ndGgpCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgZHN0W2kgKyBvZmZzZXRdID0gc3JjW2ldOwogICAgICAgIH0KICAgICAgICByZXR1cm4gaTsKICAgICAgfQogICAgICBmdW5jdGlvbiBpc0luc3RhbmNlKG9iaiwgdHlwZSkgewogICAgICAgIHJldHVybiBvYmogaW5zdGFuY2VvZiB0eXBlIHx8IG9iaiAhPSBudWxsICYmIG9iai5jb25zdHJ1Y3RvciAhPSBudWxsICYmIG9iai5jb25zdHJ1Y3Rvci5uYW1lICE9IG51bGwgJiYgb2JqLmNvbnN0cnVjdG9yLm5hbWUgPT09IHR5cGUubmFtZTsKICAgICAgfQogICAgICBmdW5jdGlvbiBudW1iZXJJc05hTihvYmopIHsKICAgICAgICByZXR1cm4gb2JqICE9PSBvYmo7CiAgICAgIH0KICAgICAgdmFyIGhleFNsaWNlTG9va3VwVGFibGUgPSBmdW5jdGlvbigpIHsKICAgICAgICBjb25zdCBhbHBoYWJldCA9ICIwMTIzNDU2Nzg5YWJjZGVmIjsKICAgICAgICBjb25zdCB0YWJsZSA9IG5ldyBBcnJheSgyNTYpOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgMTY7ICsraSkgewogICAgICAgICAgY29uc3QgaTE2ID0gaSAqIDE2OwogICAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCAxNjsgKytqKSB7CiAgICAgICAgICAgIHRhYmxlW2kxNiArIGpdID0gYWxwaGFiZXRbaV0gKyBhbHBoYWJldFtqXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRhYmxlOwogICAgICB9KCk7CiAgICAgIGZ1bmN0aW9uIGRlZmluZUJpZ0ludE1ldGhvZChmbikgewogICAgICAgIHJldHVybiB0eXBlb2YgQmlnSW50ID09PSAidW5kZWZpbmVkIiA/IEJ1ZmZlckJpZ0ludE5vdERlZmluZWQgOiBmbjsKICAgICAgfQogICAgICBmdW5jdGlvbiBCdWZmZXJCaWdJbnROb3REZWZpbmVkKCkgewogICAgICAgIHRocm93IG5ldyBFcnJvcigiQmlnSW50IG5vdCBzdXBwb3J0ZWQiKTsKICAgICAgfQogICAgfQogIH0pOwoKICAvLyBzcmMvYWxpYXMvYnVmZmVyLXNoaW0uanMKICB2YXIgaW1wb3J0X2J1ZmZlcjsKICB2YXIgaW5pdF9idWZmZXJfc2hpbSA9IF9fZXNtKHsKICAgICJzcmMvYWxpYXMvYnVmZmVyLXNoaW0uanMiKCkgewogICAgICBpbXBvcnRfYnVmZmVyID0gX190b01vZHVsZShyZXF1aXJlX2J1ZmZlcigpKTsKICAgIH0KICB9KTsKCiAg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wZSwgewogICAgICAgICAgY29uc3RydWN0b3I6IHsKICAgICAgICAgICAgdmFsdWU6IHN1YkNsYXNzLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9CiAgICAgICAgfSk7CiAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHN1YkNsYXNzLCAicHJvdG90eXBlIiwgewogICAgICAgICAgd3JpdGFibGU6IGZhbHNlCiAgICAgICAgfSk7CiAgICAgICAgaWYgKHN1cGVyQ2xhc3MpCiAgICAgICAgICBfc2V0UHJvdG90eXBlT2Yoc3ViQ2xhc3MsIHN1cGVyQ2xhc3MpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9nZXRQcm90b3R5cGVPZihvKSB7CiAgICAgICAgX2dldFByb3RvdHlwZU9mID0gT2JqZWN0LnNldFByb3RvdHlwZU9mID8gT2JqZWN0LmdldFByb3RvdHlwZU9mLmJpbmQoKSA6IGZ1bmN0aW9uIF9nZXRQcm90b3R5cGVPZjIobzIpIHsKICAgICAgICAgIHJldHVybiBvMi5fX3Byb3RvX18gfHwgT2JqZWN0LmdldFByb3RvdHlwZU9mKG8yKTsKICAgICAgICB9OwogICAgICAgIHJldHVybiBfZ2V0UHJvdG90eXBlT2Yobyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX3NldFByb3RvdHlwZU9mKG8sIHApIHsKICAgICAgICBfc2V0UHJvdG90eXBlT2YgPSBPYmplY3Quc2V0UHJvdG90eXBlT2YgPyBPYmplY3Quc2V0UHJvdG90eXBlT2YuYmluZCgpIDogZnVuY3Rpb24gX3NldFByb3RvdHlwZU9mMihvMiwgcDIpIHsKICAgICAgICAgIG8yLl9fcHJvdG9fXyA9IHAyOwogICAgICAgICAgcmV0dXJuIG8yOwogICAgICAgIH07CiAgICAgICAgcmV0dXJuIF9zZXRQcm90b3R5cGVPZihvLCBwKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBfaXNOYXRpdmVSZWZsZWN0Q29uc3RydWN0KCkgewogICAgICAgIGlmICh0eXBlb2YgUmVmbGVjdCA9PT0gInVuZGVmaW5lZCIgfHwgIVJlZmxlY3QuY29uc3RydWN0KQogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIGlmIChSZWZsZWN0LmNvbnN0cnVjdC5zaGFtKQogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIGlmICh0eXBlb2YgUHJveHkgPT09ICJmdW5jdGlvbiIpCiAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICB0cnkgewogICAgICAgICAgQm9vbGVhbi5wcm90b3R5cGUudmFsdWVPZi5jYWxsKFJlZmxlY3QuY29uc3RydWN0KEJvb2xlYW4sIFtdLCBmdW5jdGlvbigpIHsKICAgICAgICAgIH0pKTsKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX2Fzc2VydFRoaXNJbml0aWFsaXplZChzZWxmMikgewogICAgICAgIGlmIChzZWxmMiA9PT0gdm9pZCAwKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmVmZXJlbmNlRXJyb3IoInRoaXMgaGFzbid0IGJlZW4gaW5pdGlhbGlzZWQgLSBzdXBlcigpIGhhc24ndCBiZWVuIGNhbGxlZCIpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gc2VsZjI7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX3Bvc3NpYmxlQ29uc3RydWN0b3JSZXR1cm4oc2VsZjIsIGNhbGwpIHsKICAgICAgICBpZiAoY2FsbCAmJiAodHlwZW9mIGNhbGwgPT09ICJvYmplY3QiIHx8IHR5cGVvZiBjYWxsID09PSAiZnVuY3Rpb24iKSkgewogICAgICAgICAgcmV0dXJuIGNhbGw7CiAgICAgICAgfSBlbHNlIGlmIChjYW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R5KSkgewogICAgICAgICAgb2JqZWN0ID0gX2dldFByb3RvdHlwZU9mKG9iamVjdCk7CiAgICAgICAgICBpZiAob2JqZWN0ID09PSBudWxsKQogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG9iamVjdDsKICAgICAgfQogICAgICBmdW5jdGlvbiBfZ2V0KCkgewogICAgICAgIGlmICh0eXBlb2YgUmVmbGVjdCAhPT0gInVuZGVmaW5lZCIgJiYgUmVmbGVjdC5nZXQpIHsKICAgICAgICAgIF9nZXQgPSBSZWZsZWN0LmdldC5iaW5kKCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIF9nZXQgPSBmdW5jdGlvbiBfZ2V0Mih0YXJnZXQsIHByb3BlcnR5LCByZWNlaXZlcikgewogICAgICAgICAgICB2YXIgYmFzZSA9IF9zdXBlclByb3BCYXNlKHRhcmdldCwgcHJvcGVydHkpOwogICAgICAgICAgICBpZiAoIWJhc2UpCiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB2YXIgZGVzYyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eURlc2NyaXB0b3IoYmFzZSwgcHJvcGVydHkpOwogICAgICAgICAgICBpZiAoZGVzYy5nZXQpIHsKICAgICAgICAgICAgICByZXR1cm4gZGVzYy5nZXQuY2FsbChhcmd1bWVudHMubGVuZ3RoIDwgMyA/IHRhcmdldCA6IHJlY2VpdmVyKTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gZGVzYy52YWx1ZTsKICAgICAgICAgIH07CiAgICAgICAgfQogICAgICAgIHJldHVybiBfZ2V0LmFwcGx5KHRoaXMsIGFyZ3VtZW50cyk7CiAgICAgIH0KICAgICAgdmFyIEVtaXR0ZXIgPSAvKiBAX19QVVJFX18gKi8gZnVuY3Rpb24oKSB7CiAgICAgICAgZnVuY3Rpb24gRW1pdHRlcjIoKSB7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgRW1pdHRlcjIpOwogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJsaXN0ZW5lcnMiLCB7CiAgICAgICAgICAgIHZhbHVlOiB7fSwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhFbWl0dGVyMiwgW3sKICAgICAgICAgIGtleTogImFkZEV2ZW50TGlzdGVuZXIiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGFkZEV2ZW50TGlzdGVuZXIodHlwZSwgY2FsbGJhY2ssIG9wdGlvbnMpIHsKICAgICAgICAgICAgaWYgKCEodHlwZSBpbiB0aGlzLmxpc3RlbmVycykpIHsKICAgICAgICAgICAgICB0aGlzLmxpc3RlbmVyc1t0eXBlXSA9IFtdOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMubGlzdGVuZXJzW3R5cGVdLnB1c2goewogICAgICAgICAgICAgIGNhbGxiYWNrLAogICAgICAgICAgICAgIG9wdGlvbnMKICAgICAgICAgICAgfSk7CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAicmVtb3ZlRXZlbnRMaXN0ZW5lciIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gcmVtb3ZlRXZlbnRMaXN0ZW5lcih0eXBlLCBjYWxsYmFjaykgewogICAgICAgICAgICBpZiAoISh0eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICB2YXIgc3RhY2sgPSB0aGlzLmxpc3RlbmVyc1t0eXBlXTsKICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGwgPSBzdGFjay5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgICBpZiAoc3RhY2tbaV0uY2FsbGJhY2sgPT09IGNhbGxiYWNrKSB7CiAgICAgICAgICAgICAgICBzdGFjay5zcGxpY2UoaSwgMSk7CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAiZGlzcGF0Y2hFdmVudCIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gZGlzcGF0Y2hFdmVudChldmVudCkgewogICAgICAgICAgICBpZiAoIShldmVudC50eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICB2YXIgc3RhY2sgPSB0aGlzLmxpc3RlbmVyc1tldmVudC50eXBlXTsKICAgICAgICAgICAgdmFyIHN0YWNrVG9DYWxsID0gc3RhY2suc2xpY2UoKTsKICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGwgPSBzdGFja1RvQ2FsbC5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgICB2YXIgbGlzdGVuZXIgPSBzdGFja1RvQ2FsbFtpXTsKICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgbGlzdGVuZXIuY2FsbGJhY2suY2FsbCh0aGlzLCBldmVudCk7CiAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgUHJvbWlzZS5yZXNvbHZlKCkudGhlbihmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgICAgdGhyb3cgZTsKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAobGlzdGVuZXIub3B0aW9ucyAmJiBsaXN0ZW5lci5vcHRpb25zLm9uY2UpIHsKICAgICAgICAgICAgICAgIHRoaXMucmVtb3ZlRXZlbnRMaXN0ZW5lcihldmVudC50eXBlLCBsaXN0ZW5lci5jYWxsYmFjayk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiAhZXZlbnQuZGVmYXVsdFByZXZlbnRlZDsKICAgICAgICAgIH0KICAgICAgICB9XSk7CiAgICAgICAgcmV0dXJuIEVtaXR0ZXIyOwogICAgICB9KCk7CiAgICAgIHZhciBBYm9ydFNpZ25hbCA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbihfRW1pdHRlcikgewogICAgICAgIF9pbmhlcml0cyhBYm9ydFNpZ25hbDIsIF9FbWl0dGVyKTsKICAgICAgICB2YXIgX3N1cGVyID0gX2NyZWF0ZVN1cGVyKEFib3J0U2lnbmFsMik7CiAgICAgICAgZnVuY3Rpb24gQWJvcnRTaWduYWwyKCkgewogICAgICAgICAgdmFyIF90aGlzOwogICAgICAgICAgX2NsYXNzQ2FsbENoZWNrKHRoaXMsIEFib3J0U2lnbmFsMik7CiAgICAgICAgICBfdGhpcyA9IF9zdXBlci5jYWxsKHRoaXMpOwogICAgICAgICAgaWYgKCFfdGhpcy5saXN0ZW5lcnMpIHsKICAgICAgICAgICAgRW1pdHRlci5jYWxsKF9hc3NlcnRUaGlzSW5pdGlhbGl6ZWQoX3RoaXMpKTsKICAgICAgICAgIH0KICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgImFib3J0ZWQiLCB7CiAgICAgICAgICAgIHZhbHVlOiBmYWxzZSwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcyksICJvbmFib3J0IiwgewogICAgICAgICAgICB2YWx1ZTogbnVsbCwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcyksICJyZWFzb24iLCB7CiAgICAgICAgICAgIHZhbHVlOiB2b2lkIDAsCiAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlLAogICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUKICAgICAgICAgIH0pOwogICAgICAgICAgcmV0dXJuIF90aGlzOwogICAgICAgIH0KICAgICAgICBfY3JlYXRlQ2xhc3MoQWJvcnRTaWduYWwyLCBbewogICAgICAgICAga2V5OiAidG9TdHJpbmciLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gIltvYmplY3QgQWJvcnRTaWduYWxdIjsKICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJkaXNwYXRjaEV2ZW50IiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiBkaXNwYXRjaEV2ZW50KGV2ZW50KSB7CiAgICAgICAgICAgIGlmIChldmVudC50eXBlID09PSAiYWJvcnQiKSB7CiAgICAgICAgICAgICAgdGhpcy5hYm9ydGVkID0gdHJ1ZTsKICAgICAgICAgICAgICBpZiAodHlwZW9mIHRoaXMub25hYm9ydCA9PT0gImZ1bmN0aW9uIikgewogICAgICAgICAgICAgICAgdGhpcy5vbmFib3J0LmNhbGwodGhpcywgZXZlbnQpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBfZ2V0KF9nZXRQcm90b3R5cGVPZihBYm9ydFNpZ25hbDIucHJvdG90eXBlKSwgImRpc3BhdGNoRXZlbnQiLCB0aGlzKS5jYWxsKHRoaXMsIGV2ZW50KTsKICAgICAgICAgIH0KICAgICAgICB9XSk7CiAgICAgICAgcmV0dXJuIEFib3J0U2lnbmFsMjsKICAgICAgfShFbWl0dGVyKTsKICAgICAgdmFyIEFib3J0Q29udHJvbGxlciA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbigpIHsKICAgICAgICBmdW5jdGlvbiBBYm9ydENvbnRyb2xsZXIyKCkgewogICAgICAgICAgX2NsYXNzQ2FsbENoZWNrKHRoaXMsIEFib3J0Q29udHJvbGxlcjIpOwogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJzaWduYWwiLCB7CiAgICAgICAgICAgIHZhbHVlOiBuZXcgQWJvcnRTaWduYWwoKSwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhBYm9ydENvbnRyb2xsZXIyLCBbewogICAgICAgICAga2V5OiAiYWJvcnQiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGFib3J0KHJlYXNvbikgewogICAgICAgICAgICB2YXIgZXZlbnQ7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgZXZlbnQgPSBuZXcgRXZlbnQoImFib3J0Iik7CiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICBpZiAodHlwZW9mIGRvY3VtZW50ICE9PSAidW5kZWZpbmVkIikgewogICAgICAgICAgICAgICAgaWYgKCFkb2N1bWVudC5jcmVhdGVFdmVudCkgewogICAgICAgICAgICAgICAgICBldmVudCA9IGRvY3VtZW50LmNyZWF0ZUV2ZW50T2JqZWN0KCk7CiAgICAgICAgICAgICAgICAgIGV2ZW50LnR5cGUgPSAiYWJvcnQiOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgZXZlbnQgPSBkb2N1bWVudC5jcmVhdGVFdmVudCgiRXZlbnQiKTsKICAgICAgICAgICAgICAgICAgZXZlbnQuaW5pdEV2ZW50KCJhYm9ydCIsIGZhbHNlLCBmYWxzZSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGV2ZW50ID0gewogICAgICAgICAgICAgICAgICB0eXBlOiAiYWJvcnQiLAogICAgICAgICAgICAgICAgICBidWJibGVzOiBmYWxzZSwKICAgICAgICAgICAgICAgICAgY2FuY2VsYWJsZTogZmFsc2UKICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzaWduYWxSZWFzb24gPSByZWFzb247CiAgICAgICAgICAgIGlmIChzaWduYWxSZWFzb24gPT09IHZvaWQgMCkgewogICAgICAgICAgICAgIGlmICh0eXBlb2YgZG9jdW1lbnQgPT09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRXJyb3IoIlRoaXMgb3BlcmF0aW9uIHdhcyBhYm9ydGVkIik7CiAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24ubmFtZSA9ICJBYm9ydEVycm9yIjsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgc2lnbmFsUmVhc29uID0gbmV3IERPTUV4Y2VwdGlvbigic2lnbmFsIGlzIGFib3J0ZWQgd2l0aG91dCByZWFzb24iKTsKICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGVycikgewogICAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRXJyb3IoIlRoaXMgb3BlcmF0aW9uIHdhcyBhYm9ydGVkIik7CiAgICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbi5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLnNpZ25hbC5yZWFzb24gPSBzaWduYWxSZWFzb247CiAgICAgICAgICAgIHRoaXMuc2lnbmFsLmRpc3BhdGNoRXZlbnQoZXZlbnQpOwogICAgICAgICAgf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2gsCiAgICAgICAgICAgIFJlcXVlc3QKICAgICAgICAgIH07CiAgICAgICAgfQogICAgICAgIHZhciBSZXF1ZXN0ID0gTmF0aXZlUmVxdWVzdDsKICAgICAgICBpZiAoUmVxdWVzdCAmJiAhUmVxdWVzdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHkoInNpZ25hbCIpIHx8IF9fRk9SQ0VfSU5TVEFMTF9BQk9SVENPTlRST0xMRVJfUE9MWUZJTEwpIHsKICAgICAgICAgIFJlcXVlc3QgPSBmdW5jdGlvbiBSZXF1ZXN0MihpbnB1dCwgaW5pdDIpIHsKICAgICAgICAgICAgdmFyIHNpZ25hbDsKICAgICAgICAgICAgaWYgKGluaXQyICYmIGluaXQyLnNpZ25hbCkgewogICAgICAgICAgICAgIHNpZ25hbCA9IGluaXQyLnNpZ25hbDsKICAgICAgICAgICAgICBkZWxldGUgaW5pdDIuc2lnbmFsOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciByZXF1ZXN0ID0gbmV3IE5hdGl2ZVJlcXVlc3QoaW5wdXQsIGluaXQyKTsKICAgICAgICAgICAgaWYgKHNpZ25hbCkgewogICAgICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShyZXF1ZXN0LCAic2lnbmFsIiwgewogICAgICAgICAgICAgICAgd3JpdGFibGU6IGZhbHNlLAogICAgICAgICAgICAgICAgZW51bWVyYWJsZTogZmFsc2UsCiAgICAgICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUsCiAgICAgICAgICAgICAgICB2YWx1ZTogc2lnbmFsCiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIHJlcXVlc3Q7CiAgICAgICAgICB9OwogICAgICAgICAgUmVxdWVzdC5wcm90b3R5cGUgPSBOYXRpdmVSZXF1ZXN0LnByb3RvdHlwZTsKICAgICAgICB9CiAgICAgICAgdmFyIHJlYWxGZXRjaCA9IGZldGNoOwogICAgICAgIHZhciBhYm9ydGFibGVGZXRjaCA9IGZ1bmN0aW9uIGFib3J0YWJsZUZldGNoMihpbnB1dCwgaW5pdDIpIHsKICAgICAgICAgIHZhciBzaWduYWwgPSBSZXF1ZXN0ICYmIFJlcXVlc3QucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoaW5wdXQpID8gaW5wdXQuc2lnbmFsIDogaW5pdDIgPyBpbml0Mi5zaWduYWwgOiB2b2lkIDA7CiAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgIHZhciBhYm9ydEVycm9yOwogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIGFib3J0RXJyb3IgPSBuZXcgRE9NRXhjZXB0aW9uKCJBYm9ydGVkIiwgIkFib3J0RXJyb3IiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgYWJvcnRFcnJvciA9IG5ldyBFcnJvcigiQWJvcnRlZCIpOwogICAgICAgICAgICAgIGFib3J0RXJyb3IubmFtZSA9ICJBYm9ydEVycm9yIjsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZWplY3QoYWJvcnRFcnJvcik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIGNhbmNlbGxhdGlvbiA9IG5ldyBQcm9taXNlKGZ1bmN0aW9uKF8sIHJlamVjdCkgewogICAgICAgICAgICAgIHNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsIGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmV0dXJuIHJlamVjdChhYm9ydEVycm9yKTsKICAgICAgICAgICAgICB9LCB7CiAgICAgICAgICAgICAgICBvbmNlOiB0cnVlCiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICBpZiAoaW5pdDIgJiYgaW5pdDIuc2lnbmFsKSB7CiAgICAgICAgICAgICAgZGVsZX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gICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJjYW5ub3QgYWRkIGEgc2lnbmFsLCBhbHJlYWR5IGFib3J0ZWQhIik7CiAgICAgICAgICB9CiAgICAgICAgICB0aGlzLnNpZ25hbHMuYWRkKHNpZ25hbCk7CiAgICAgICAgICBpZiAoc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgdGhpcy5oYW5kbGVBYm9ydGVkKHNpZ25hbCk7CiAgICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBzaWduYWwuYWRkRXZlbnRMaXN0ZW5lciA9PT0gImZ1bmN0aW9uIikgewogICAgICAgICAgICBzaWduYWwuYWRkRXZlbnRMaXN0ZW5lcigiYWJvcnQiLCAoKSA9PiB7CiAgICAgICAgICAgICAgdGhpcy5oYW5kbGVBYm9ydGVkKHNpZ25hbCk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBoYW5kbGVBYm9ydGVkKHNpZ25hbCkgewogICAgICAgICAgdGhpcy5zaWduYWxzLmRlbGV0ZShzaWduYWwpOwogICAgICAgICAgaWYgKHRoaXMuc2lnbmFscy5zaXplID09PSAwKSB7CiAgICAgICAgICAgIHRoaXMuYWJvcnRDb250cm9sbGVyLmFib3J0KCk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGdldCBzaWduYWwoKSB7CiAgICAgICAgICByZXR1cm4gdGhpcy5hYm9ydENvbnRyb2xsZXIuc2lnbmFsOwogICAgICAgIH0KICAgICAgICBhYm9ydCgpIHsKICAgICAgICAgIHRoaXMuYWJvcnRDb250cm9sbGVyLmFib3J0KCk7CiAgICAgICAgfQogICAgICB9OwogICAgICBleHBvcnRzMi5kZWZhdWx0ID0gQWdncmVnYXRlQWJvcnRDb250cm9sbGVyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vYWJvcnRhYmxlLXByb21pc2UtY2FjaGVAMS41LjAvbm9kZV9tb2R1bGVzL2F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b3I6IGFib3J0ZWQiIHx8IGV4Y2VwdGlvbi5tZXNzYWdlID09PSAiRXJyb3I6IGFib3J0ZWQiOwogICAgICAgIH0KICAgICAgICBldmljdChrZXksIGVudHJ5KSB7CiAgICAgICAgICBpZiAodGhpcy5jYWNoZS5nZXQoa2V5KSA9PT0gZW50cnkpIHsKICAgICAgICAgICAgdGhpcy5jYWNoZS5kZWxldGUoa2V5KTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZmlsbChrZXksIGRhdGEsIHNpZ25hbCwgc3RhdHVzQ2FsbGJhY2spIHsKICAgICAgICAgIGNvbnN0IGFib3J0ZXIgPSBuZXcgQWdncmVnYXRlQWJvcnRDb250cm9sbGVyXzEuZGVmYXVsdCgpOwogICAgICAgICAgY29uc3Qgc3RhdHVzUmVwb3J0ZXIgPSBuZXcgQWdncmVnYXRlU3RhdHVzUmVwb3J0ZXJfMS5kZWZhdWx0KCk7CiAgICAgICAgICBzdGF0dXNSZXBvcnRlci5hZGRDYWxsYmFjayhzdGF0dXNDYWxsYmFjayk7CiAgICAgICAgICBjb25zdCBuZXdFbnRyeSA9IHsKICAgICAgICAgICAgYWJvcnRlciwKICAgICAgICAgICAgcHJvbWlzZTogdGhpcy5maWxsQ2FsbGJhY2soZGF0YSwgYWJvcnRlci5zaWduYWwsIChtZXNzYWdlKSA9PiB7CiAgICAgICAgICAgICAgc3RhdHVzUmVwb3J0ZXIuY2FsbGJhY2sobWVzc2FnZSk7CiAgICAgICAgICAgIH0pLAogICAgICAgICAgICBzZXR0bGVkOiBmYWxzZSwKICAgICAgICAgICAgc3RhdHVzUmVwb3J0ZXIsCiAgICAgICAgICAgIGdldCBhYm9ydGVkKCkgewogICAgICAgICAgICAgIHJldHVybiB0aGlzLmFib3J0ZXIuc2lnbmFsLmFib3J0ZWQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH07CiAgICAgICAgICBuZXdFbnRyeS5hYm9ydGVyLmFkZFNpZ25hbChzaWduYWwpOwogICAgICAgICAgbmV3RW50cnkuYWJvcnRlci5zaWduYWwuYWRkRXZlbnRMaXN0ZW5lcigiYWJvcnQiLCAoKSA9PiB7CiAgICAgICAgICAgIGlmICghbmV3RW50cnkuc2V0dGxlZCkgewogICAgICAgICAgICAgIHRoaXMuZXZpY3Qoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0pOwogICAgICAgICAgbmV3RW50cnkucHJvbWlzZS50aGVuKCgpID0+IHsKICAgICAgICAgICAgbmV3RW50cnkuc2V0dGxlZCA9IHRydWU7CiAgICAgICAgICB9LCAoKSA9PiB7CiAgICAgICAgICAgIG5ld0VudHJ5LnNldHRsZWQgPSB0cnVlOwogICAgICAgICAgICB0aGlzLmV2aWN0KGtleSwgbmV3RW50cnkpOwogICAgICAgICAgfSkuY2F0Y2goKGUpID0+IHsKICAgICAgICAgICAgY29uc29sZS5lcnJvcihlKTsKICAgICAgICAgICAgdGhyb3cgZTsKICAgICAgICAgIH0pOwogICAgICAgICAgdGhpcy5jYWNoZS5zZXQoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgfQogICAgICAgIHN0YXRpYyBjaGVja1NpbmdsZVByb21pc2UocHJvbWlzZSwgc2lnbmFsKSB7CiAgICAgICAgICBmdW5jdGlvbiBjaGVja0ZvclNpbmdsZUFib3J0KCkgewogICAgICAgICAgICBpZiAoc2lnbmFsICYmIHNpZ25hbC5hYm9ydGVkKSB7CiAgICAgICAgICAgICAgdGhyb3cgT2JqZWN0LmFzc2lnbihuZXcgRXJyb3IoImFib3J0ZWQiKSwgeyBjb2RlOiAiRVJSX0FCT1JURUQiIH0pOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gcHJvbWlzZS50aGVuKChyZXN1bHQpID0+IHsKICAgICAgICAgICAgY2hlY2tGb3JTaW5nbGVBYm9ydCgpOwogICAgICAgICAgICByZXR1cm4gcmVzdWx0OwogICAgICAgICAgfSwgKGVycm9yKSA9PiB7CiAgICAgICAgICAgIGNoZWNrRm9yU2luZ2xlQWJvcnQoKTsKICAgICAgICAgICAgdGhyb3cgZXJyb3I7CiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgaGFzKGtleSkgewogICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuaGFzKGtleSk7CiAgICAgICAgfQogICAgICAgIGdldChrZXksIGRhdGEsIHNpZ25hbCwgc3RhdHVzQ2FsbGJhY2spIHsKICAgICAgICAgIGlmICghc2lnbmFsICYmIGRhdGEgaW5zdGFuY2VvZiBhYm9ydGNvbnRyb2xsZXJfcG9ueWZpbGxfMS5BYm9ydFNpZ25hbCkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJzZWNvbmQgZ2V0IGFyZ3VtZW50IGFwcGVhcnMgdG8gYmUgYW4gQWJvcnRTaWduYWwsIHBlcmhhcHMgeW91IG1lYW50IHRvIHBhc3MgYG51bGxgIGZvciB0aGUgZmlsbCBkYXRhPyIpOwogICAgICAgICAgfQogICAgICAgICAgY29uc3QgY2FjaGVFbnRyeSA9IHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICBpZiAoY2FjaGVFbnRyeSkgewogICAgICAgICAgICBpZiAoY2FjaGVFbnRyeS5hYm9ydGVkICYmICFjYWNoZUVudHJ5LnNldHRsZWQpIHsKICAgICAgICAgICAgICB0aGlzLmV2aWN0KGtleSwgY2FjaGVFbnRyeSk7CiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuZ2V0KGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjayk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGNhY2hlRW50cnkuc2V0dGxlZCkgewogICAgICAgICAgICAgIHJldHVybiBjYWNoZUVudHJ5LnByb21pc2U7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY2FjaGVFbnRyeS5hYm9ydGVyLmFkZFNpZ25hbChzaWduYWwpOwogICAgICAgICAgICBjYWNoZUVudHJ5LnN0YXR1c1JlcG9ydGVyLmFkZENhbGxiYWNrKHN0YXR1c0NhbGxiYWNrKTsKICAgICAgICAgICAgcmV0dXJuIEFib3J0YWJsZVByb21pc2VDYWNoZTIuY2hlY2tTaW5nbGVQcm9taXNlKGNhY2hlRW50cnkucHJvbWlzZSwgc2lnbmFsKTsKICAgICAgICAgIH0KICAgICAgICAgIHRoaXMuZmlsbChrZXksIGRhdGEsIHNpZ25hbCwgc3RhdHVzQ2FsbGJhY2spOwogICAgICAgICAgcmV0dXJuIEFib3J0YWJsZVByb21pc2VDYWNoZTIuY2hlY2tTaW5nbGVQcm9taXNlKHRoaXMuY2FjaGUuZ2V0KGtleSkucHJvbWlzZSwgc2lnbmFsKTsKICAgICAgICB9CiAgICAgICAgZGVsZXRlKGtleSkgewogICAgICAgICAgY29uc3QgY2FjaGVkRW50cnkgPSB0aGlzLmNhY2hlLmdldChrZXkpOwogICAgICAgICAgaWYgKGNhY2hlZEVudHJ5KSB7CiAgICAgICAgICAgIGlmICghY2FjaGVkRW50cnkuc2V0dGxlZCkgewogICAgICAgICAgICAgIGNhY2hlZEVudHJ5LmFib3J0ZXIuYWJvcnQoKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLmNhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjbGVhcigpIHsKICAgICAgICAgIGNvbnN0IGtleUl0ZXIgPSB0aGlzLmNhY2hlLmtleXMoKTsKICAgICAgICAgIGxldCBkZWxldGVDb3VudCA9IDA7CiAgICAgICAgICBmb3IgKGxldCByZXN1bHQgPSBrZXlJdGVyLm5leHQoKTsgIXJlc3VsdC5kb25lOyByZXN1bHQgPSBrZXlJdGVyLm5leHQoKSkgewogICAgICAgICAgICB0aGlzLmRlbGV0ZShyZXN1bHQudmFsdWUpOwogICAgICAgICAgICBkZWxldGVDb3VudCArPSAxOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGRlbGV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kdWxlcy9xdWljay1scnUvaW5kZXguanMKICB2YXIgcmVxdWlyZV9xdWlja19scnUgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcXVpY2stbHJ1QDQuMC4xL25vZGVfbW9kdWxlcy9xdWljay1scnUvaW5kZXguanMiKGV4cG9ydHMyLCBtb2R1bGUyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgUXVpY2tMUlUgPSBjbGFzcyB7CiAgICAgICAgY29uc3RydWN0b3Iob3B0aW9ucyA9IHt9KSB7CiAgICAgICAgICBpZiAoIShvcHRpb25zLm1heFNpemUgJiYgb3B0aW9ucy5tYXhTaXplID4gMCkpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiYG1heFNpemVgIG11c3QgYmUgYSBudW1iZXIgZ3JlYXRlciB0aGFuIDAiKTsKICAgICAgICAgIH0KICAgICAgICAgIHRoaXMubWF4U2l6ZSA9IG9wdGlvbnMubWF4U2l6ZTsKICAgICAgICAgIHRoaXMuY2FjaGUgPSBuZXcgTWFwKCk7CiAgICAgICAgICB0aGlzLm9sZENhY2hlID0gbmV3IE1hcCgpOwogICAgICAgICAgdGhpcy5fc2l6ZSA9IDA7CiAgICAgICAgfQogICAgICAgIF9zZXQoa2V5LCB2YWx1ZSkgewogICAgICAgICAgdGhpcy5jYWNoZS5zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICB0aGlzLl9zaXplKys7CiAgICAgICAgICBpZiAodGhpcy5fc2l6ZSA+PSB0aGlzLm1heFNpemUpIHsKICAgICAgICAgICAgdGhpcy5fc2l6ZSA9IDA7CiAgICAgICAgICAgIHRoaXMub2xkQ2FjaGUgPSB0aGlzLmNhY2hlOwogICAgICAgICAgICB0aGlzLmNhY2hlID0gbmV3IE1hcCgpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBnZXQoa2V5KSB7CiAgICAgICAgICBpZiAodGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5nZXQoa2V5KTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0aGlzLm9sZENhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIGNvbnN0IHZhbHVlID0gdGhpcy5vbGRDYWNoZS5nZXQoa2V5KTsKICAgICAgICAgICAgdGhpcy5vbGRDYWNoZS5kZWxldGUoa2V5KTsKICAgICAgICAgICAgdGhpcy5fc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgICByZXR1cm4gdmFsdWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHNldChrZXksIHZhbHVlKSB7CiAgICAgICAgICBpZiAodGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIHZhbHVlKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRoaXMuX3NldChrZXksIHZhbHVlKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIH0KICAgICAgICBoYXMoa2V5KSB7CiAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5oYXMoa2V5KSB8fCB0aGlzLm9sZENhY2hlLmhhcyhrZXkpOwogICAgICAgIH0KICAgICAgICBwZWVrKGtleSkgewogICAgICAgICAgaWYgKHRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodGhpcy5vbGRDYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5vbGRDYWNoZS5nZXQoa2V5KTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZGVsZXRlKGtleSkgewogICAgICAgICAgY29uc3QgZGVsZXRlZCA9IHRoaXMuY2FjaGUuZGVsZXRlKGtleSk7CiAgICAgICAgICBpZiAoZGVsZXRlZCkgewogICAgICAgICAgICB0aGlzLl9zaXplLS07CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gdGhpcy5vbGRDYWNoZS5kZWxldGUoa2V5KSB8fCBkZWxldGVkOwogICAgICAgIH0KICAgICAgICBjbGVhcigpIHsKICAgICAgICAgIHRoaXMuY2FjaGUuY2xlYXIoKTsKICAgICAgICAgIHRoaXMub2xkQ2FjaGUuY2xlYXIoKTsKICAgICAgICAgIHRoaXMuX3NpemUgPSAwOwogICAgICAgIH0KICAgICAgICAqa2V5cygpIHsKICAgICAgICAgIGZvciAoY29uc3QgW2tleV0gb2YgdGhpcykgewogICAgICAgICAgICB5aWVsZCBrZXk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgICp2YWx1ZXMoKSB7CiAgICAgICAgICBmb3IgKGNvbnN0IFssIHZhbHVlXSBvZiB0aGlzKSB7CiAgICAgICAgICAgIHlpZWxkIHZhbHVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAqW1N5bWJvbC5pdGVyYXRvcl0oKSB7CiAgICAgICAgICBmb3IgKGNvbnN0IGl0ZW0gb2YgdGhpcy5jYWNoZSkgewogICAgICAgICAgICB5aWVsZCBpdGVtOwogICAgICAgICAgfQogICAgICAgICAgZm9yIChjb25zdCBpdGVtIG9mIHRoaXMub2xkQ2FjaGUpIHsKICAgICAgICAgICAgY29uc3QgW2tleV0gPSBpdGVtOwogICAgICAgICAgICBpZiAoIXRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgICB5aWVsZCBpdGVtOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGdldCBzaXplKCkgewogICAgICAgICAgbGV0IG9sZENhY2hlU2l6ZSA9IDA7CiAgICAgICAgICBmb3IgKGNvbnN0IGtleSBvZiB0aGlzLm9sZENhY2hlLmtleXMoKSkgewogICAgICAgICAgICBpZiAoIXRoaXMuY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hPT0gInVuZGVmaW5lZCI7CiAgICAgIGZ1bmN0aW9uIF9oYXMob2JqLCBrZXkpIHsKICAgICAgICByZXR1cm4gT2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eS5jYWxsKG9iaiwga2V5KTsKICAgICAgfQogICAgICBleHBvcnRzMi5hc3NpZ24gPSBmdW5jdGlvbihvYmopIHsKICAgICAgICB2YXIgc291cmNlcyA9IEFycmF5LnByb3RvdHlwZS5zbGljZS5jYWxsKGFyZ3VtZW50cywgMSk7CiAgICAgICAgd2hpbGUgKHNvdXJjZXMubGVuZ3RoKSB7CiAgICAgICAgICB2YXIgc291cmNlID0gc291cmNlcy5zaGlmdCgpOwogICAgICAgICAgaWYgKCFzb3VyY2UpIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodHlwZW9mIHNvdXJjZSAhPT0gIm9iamVjdCIpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcihzb3VyY2UgKyAibXVzdCBiZSBub24tb2JqZWN0Iik7CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKHZhciBwIGluIHNvdXJjZSkgewogICAgICAgICAgICBpZiAoX2hhcyhzb3VyY2UsIHApKSB7CiAgICAgICAgICAgICAgb2JqW3BdID0gc291cmNlW3BdOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBvYmo7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLnNocmlua0J1ZiA9IGZ1bmN0aW9uKGJ1Ziwgc2l6ZSkgewogICAgICAgIGlmIChidWYubGVuZ3RoID09PSBzaXplKSB7CiAgICAgICAgICByZXR1cm4gYnVmOwogICAgICAgIH0KICAgICAgICBpZiAoYnVmLnN1YmFycmF5KSB7CiAgICAgICAgICByZXR1cm4gYnVmLnN1YmFycmF5KDAsIHNpemUpOwogICAgICAgIH0KICAgICAgICBidWYubGVuZ3RoID0gc2l6ZTsKICAgICAgICByZXR1cm4gYnVmOwogICAgICB9OwogICAgICB2YXIgZm5UeXBlZCA9IHsKICAgICAgICBhcnJheVNldDogZnVuY3Rpb24oZGVzdCwgc3JjLCBzcmNfb2ZmcywgbGVuLCBkZXN0X29mZnMpIHsKICAgICAgICAgIGlmIChzcmMuc3ViYXJyYXkgJiYgZGVzdC5zdWJhcnJheSkgewogICAgICAgICAgICBkZXN0LnNldChzcmMuc3ViYXJyYXkoc3JjX29mZnMsIHNyY19vZmZzICsgbGVuKSwgZGVzdF9vZmZzKTsKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgfQogICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgICBkZXN0W2Rlc3Rfb2ZmcyArIGldID0gc3JjW3NyY19vZmZzICsgaV07CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBmbGF0dGVuQ2h1bmtzOiBmdW5jdGlvbihjaHVua3MpIHsKICAgICAgICAgIHZhciBpLCBsLCBsZW4sIHBvcywgY2h1bmssIHJlc3VsdDsKICAgICAgICAgIGxlbiA9IDA7CiAgICAgICAgICBmb3IgKGkgPSAwLCBsID0gY2h1bmtzLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICBsZW4gKz0gY2h1bmtzW2ldLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICAgIHJlc3VsdCA9IG5ldyBVaW50OEFycmF5KGxlbik7CiAgICAgICAgICBwb3MgPSAwOwogICAgICAgICAgZm9yIChpID0gMCwgbCA9IGNodW5rcy5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgY2h1bmsgPSBjaHVua3NbaV07CiAgICAgICAgICAgIHJlc3VsdC5zZXQoY2h1bmssIHBvcyk7CiAgICAgICAgICAgIHBvcyArPSBjaHVuay5sZW5ndGg7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gcmVzdWx0OwogICAgICAgIH0KICAgICAgfTsKICAgICAgdmFyIGZuVW50eXBlZCA9IHsKICAgICAgICBhcnJheVNldDogZnVuY3Rpb24oZGVzdCwgc3JjLCBzcmNfb2ZmcywgbGVuLCBkZXN0X29mZnMpIHsKICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICAgICAgZGVzdFtkZXN0X29mZnMgKyBpXSA9IHNyY1tzcmNfb2ZmcyArIGldOwogICAgICAgICAgfQogICAgICAgIH0sCiAgICAgICAgZmxhdHRlbkNodW5rczogZnVuY3Rpb24oY2h1bmtzKSB7CiAgICAgICAgICByZXR1cm4gW10uY29uY2F0LmFwcGx5KFtdLCBjaHVua3MpOwogICAgICAgIH0KICAgICAgfTsKICAgICAgZXhwb3J0czIuc2V0VHlwZWQgPSBmdW5jdGlvbihvbikgewogICAgICAgIGlmIChvbikgewogICAgICAgICAgZXhwb3J0czIuQnVmOCA9IFVpbnQ4QXJyYXk7CiAgICAgICAgICBleHBvcnRzMi5CdWYxNiA9IFVpbnQxNkFycmF5OwogICAgICAgICAgZXhwb3J0czIuQnVmMzIgPSBJbnQzMkFycmF5OwogICAgICAgICAgZXhwb3J0czIuYXNzaWduKGV4cG9ydHMyLCBmblR5cGVkKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZXhwb3J0czIuQnVmOCA9IEFycmF5OwogICAgICAgICAgZXhwb3J0czIuQnVmMTYgPSBBcnJheTsKICAgICAgICAgIGV4cG9ydHMyLkJ1ZjMyID0gQXJyYXk7CiAgICAgICAgICBleHBvcnRzMi5hc3NpZ24oZXhwb3J0czIsIGZuVW50eXBlZCk7CiAgICAgICAgfQogICAgICB9OwogICAgICBleHBvcnRzMi5zZXRUeXBlZChUWVBFRF9PSyk7CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi90cmVlcy5qcwogIHZhciByZXF1aXJlX3RyZWVzID0gX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AgIHMuYmxfY291bnRbYml0c10gPSAwOwogICAgICAgIH0KICAgICAgICB0cmVlW3MuaGVhcFtzLmhlYXBfbWF4XSAqIDIgKyAxXSA9IDA7CiAgICAgICAgZm9yIChoID0gcy5oZWFwX21heCArIDE7IGggPCBIRUFQX1NJWkU7IGgrKykgewogICAgICAgICAgbiA9IHMuaGVhcFtoXTsKICAgICAgICAgIGJpdHMgPSB0cmVlW3RyZWVbbiAqIDIgKyAxXSAqIDIgKyAxXSArIDE7CiAgICAgICAgICBpZiAoYml0cyA+IG1heF9sZW5ndGgpIHsKICAgICAgICAgICAgYml0cyA9IG1heF9sZW5ndGg7CiAgICAgICAgICAgIG92ZXJmbG93Kys7CiAgICAgICAgICB9CiAgICAgICAgICB0cmVlW24gKiAyICsgMV0gPSBiaXRzOwogICAgICAgICAgaWYgKG4gPiBtYXhfY29kZSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIHMuYmxfY291bnRbYml0c10rKzsKICAgICAgICAgIHhiaXRzID0gMDsKICAgICAgICAgIGlmIChuID49IGJhc2UpIHsKICAgICAgICAgICAgeGJpdHMgPSBleHRyYVtuIC0gYmFzZV07CiAgICAgICAgICB9CiAgICAgICAgICBmID0gdHJlZVtuICogMl07CiAgICAgICAgICBzLm9wdF9sZW4gKz0gZiAqIChiaXRzICsgeGJpdHMpOwogICAgICAgICAgaWYgKGhhc19zdHJlZSkgewogICAgICAgICAgICBzLnN0YXRpY19sZW4gKz0gZiAqIChzdHJlZVtuICogMiArIDFdICsgeGJpdHMpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAob3ZlcmZsb3cgPT09IDApIHsKICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgZG8gewogICAgICAgICAgYml0cyA9IG1heF9sZW5ndGggLSAxOwogICAgICAgICAgd2hpbGUgKHMuYmxfY291bnRbYml0c10gPT09IDApIHsKICAgICAgICAgICAgYml0cy0tOwogICAgICAgICAgfQogICAgICAgICAgcy5ibF9jb3VudFtiaXRzXS0tOwogICAgICAgICAgcy5ibF9jb3VudFtiaXRzICsgMV0gKz0gMjsKICAgICAgICAgIHMuYmxfY291bnRbbWF4X2xlbmd0aF0tLTsKICAgICAgICAgIG92ZXJmbG93IC09IDI7CiAgICAgICAgfSB3aGlsZSAob3ZlcmZsb3cgPiAwKTsKICAgICAgICBmb3IgKGJpdHMgPSBtYXhfbGVuZ3RoOyBiaXRzICE9PSAwOyBiaXRzLS0pIHsKICAgICAgICAgIG4gPSBzLmJsX2NvdW50W2JpdHNdOwogICAgICAgICAgd2hpbGUgKG4gIT09IDApIHsKICAgICAgICAgICAgbSA9IHMuaGVhcFstLWhdOwogICAgICAgICAgICBpZiAobSA+IG1heF9jb2RlKSB7CiAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHRyZWVbbSAqIDIgKyAxXSAhPT0gYml0cykgewogICAgICAgICAgICAgIHMub3B0X2xlbiArPSAoYml0cyAtIHRyZWVbbSAqIDIgKyAxXSkgKiB0cmVlW20gKiAyXTsKICAgICAgICAgICAgICB0cmVlW20gKiAyICsgMV0gPSBiaXRzOwogICAgICAgICAgICB9CiAgICAgICAgICAgIG4tLTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZ2VuX2NvZGVzKHRyZWUsIG1heF9jb2RlLCBibF9jb3VudCkgewogICAgICAgIHZhciBuZXh0X2NvZGUgPSBuZXcgQXJyYXkoTUFYX0JJVFMgKyAxKTsKICAgICAgICB2YXIgY29kZSA9IDA7CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIG47CiAgICAgICAgZm9yIChiaXRzID0gMTsgYml0cyA8PSBNQVhfQklUUzsgYml0cysrKSB7CiAgICAgICAgICBuZXh0X2NvZGVbYml0c10gPSBjb2RlID0gY29kZSArIGJsX2NvdW50W2JpdHMgLSAxXSA8PCAxOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IG1heF9jb2RlOyBuKyspIHsKICAgICAgICAgIHZhciBsZW4gPSB0cmVlW24gKiAyICsgMV07CiAgICAgICAgICBpZiAobGVuID09PSAwKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgdHJlZVtuICogMl0gPSBiaV9yZXZlcnNlKG5leHRfY29kZVtsZW5dKyssIGxlbik7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIHRyX3N0YXRpY19pbml0KCkgewogICAgICAgIHZhciBuOwogICAgICAgIHZhciBiaXRzOwogICAgICAgIHZhciBsZW5ndGg7CiAgICAgICAgdmFyIGNvZGU7CiAgICAgICAgdmFyIGRpc3Q7CiAgICAgICAgdmFyIGJsX2NvdW50ID0gbmV3IEFycmF5KE1BWF9CSVRTICsgMSk7CiAgICAgICAgbGVuZ3RoID0gMDsKICAgICAgICBmb3IgKGNvZGUgPSAwOyBjb2RlIDwgTEVOR1RIX0NPREVTIC0gMTsgY29kZSsrKSB7CiAgICAgICAgICBiYXNlX2xlbmd0aFtjb2RlXSA9IGxlbmd0aDsKICAgICAgICAgIGZvciAobiA9IDA7IG4gPCAxIDw8IGV4dHJhX2xiaXRzW2NvZGVdOyBuKyspIHsKICAgICAgICAgICAgX2xlbmd0aF9jb2RlW2xlbmd0aCsrXSA9IGNvZGU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIF9sZW5ndGhfY29kZVtsZW5ndGggLSAxXSA9IGNvZGU7CiAgICAgICAgZGlzdCA9IDA7CiAgICAgICAgZm9yIChjb2RlID0gMDsgY29kZSA8IDE2OyBjb2RlKyspIHsKICAgICAgICAgIGJhc2VfZGlzdFtjb2RlXSA9IGRpc3Q7CiAgICAgICAgICBmb3IgKG4gPSAwOyBuIDwgMSA8PCBleHRyYV9kYml0c1tjb2RlXTsgbisrKSB7CiAgICAgICAgICAgIF9kaXN0X2NvZGVbZGlzdCsrXSA9IGNvZGU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRpc3QgPj49IDc7CiAgICAgICAgZm9yICg7IGNvZGUgPCBEX0NPREVTOyBjb2RlKyspIHsKICAgICAgICAgIGJhc2VfZGlzdFtjb2RlXSA9IGRpc3QgPDwgNzsKICAgICAgICAgIGZvciAobiA9IDA7IG4gPCAxIDw8IGV4dHJhX2RiaXRzW2NvZGVdIC0gNzsgbisrKSB7CiAgICAgICAgICAgIF9kaXN0X2NvZGVbMjU2ICsgZGlzdCsrXSA9IGNvZGU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZvciAoYml0cyA9IDA7IGJpdHMgPD0gTUFYX0JJVFM7IGJpdHMrKykgewogICAgICAgICAgYmxfY291bnRbYml0c10gPSAwOwogICAgICAgIH0KICAgICAgICBuID0gMDsKICAgICAgICB3aGlsZSAobiA8PSAxNDMpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gODsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzhdKys7CiAgICAgICAgfQogICAgICAgIHdoaWxlIChuIDw9IDI1NSkgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA5OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbOV0rKzsKICAgICAgICB9CiAgICAgICAgd2hpbGUgKG4gPD0gMjc5KSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDc7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs3XSsrOwogICAgICAgIH0KICAgICAgICB3aGlsZSAobiA8PSAyODcpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gODsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzhdKys7CiAgICAgICAgfQogICAgICAgIGdlbl9jb2RlcyhzdGF0aWNfbHRyZWUsIExfQ09ERVMgKyAxLCBibF9jb3VudCk7CiAgICAgICAgZm9yIChuID0gMDsgbiA8IERfQ09ERVM7IG4rKykgewogICAgICAgICAgc3RhdGljX2R0cmVlW24gKiAyICsgMV0gPSA1OwogICAgICAgICAgc3RhdGljX2R0cmVlW24gKiAyXSA9IGJpX3JldmVyc2UobiwgNSk7CiAgICAgICAgfQogICAgICAgIHN0YXRpY19sX2Rlc2MgPSBuZXcgU3RhdGljVHJlZURlc2Moc3RhdGljX2x0cmVlLCBleHRyYV9sYml0cywgTElURVJBTFMgKyAxLCBMX0NPREVTLCBNQVhfQklUUyk7CiAgICAgICAgc3RhdGljX2RfZGVzYyA9IG5ldyBTdGF0aWNUcmVlRGVzYyhzdGF0aWNfZHRyZWUsIGV4dHJhX2RiaXRzLCAwLCBEX0NPREVTLCBNQVhfQklUUyk7CiAgICAgICAgc3RhdGljX2JsX2Rlc2MgPSBuZXcgU3RhdGljVHJlZURlc2MobmV3IEFycmF5KDApLCBleHRyYV9ibGJpdHMsIDAsIEJMX0NPREVTLCBNQVhfQkxfQklUUyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5pdF9ibG9jayhzKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgZm9yIChuID0gMDsgbiA8IExfQ09ERVM7IG4rKykgewogICAgICAgICAgcy5keW5fbHRyZWVbbiAqIDJdID0gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8IERfQ09ERVM7IG4rKykgewogICAgICAgICAgcy5keW5fZHRyZWVbbiAqIDJdID0gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8IEJMX0NPREVTOyBuKyspIHsKICAgICAgICAgIHMuYmxfdHJlZVtuICogMl0gPSAwOwogICAgICAgIH0KICAgICAgICBzLmR5bl9sdHJlZVtFTkRfQkxPQ0sgKiAyXSA9IDE7CiAgICAgICAgcy5vcHRfbGVuID0gcy5zdGF0aWNfbGVuID0gMDsKICAgICAgICBzLmxhc3RfbGl0ID0gcy5tYXRjaGVzID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBiaV93aW5kdXAocykgewogICAgICAgIGlmIChzLmJpX3ZhbGlkID4gOCkgewogICAgICAgICAgcHV0X3Nob3J0KHMsIHMuYmlfYnVmKTsKICAgICAgICB9IGVsc2UgaWYgKHMuYmlfdmFsaWQgPiAwKSB7CiAgICAgICAgICBzLnBlbmRpbmdfYnVmW3MucGVuZGluZysrXSA9IHMuYmlfYnVmOwogICAgICAgIH0KICAgICAgICBzLmJpX2J1ZiA9IDA7CiAgICAgICAgcy5iaV92YWxpZCA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gY29weV9ibG9jayhzLCBidWYsIGxlbiwgaGVhZGVyKSB7CiAgICAgICAgYmlfd2luZHVwKHMpOwogICAgICAgIGlmIChoZWFkZXIpIHsKICAgICAgICAgIHB1dF9zaG9ydChzLCBsZW4pOwogICAgICAgICAgcHV0X3Nob3J0KHMsIH5sZW4pOwogICAgICAgIH0KICAgICAgICB1dGlscy5hcnJheVNldChzLnBlbmRpbmdfYnVmLCBzLndpbmRvdywgYnVmLCBsZW4sIHMucGVuZGluZyk7CiAgICAgICAgcy5wZW5kaW5nICs9IGxlbjsKICAgICAgfQogICAgICBmdW5jdGlvbiBzbWFsbGVyKHRyZWUsIG4sIG0sIGRlcHRoKSB7CiAgICAgICAgdmFyIF9uMiA9IG4gKiAyOwogICAgICAgIHZhciBfbTIgPSBtICogMjsKICAgICAgICByZXR1cm4gdHJlZVtfbjJdIDwgdHJlZVtfbTJdIHx8IHRyZWVbX24yXSA9PT0gdHJlZVtfbTJdICYmIGRlcHRoW25dIDw9IGRlcHRoW21dOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHBxZG93bmhlYXAocywgdHJlZSwgaykgewogICAgICAgIHZhciB2ID0gcy5oZWFwW2tdOwogICAgICAgIHZhciBqID0gayA8PCAxOwogICAgICAgIHdoaWxlIChqIDw9IHMuaGVhcF9sZW4pIHsKICAgICAgICAgIGlmIChqIDwgcy5oZWFwX2xlbiAmJiBzbWFsbGVyKHRyZWUsIHMuaGVhcFtqICsgMV0sIHMuaGVhcFtqXSwgcy5kZXB0aCkpIHsKICAgICAgICAgICAgaisrOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHNtYWxsZXIodHJlZSwgdiwgcy5oZWFwW2pdLCBzLmRlcHRoKSkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIHMuaGVhcFtrXSA9IHMuaGVhcFtqXTsKICAgICAgICAgIGsgPSBqOwogICAgICAgICAgaiA8PD0gMTsKICAgICAgICB9CiAgICAgICAgcy5oZWFwW2tdID0gdjsKICAgICAgfQogICAgICBmdW5jdGlvbiBjb21wcmVzc19ibG9jayhzLCBsdHJlZSwgZHRyZWUpIHsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgbGM7CiAgICAgICAgdmFyIGx4ID0gMDsKICAgICAgICB2YXIgY29kZTsKICAgICAgICB2YXIgZXh0cmE7CiAgICAgICAgaWYgKHMubGFzdF9saXQgIT09IDApIHsKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgZGlzdCA9IHMucGVuZGluZ19idWZbcy5kX2J1ZiArIGx4ICogMl0gPDwgOCB8IHMucGVuZGluZ19idWZbcy5kX2J1ZiArIGx4ICogMiArIDFdOwogICAgICAgICAgICBsYyA9IHMucGVuZGluZ19idWZbcy5sX2J1ZiArIGx4XTsKICAgICAgICAgICAgbHgrKzsKICAgICAgICAgICAgaWYgKGRpc3QgPT09IDApIHsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgbGMsIGx0cmVlKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBjb2RlID0gX2xlbmd0aF9jb2RlW2xjXTsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY29kZSArIExJVEVSQUxTICsgMSwgbHRyZWUpOwogICAgICAgICAgICAgIGV4dHJhID0gZXh0cmFfbGJpdHNbY29kZV07CiAgICAgICAgICAgICAgaWYgKGV4dHJhICE9PSAwKSB7CiAgICAgICAgICAgICAgICBsYyAtPSBiYXNlX2xlbmd0aFtjb2RlXTsKICAgICAgICAgICAgICAgIHNlbmRfYml0cyhzLCBsYywgZXh0cmEpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBkaXN0LS07CiAgICAgICAgICAgICAgY29kZSA9IGRfY29kZShkaXN0KTsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY29kZSwgZHRyZWUpOwogICAgICAgICAgICAgIGV4dHJhID0gZXh0cmFfZGJpdHNbY29kZV07CiAgICAgICAgICAgICAgaWYgKGV4dHJhICE9PSAwKSB7CiAgICAgICAgICAgICAgICBkaXN0IC09IGJhc2VfZGlzdFtjb2RlXTsKICAgICAgICAgICAgICAgIHNlbmRfYml0cyhzLCBkaXN0LCBleHRyYSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IHdoaWxlIChseCA8IHMubGFzdF9saXQpOwogICAgICAgIH0KICAgICAgICBzZW5kX2NvZGUocywgRU5EX0JMT0NLLCBsdHJlZSk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYnVpbGRfdHJlZShzLCBkZXNjKSB7CiAgICAgICAgdmFyIHRyZWUgPSBkZXNjLmR5bl90cmVlOwogICAgICAgIHZhciBzdHJlZSA9IGRlc2Muc3RhdF9kZXNjLnN0YXRpY190cmVlOwogICAgICAgIHZhciBoYXNfc3RyZWUgPSBkZXNjLnN0YXRfZGVzYy5oYXNfc3RyZWU7CiAgICAgICAgdmFyIGVsZW1zID0gZGVzYy5zdGF0X2Rlc2MuZWxlbXM7CiAgICAgICAgdmFyIG4sIG07CiAgICAgICAgdmFyIG1heF9jb2RlID0gLTE7CiAgICAgICAgdmFyIG5vZGU7CiAgICAgICAgcy5oZWFwX2xlbiA9IDA7CiAgICAgICAgcy5oZWFwX21heCA9IEhFQVBfU0laRTsKICAgICAgICBmb3IgKG4gPSAwOyBuIDwgZWxlbXM7IG4rKykgewogICAgICAgICAgaWYgKHRyZWVbbiAqIDJdICE9PSAwKSB7CiAgICAgICAgICAgIHMuaGVhcFsrK3MuaGVhcF9sZW5dID0gbWF4X2NvZGUgPSBuOwogICAgICAgICAgICBzLmRlcHRoW25dID0gMDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRyZWVbbiAqIDIgKyAxXSA9IDA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHdoaWxlIChzLmhlYXBfbGVuIDwgMikgewogICAgICAgICAgbm9kZSA9IHMuaGVhcFsrK3MuaGVhcF9sZW5dID0gbWF4X2NvZGUgPCAyID8gKyttYXhfY29kZSA6IDA7CiAgICAgICAgICB0cmVlW25vZGUgKiAyXSA9IDE7CiAgICAgICAgICBzLmRlcHRoW25vZGVdID0gMDsKICAgICAgICAgIHMub3B0X2xlbi0tOwogICAgICAgICAgaWYgKGhhc19zdHJlZSkgewogICAgICAgICAgICBzLnN0YXRpY19sZW4gLT0gc3RyZWVbbm9kZSAqIDIgKyAxXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZGVzYy5tYXhfY29kZSA9IG1heF9jb2RlOwogICAgICAgIGZvciAobiA9IHMuaGVhcF9sZW4gPj4gMTsgbiA+PSAxOyBuLS0pIHsKICAgICAgICAgIHBxZG93bmhlYXAocywgdHJlZSwgbik7CiAgICAgICAgfQogICAgICAgIG5vZGUgPSBlbGVtczsKICAgICAgICBkbyB7CiAgICAgICAgICBuID0gcy5oZWFwWzFdOwogICAgICAgICAgcy5oZWFwWzFdID0gcy5oZWFwW3MuaGVhcF9sZW4tLV07CiAgICAgICAgICBwcWRvd25oZWFwKHMsIHRyZWUsIDEpOwogICAgICAgICAgbSA9IHMuaGVhcFsxXTsKICAgICAgICAgIHMuaGVhcFstLXMuaGVhcF9tYXhdID0gbjsKICAgICAgICAgIHMuaGVhcFstLXMuaGVhcF9tYXhdID0gbTsKICAgICAgICAgIHRyZWVbbm9kZSAqIDJdID0gdHJlZVtuICogMl0gKyB0cmVlW20gKiAyXTsKICAgICAgICAgIHMuZGVwdGhbbm9kZV0gPSAocy5kZXB0aFtuXSA+PSBzLmRlcHRoW21dID8gcy5kZXB0aFtuXSA6IHMuZGVwdGhbbV0pICsgMTsKICAgICAgICAgIHRyZWVbbiAqIDIgKyAxXSA9IHRyZWVbbSAqIDIgKyAxXSA9IG5vZGU7CiAgICAgICAgICBzLmhlYXBbMV0gPSBub2RlKys7CiAgICAgICAgICBwcWRvd25oZWFwKHMsIHRyZWUsIDEpOwogICAgICAgIH0gd2hpbGUgKHMuaGVhcF9sZW4gPj0gMik7CiAgICAgICAgcy5oZWFwWy0tcy5oZWFwX21heF0gPSBzLmhlYXBbMV07CiAgICAgICAgZ2VuX2JpdGxlbihzLCBkZXNjKTsKICAgICAgICBnZW5fY29kZXModHJlZSwgbWF4X2NvZGUsIHMuYmxfY291bnQpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNjYW5fdHJlZShzLCB0cmVlLCBtYXhfY29kZSkgewogICAgICAgIHZhciBuOwogICAgICAgIHZhciBwcmV2bGVuID0gLTE7CiAgICAgICAgdmFyIGN1cmxlbjsKICAgICAgICB2YXIgbmV4dGxlbiA9IHRyZWVbMCAqIDIgKyAxXTsKICAgICAgICB2YXIgY291bnQgPSAwOwogICAgICAgIHZhciBtYXhfY291bnQgPSA3OwogICAgICAgIHZhciBtaW5fY291bnQgPSA0OwogICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgIH0KICAgICAgICB0cmVlWyhtYXhfY29kZSArIDEpICogMiArIDFdID0gNjU1MzU7CiAgICAgICAgZm9yIChuID0gMDsgbiA8PSBtYXhfY29kZTsgbisrKSB7CiAgICAgICAgICBjdXJsZW4gPSBuZXh0bGVuOwogICAgICAgICAgbmV4dGxlbiA9IHRyZWVbKG4gKyAxKSAqIDIgKyAxXTsKICAgICAgICAgIGlmICgrK2NvdW50IDwgbWF4X2NvdW50ICYmIGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPCBtaW5fY291bnQpIHsKICAgICAgICAgICAgcy5ibF90cmVlW2N1cmxlbiAqIDJdICs9IGNvdW50OwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gIT09IDApIHsKICAgICAgICAgICAgaWYgKGN1cmxlbiAhPT0gcHJldmxlbikgewogICAgICAgICAgICAgIHMuYmxfdHJlZVtjdXJsZW4gKiAyXSsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHMuYmxfdHJlZVtSRVBfM182ICogMl0rKzsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPD0gMTApIHsKICAgICAgICAgICAgcy5ibF90cmVlW1JFUFpfM18xMCAqIDJdKys7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLmJsX3RyZWVbUkVQWl8xMV8xMzggKiAyXSsrOwogICAgICAgICAgfQogICAgICAgICAgY291bnQgPSAwOwogICAgICAgICAgcHJldmxlbiA9IGN1cmxlbjsKICAgICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDY7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtYXhfY291bnQgPSA3OwogICAgICAgICAgICBtaW5fY291bnQgPSA0OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBzZW5kX3RyZWUocywgdHJlZSwgbWF4X2NvZGUpIHsKICAgICAgICB2YXIgbjsKICAgICAgICB2YXIgcHJldmxlbiA9IC0xOwogICAgICAgIHZhciBjdXJsZW47CiAgICAgICAgdmFyIG5leHRsZW4gPSB0cmVlWzAgKiAyICsgMV07CiAgICAgICAgdmFyIGNvdW50ID0gMDsKICAgICAgICB2YXIgbWF4X2NvdW50ID0gNzsKICAgICAgICB2YXIgbWluX2NvdW50ID0gNDsKICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8PSBtYXhfY29kZTsgbisrKSB7CiAgICAgICAgICBjdXJsZW4gPSBuZXh0bGVuOwogICAgICAgICAgbmV4dGxlbiA9IHRyZWVbKG4gKyAxKSAqIDIgKyAxXTsKICAgICAgICAgIGlmICgrK2NvdW50IDwgbWF4X2NvdW50ICYmIGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPCBtaW5fY291bnQpIHsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjdXJsZW4sIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIH0gd2hpbGUgKC0tY291bnQgIT09IDApOwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gIT09IDApIHsKICAgICAgICAgICAgaWYgKGN1cmxlbiAhPT0gcHJldmxlbikgewogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjdXJsZW4sIHMuYmxfdHJlZSk7CiAgICAgICAgICAgICAgY291bnQtLTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzZW5kX2NvZGUocywgUkVQXzNfNiwgcy5ibF90cmVlKTsKICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGNvdW50IC0gMywgMik7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDw9IDEwKSB7CiAgICAgICAgICAgIHNlbmRfY29kZShzLCBSRVBaXzNfMTAsIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIHNlbmRfYml0cyhzLCBjb3VudCAtIDMsIDMpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgc2VuZF9jb2RlKHMsIFJFUFpfMTFfMTM4LCBzLmJsX3RyZWUpOwogICAgICAgICAgICBzZW5kX2JpdHMocywgY291bnQgLSAxMSwgNyk7CiAgICAgICAgICB9CiAgICAgICAgICBjb3VudCA9IDA7CiAgICAgICAgICBwcmV2bGVuID0gY3VybGVuOwogICAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNjsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDc7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJ1aWxkX2JsX3RyZWUocykgewogICAgICAgIHZhciBtYXhfYmxpbmRleDsKICAgICAgICBzY2FuX3RyZWUocywgcy5keW5fbHRyZWUsIHMubF9kZXNjLm1heF9jb2RlKTsKICAgICAgICBzY2FuX3RyZWUocywgcy5keW5fZHRyZWUsIHMuZF9kZXNjLm1heF9jb2RlKTsKICAgICAgICBidWlsZF90cmVlKHMsIHMuYmxfZGVzYyk7CiAgICAgICAgZm9yIChtYXhfYmxpbmRleCA9IEJMX0NPREVTIC0gMTsgbWF4X2JsaW5kZXggPj0gMzsgbWF4X2JsaW5kZXgtLSkgewogICAgICAgICAgaWYgKHMuYmxfdHJlZVtibF9vcmRlclttYXhfYmxpbmRleF0gKiAyICsgMV0gIT09IDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMub3B0X2xlbiArPSAzICogKG1heF9ibGluZGV4ICsgMSkgKyA1ICsgNSArIDQ7CiAgICAgICAgcmV0dXJuIG1heF9ibGluZGV4OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNlbmRfYWxsX3RyZWVzKHMsIGxjb2RlcywgZGNvZGVzLCBibGNvZGVzKSB7CiAgICAgICAgdmFyIHJhbms7CiAgICAgICAgc2VuZF9iaXRzKHMsIGxjb2RlcyAtIDI1NywgNSk7CiAgICAgICAgc2VuZF9iaXRzKHMsIGRjb2RlcyAtIDEsIDUpOwogICAgICAgIHNlbmRfYml0cyhzLCBibGNvZGVzIC0gNCwgNCk7CiAgICAgICAgZm9yIChyYW5rID0gMDsgcmFuayA8IGJsY29kZXM7IHJhbmsrKykgewogICAgICAgICAgc2VuZF9iaXRzKHMsIHMuYmxfdHJlZVtibF9vcmRlcltyYW5rXSAqIDIgKyAxXSwgMyk7CiAgICAgICAgfQogICAgICAgIHNlbmRfdHJlZShzLCBzLmR5bl9sdHJlZSwgbGNvZGVzIC0gMSk7CiAgICAgICAgc2VuZF90cmVlKHMsIHMuZHluX2R0cmVlLCBkY29kZXMgLSAxKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZXRlY3RfZGF0YV90eXBlKHMpIHsKICAgICAgICB2YXIgYmxhY2tfbWFzayA9IDQwOTM2MjQ0NDc7CiAgICAgICAgdmFyIG47CiAgICAgICAgZm9yIChuID0gMDsgbiA8PSAzMTsgbisrLCBibGFja19tYXNrID4+Pj0gMSkgewogICAgICAgICAgaWYgKGJsYWNrX21hc2sgJiAxICYmIHMuZHluX2x0cmVlW24gKiAyXSAhPT0gMCkgewogICAgICAgICAgICByZXR1cm4gWl9CSU5BUlk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLmR5bl9sdHJlZVs5ICogMl0gIT09IDAgfHwgcy5keW5fbHRyZWVbMTAgKiAyXSAhPT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AgIH0KICAgICAgZnVuY3Rpb24gX3RyX2FsaWduKHMpIHsKICAgICAgICBzZW5kX2JpdHMocywgU1RBVElDX1RSRUVTIDw8IDEsIDMpOwogICAgICAgIHNlbmRfY29kZShzLCBFTkRfQkxPQ0ssIHN0YXRpY19sdHJlZSk7CiAgICAgICAgYmlfZmx1c2gocyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX3RyX2ZsdXNoX2Jsb2NrKHMsIGJ1Ziwgc3RvcmVkX2xlbiwgbGFzdCkgewogICAgICAgIHZhciBvcHRfbGVuYiwgc3RhdGljX2xlbmI7CiAgICAgICAgdmFyIG1heF9ibGluZGV4ID0gMDsKICAgICAgICBpZiAocy5sZXZlbCA+IDApIHsKICAgICAgICAgIGlmIChzLnN0cm0uZGF0YV90eXBlID09PSBaX1VOS05PV04pIHsKICAgICAgICAgICAgcy5zdHJtLmRhdGFfdHlwZSA9IGRldGVjdF9kYXRhX3R5cGUocyk7CiAgICAgICAgICB9CiAgICAgICAgICBidWlsZF90cmVlKHMsIHMubF9kZXNjKTsKICAgICAgICAgIGJ1aWxkX3RyZWUocywgcy5kX2Rlc2MpOwogICAgICAgICAgbWF4X2JsaW5kZXggPSBidWlsZF9ibF90cmVlKHMpOwogICAgICAgICAgb3B0X2xlbmIgPSBzLm9wdF9sZW4gKyAzICsgNyA+Pj4gMzsKICAgICAgICAgIHN0YXRpY19sZW5iID0gcy5zdGF0aWNfbGVuICsgMyArIDcgPj4+IDM7CiAgICAgICAgICBpZiAoc3RhdGljX2xlbmIgPD0gb3B0X2xlbmIpIHsKICAgICAgICAgICAgb3B0X2xlbmIgPSBzdGF0aWNfbGVuYjsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgb3B0X2xlbmIgPSBzdGF0aWNfbGVuYiA9IHN0b3JlZF9sZW4gKyA1OwogICAgICAgIH0KICAgICAgICBpZiAoc3RvcmVkX2xlbiArIDQgPD0gb3B0X2xlbmIgJiYgYnVmICE9PSAtMSkgewogICAgICAgICAgX3RyX3N0b3JlZF9ibG9jayhzLCBidWYsIHN0b3JlZF9sZW4sIGxhc3QpOwogICAgICAgIH0gZWxzZSBpZiAocy5zdHJhdGVneSA9PT0gWl9GSVhFRCB8fCBzdGF0aWNfbGVuYiA9PT0gb3B0X2xlbmIpIHsKICAgICAgICAgIHNlbmRfYml0cyhzLCAoU1RBVElDX1RSRUVTIDw8IDEpICsgKGxhc3QgPyAxIDogMCksIDMpOwogICAgICAgICAgY29tcHJlc3NfYmxvY2socywgc3RhdGljX2x0cmVlLCBzdGF0aWNfZHRyZWUpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzZW5kX2JpdHMocywgKERZTl9UUkVFUyA8PCAxKSArIChsYXN0ID8gMSA6IDApLCAzKTsKICAgICAgICAgIHNlbmRfYWxsX3RyZWVzKHMsIHMubF9kZXNjLm1heF9jb2RlICsgMSwgcy5kX2Rlc2MubWF4X2NvZGUgKyAxLCBtYXhfYmxpbmRleCArIDEpOwogICAgICAgICAgY29tcHJlc3NfYmxvY2socywgcy5keW5fbHRyZWUsIHMuZHluX2R0cmVlKTsKICAgICAgICB9CiAgICAgICAgaW5pdF9ibG9jayhzKTsKICAgICAgICBpZiAobGFzdCkgewogICAgICAgICAgYmlfd2luZHVwKHMpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBfdHJfdGFsbHkocywgZGlzdCwgbGMpIHsKICAgICAgICBzLnBlbmRpbmdfYnVmW3MuZF9idWYgKyBzLmxhc3RfbGl0ICogMl0gPSBkaXN0ID4+PiA4ICYgMjU1OwogICAgICAgIHMucGVuZGluZ19idWZbcy5kX2J1ZiArIHMubGFzdF9saXQgKiAyICsgMV0gPSBkaXN0ICYgMjU1OwogICAgICAgIHMucGVuZGluZ19idWZbcy5sX2J1ZiArIHMubGFzdF9saXRdID0gbGMgJiAyNTU7CiAgICAgICAgcy5sYXN0X2xpdCsrOwogICAgICAgIGlmIChkaXN0ID09PSAwKSB7CiAg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+IDE2ICYgNjU1MzUgfCAwLCBuID0gMDsKICAgICAgICB3aGlsZSAobGVuICE9PSAwKSB7CiAgICAgICAgICBuID0gbGVuID4gMmUzID8gMmUzIDogbGVuOwogICAgICAgICAgbGVuIC09IG47CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIHMxID0gczEgKyBidWZbcG9zKytdIHwgMDsKICAgICAgICAgICAgczIgPSBzMiArIHMxIHwgMDsKICAgICAgICAgIH0gd2hpbGUgKC0tbik7CiAgICAgICAgICBzMSAlPSA2NTUyMTsKICAgICAgICAgIHMyICU9IDY1NTIxOwogICAgICAgIH0KICAgICAgICByZXR1cm4gczEgfCBzMiA8PCAxNiB8IDA7CiAgICAgIH0KICAgICAgbW9kdWxlMi5leHBvcnRzID0gYWRsZXIzMjsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2NyYzMyLmpzCiAgdmFyIHJlcXVpcmVfY3JjMzIgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvY3JjMzIuanMiKGV4cG9ydHMyLCBtb2R1bGUyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBmdW5jdGlvbiBtYWtlVGFibGUoKSB7CiAgICAgICAgdmFyIGMsIHRhYmxlID0gW107CiAgICAgICAgZm9yICh2YXIgbiA9IDA7IG4gPCAyNTY7IG4rKykgewogICAgICAgICAgYyA9IG47CiAgICAgICAgICBmb3IgKHZhciBrID0gMDsgayA8IDg7IGsrKykgewogICAgICAgICAgICBjID0gYyAmIDEgPyAzOTg4MjkyMzg0IF4gYyA+Pj4gMSA6IGMgPj4+IDE7CiAgICAgICAgICB9CiAgICAgICAgICB0YWJsZVtuXSA9IGM7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0YWJsZTsKICAgICAgfQogICAgICB2YXIgY3JjVGFibGUgPSBtYWtlVGFibGUoKTsKICAgICAgZnVuY3Rpb24gY3JjMzIoY3JjLCBidWYsIGxlbiwgcG9zKSB7CiAgICAgICAgdmFyIHQgPSBjcmNUYWJsZSwgZW5kID0gcG9zICsgbGVuOwogICAgICAgIGNyYyBePSAtMTsKICAgICAgICBmb3IgKHZhciBpID0gcG9zOyBpIDwgZW5kOyBpKyspIHsKICAgICAgICAgIGNyYyA9IGNyYyA+Pj4gOCBeIHRbKGNyYyBeIGJ1ZltpXSkgJiAyNTVdOwogICAgICAgIH0KICAgICAgICByZXR1cm4gY3JjIF4gLTE7CiAgICAgIH0KICAgICAgbW9kdWxlMi5leHBvcnRzID0gY3JjMzI7CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9tZXNzYWdlcy5qcwogIHZhciByZXF1aXJlX21lc3NhZ2VzID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL21lc3NhZ2VzLmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgbW9kdWxlMi5leHBvcnRzID0gewogICAgICAgIDI6ICJuZWVkIGRpY3Rpb25hcnkiLAogICAgICAgIDE6ICJzdHJlYW0gZW5kIiwKICAgICAgICAwOiAiIiwKICAgICAgICAiLTEiOiAiZmlsZSBlcnJvciIsCiAgICAgICAgIi0yIjogInN0cmVhbSBlcnJvciIsCiAgICAgICAgIi0zIjogImRhdGEgZXJyb3IiLAogICAgICAgICItNCI6ICJpbnN1ZmZpY2llbnQgbWVtb3J5IiwKICAgICAgICAiLTUiOiAi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gICAgdmFyIFpfSFVGRk1BTl9PTkxZID0gMjsKICAgICAgdmFyIFpfUkxFID0gMzsKICAgICAgdmFyIFpfRklYRUQgPSA0OwogICAgICB2YXIgWl9ERUZBVUxUX1NUUkFURUdZID0gMDsKICAgICAgdmFyIFpfVU5LTk9XTiA9IDI7CiAgICAgIHZhciBaX0RFRkxBVEVEID0gODsKICAgICAgdmFyIE1BWF9NRU1fTEVWRUwgPSA5OwogICAgICB2YXIgTUFYX1dCSVRTID0gMTU7CiAgICAgIHZhciBERUZfTUVNX0xFVkVMID0gODsKICAgICAgdmFyIExFTkdUSF9DT0RFUyA9IDI5OwogICAgICB2YXIgTElURVJBTFMgPSAyNTY7CiAgICAgIHZhciBMX0NPREVTID0gTElURVJBTFMgKyAxICsgTEVOR1RIX0NPREVTOwogICAgICB2YXIgRF9DT0RFUyA9IDMwOwogICAgICB2YXIgQkxfQ09ERVMgPSAxOTsKICAgICAgdmFyIEhFQVBfU0laRSA9IDIgKiBMX0NPREVTICsgMTsKICAgICAgdmFyIE1BWF9CSVRTID0gMTU7CiAgICAgIHZhciBNSU5fTUFUQ0ggPSAzOwogICAgICB2YXIgTUFYX01BVENIID0gMjU4OwogICAgICB2YXIgTUlOX0xPT0tBSEVBRCA9IE1BWF9NQVRDSCArIE1JTl9NQVRDSCArIDE7CiAgICAgIHZhciBQUkVTRVRfRElDVCA9IDMyOwogICAgICB2YXIgSU5JVF9TVEFURSA9IDQyOwogICAgICB2YXIgRVhUUkFfU1RBVEUgPSA2OTsKICAgICAgdmFyIE5BTUVfU1RBVEUgPSA3MzsKICAgICAgdmFyIENPTU1FTlRfU1RBVEUgPSA5MTsKICAgICAgdmFyIEhDUkNfU1RBVEUgPSAxMDM7CiAgICAgIHZhciBCVVNZX1NUQVRFID0gMTEzOwogICAgICB2YXIgRklOSVNIX1NUQVRFID0gNjY2OwogICAgICB2YXIgQlNfTkVFRF9NT1JFID0gMTsKICAgICAgdmFyIEJTX0JMT0NLX0RPTkUgPSAyOwogICAgICB2YXIgQlNfRklOSVNIX1NUQVJURUQgPSAzOwogICAgICB2YXIgQlNfRklOSVNIX0RPTkUgPSA0OwogICAgICB2YXIgT1NfQ09ERSA9IDM7CiAgICAgIGZ1bmN0aW9uIGVycihzdHJtLCBlcnJvckNvZGUpIHsKICAgICAgICBzdHJtLm1zZyA9IG1zZ1tlcnJvckNvZGVdOwogICAgICAgIHJldHVybiBlcnJvckNvZGU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcmFuayhmKSB7CiAgICAgICAgcmV0dXJuIChmIDw8IDEpIC0gKGYgPiA0ID8gOSA6IDApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHplcm8oYnVmKSB7CiAgICAgICAgdmFyIGxlbiA9IGJ1Zi5sZW5ndGg7CiAgICAgICAgd2hpbGUgKC0tbGVuID49IDApIHsKICAgICAgICAgIGJ1ZltsZW5dID0gMDsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZmx1c2hfcGVuZGluZyhzdHJtKSB7CiAgICAgICAgdmFyIHMgPSBzdHJtLnN0YXRlOwogICAgICAgIHZhciBsZW4gPSBzLnBlbmRpbmc7CiAgICAgICAgaWYgKGxlbiA+IHN0cm0uYXZhaWxfb3V0KSB7CiAgICAgICAgICBsZW4gPSBzdHJtLmF2YWlsX291dDsKICAgICAgICB9CiAgICAgICAgaWYgKGxlbiA9PT0gMCkgewogICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KICAgICAgICB1dGlscy5hcnJheVNldChzdHJtLm91dHB1dCwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nX291dCwgbGVuLCBzdHJtLm5leHRfb3V0KTsKICAgICAgICBzdHJtLm5leHRfb3V0ICs9IGxlbjsKICAgICAgICBzLnBlbmRpbmdfb3V0ICs9IGxlbjsKICAgICAgICBzdHJtLnRvdGFsX291dCArPSBsZW47CiAgICAgICAgc3RybS5hdmFpbF9vdXQgLT0gbGVuOwogICAgICAgIHMucGVuZGluZyAtPSBsZW47CiAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gMCkgewogICAgICAgICAgcy5wZW5kaW5nX291dCA9IDA7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZsdXNoX2Jsb2NrX29ubHkocywgbGFzdCkgewogICAgICAgIHRyZWVzLl90cl9mbHVzaF9ibG9jayhzLCBzLmJsb2NrX3N0YXJ0ID49IDAgPyBzLmJsb2NrX3N0YXJ0IDogLTEsIHMuc3Ryc3RhcnQgLSBzLmJsb2NrX3N0YXJ0LCBsYXN0KTsKICAgICAgICBzLmJsb2NrX3N0YXJ0ID0gcy5zdHJzdGFydDsKICAgICAgICBmbHVzaF9wZW5kaW5nKHMuc3RybSk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcHV0X2J5dGUocywgYikgewogICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gYjsKICAgICAgfQogICAgICBmdW5jdGlvbiBwdXRTaG9ydE1TQihzLCBiKSB7CiAgICAgICAgcy5wZW5kaW5nX2J1ZltzLnBlbmRpbmcrK10gPSBiID4+PiA4ICYgMjU1OwogICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gYiAmIDI1NTsKICAgICAgfQogICAgICBmdW5jdGlvbiByZWFkX2J1ZihzdHJtLCBidWYsIHN0YXJ0LCBzaXplKSB7CiAgICAgICAgdmFyIGxlbiA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgaWYgKGxlbiA+IHNpemUpIHsKICAgICAgICAgIGxlbiA9IHNpemU7CiAgICAgICAgfQogICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICBzdHJtLmF2YWlsX2luIC09IGxlbjsKICAgICAgICB1dGlscy5hcnJheVNldChidWYsIHN0cm0uaW5wdXQsIHN0cm0ubmV4dF9pbiwgbGVuLCBzdGFydCk7CiAgICAgICAgaWYgKHN0cm0uc3RhdGUud3Jh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AgICAgaWYgKHMucHJldl9sZW5ndGggPj0gcy5nb29kX21hdGNoKSB7CiAgICAgICAgICBjaGFpbl9sZW5ndGggPj49IDI7CiAgICAgICAgfQogICAgICAgIGlmIChuaWNlX21hdGNoID4gcy5sb29rYWhlYWQpIHsKICAgICAgICAgIG5pY2VfbWF0Y2ggPSBzLmxvb2thaGVhZDsKICAgICAgICB9CiAgICAgICAgZG8gewogICAgICAgICAgbWF0Y2ggPSBjdXJfbWF0Y2g7CiAgICAgICAgICBpZiAoX3dpblttYXRjaCArIGJlc3RfbGVuXSAhPT0gc2Nhbl9lbmQgfHwgX3dpblttYXRjaCArIGJlc3RfbGVuIC0gMV0gIT09IHNjYW5fZW5kMSB8fCBfd2luW21hdGNoXSAhPT0gX3dpbltzY2FuXSB8fCBfd2luWysrbWF0Y2hdICE9PSBfd2luW3NjYW4gKyAxXSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIHNjYW4gKz0gMjsKICAgICAgICAgIG1hdGNoKys7CiAgICAgICAgICBkbyB7CiAgICAgICAgICB9IHdoaWxlIChfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIHNjYW4gPCBzdHJlbmQpOwogICAgICAgICAgbGVuID0gTUFYX01BVENIIC0gKHN0cmVuZCAtIHNjYW4pOwogICAgICAgICAgc2NhbiA9IHN0cmVuZCAtIE1BWF9NQVRDSDsKICAgICAgICAgIGlmIChsZW4gPiBiZXN0X2xlbikgewogICAgICAgICAgICBzLm1hdGNoX3N0YXJ0ID0gY3VyX21hdGNoOwogICAgICAgICAgICBiZXN0X2xlbiA9IGxlbjsKICAgICAgICAgICAgaWYgKGxlbiA+PSBuaWNlX21hdGNoKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgc2Nhbl9lbmQxID0gX3dpbltzY2FuICsgYmVzdF9sZW4gLSAxXTsKICAgICAgICAgICAgc2Nhbl9lbmQgPSBfd2luW3NjYW4gKyBiZXN0X2xlbl07CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKGN1cl9tYXRjaCA9IHByZXZbY3VyX21hdGNoICYgd21hc2tdKSA+IGxpbWl0ICYmIC0tY2hhaW5fbGVuZ3RoICE9PSAwKTsKICAgICAgICBpZiAoYmVzdF9sZW4gPD0gcy5sb29rYWhlYWQpIHsKICAgICAgICAgIHJldHVybiBiZXN0X2xlbjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHMubG9va2FoZWFkOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZpbGxfd2luZG93KHMpIHsKICAgICAgICB2YXIgX3dfc2l6ZSA9IHMud19zaXplOwogICAgICAgIHZhciBwLCBuLCBtLCBtb3JlLCBzdHI7CiAgICAgICAgZG8gewogICAgICAgICAgbW9yZSA9IHMud2luZG93X3NpemUgLSBzLmxvb2thaGVhZCAtIHMuc3Ryc3RhcnQ7CiAgICAgICAgICBpZiAocy5zdHJzdGFydCA+PSBfd19zaXplICsgKF93X3NpemUgLSBNSU5fTE9PS0FIRUFEKSkgewogICAgICAgICAgICB1dGlscy5hcnJheVNldChzLndpbmRvdywgcy53aW5kb3csIF93X3NpemUsIF93X3NpemUsIDApOwogICAgICAgICAgICBzLm1hdGNoX3N0YXJ0IC09IF93X3NpemU7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgLT0gX3dfc2l6ZTsKICAgICAgICAgICAgcy5ibG9ja19zdGFydCAtPSBfd19zaXplOwogICAgICAgICAgICBuID0gcy5oYXNoX3NpemU7CiAgICAgICAgICAgIHAgPSBuOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgbSA9IHMuaGVhZFstLXBdOwogICAgICAgICAgICAgIHMuaGVhZFtwXSA9IG0gPj0gX3dfc2l6ZSA/IG0gLSBfd19zaXplIDogMDsKICAgICAgICAgICAgfSB3aGlsZSAoLS1uKTsKICAgICAgICAgICAgbiA9IF93X3NpemU7CiAgICAgICAgICAgIHAgPSBuOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgbSA9IHMucHJldlstLXBdOwogICAgICAgICAgICAgIHMucHJldltwXSA9IG0gPj0gX3dfc2l6ZSA/IG0gLSBfd19zaXplIDogMDsKICAgICAgICAgICAgfSB3aGlsZSAoLS1uKTsKICAgICAgICAgICAgbW9yZSArPSBfd19zaXplOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9pbiA9PT0gMCkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIG4gPSByZWFkX2J1ZihzLnN0cm0sIHMud2luZG93LCBzLnN0cnN0YXJ0ICsgcy5sb29rYWhlYWQsIG1vcmUpOwogICAgICAgICAgcy5sb29rYWhlYWQgKz0gbjsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCArIHMuaW5zZXJ0ID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBzdHIgPSBzLnN0cnN0YXJ0IC0gcy5pbnNlcnQ7CiAgICAgICAgICAgIHMuaW5zX2ggPSBzLndpbmRvd1tzdHJdOwogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbc3RyICsgMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIHdoaWxlIChzLmluc2VydCkgewogICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICBzLnByZXZbc3RyICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHN0cjsKICAgICAgICAgICAgICBzdHIrKzsKICAgICAgICAgICAgICBzLmluc2VydC0tOwogICAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCArIHMuaW5zZXJ0IDwgTUlOX01BVENIKSB7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlIChzLmxvb2thaGVhZCA8IE1JTl9MT09LQUhFQUQgJiYgcy5zdHJtLmF2YWlsX2luICE9PSAwKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX3N0b3JlZChzLCBmbHVzaCkgewogICAgICAgIHZhciBtYXhfYmxvY2tfc2l6ZSA9IDY1NTM1OwogICAgICAgIGlmIChtYXhfYmxvY2tfc2l6ZSA+IHMucGVuZGluZ19idWZfc2l6ZSAtIDUpIHsKICAgICAgICAgIG1heF9ibG9ja19zaXplID0gcy5wZW5kaW5nX2J1Zl9zaXplIC0gNTsKICAgICAgICB9CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPD0gMSkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwICYmIGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcy5zdHJzdGFydCArPSBzLmxvb2thaGVhZDsKICAgICAgICAgIHMubG9va2FoZWFkID0gMDsKICAgICAgICAgIHZhciBtYXhfc3RhcnQgPSBzLmJsb2NrX3N0YXJ0ICsgbWF4X2Jsb2NrX3NpemU7CiAgICAgICAgICBpZiAocy5zdHJzdGFydCA9PT0gMCB8fCBzLnN0cnN0YXJ0ID49IG1heF9zdGFydCkgewogICAgICAgICAgICBzLmxvb2thaGVhZCA9IHMuc3Ryc3RhcnQgLSBtYXhfc3RhcnQ7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgPSBtYXhfc3RhcnQ7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzLnN0cnN0YXJ0IC0gcy5ibG9ja19zdGFydCA+PSBzLndfc2l6ZSAtIE1JTl9MT09LQUhFQUQpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMuc3Ryc3RhcnQgPiBzLmJsb2NrX3N0YXJ0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9mYXN0KHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGhhc2hfaGVhZDsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGhhc2hfaGVhZCA9IDA7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICBzLmhlYWRbcy5pbnNfaF0gPSBzLnN0cn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gICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMuc3Ryc3RhcnQgKz0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSAwOwogICAgICAgICAgICAgIHMuaW5zX2ggPSBzLndpbmRvd1tzLnN0cnN0YXJ0XTsKICAgICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbcy5zdHJzdGFydCArIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgMCwgcy53aW5kb3dbcy5zdHJzdGFydF0pOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSBzLnN0cnN0YXJ0IDwgTUlOX01BVENIIC0gMSA/IHMuc3Ryc3RhcnQgOiBNSU5fTUFUQ0ggLSAxOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19CTE9DS19ET05FOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfc2xvdyhzLCBmbHVzaCkgewogICAgICAgIHZhciBoYXNoX2hlYWQ7CiAgICAgICAgdmFyIGJmbHVzaDsKICAgICAgICB2YXIgbWF4X2luc2VydDsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8IE1JTl9MT09LQUhFQUQpIHsKICAgICAgICAgICAgZmlsbF93aW5kb3cocyk7CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8IE1JTl9MT09LQUhFQUQgJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBoYXNoX2hlYWQgPSAwOwogICAgICAgICAgaWYgKHMubG9va2FoZWFkID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbcy5zdHJzdGFydCArIE1JTl9NQVRDSCAtIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICBoYXNoX2hlYWQgPSBzLnByZXZbcy5zdHJzdGFydCAmIHMud19tYXNrXSA9IHMuaGVhZFtzLmluc19oXTsKICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdG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LnByZXZfbGVuZ3RoIC09IDI7CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBpZiAoKytzLnN0cnN0YXJ0IDw9IG1heF9pbnNlcnQpIHsKICAgICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgICAgICBoYXNoX2hlYWQgPSBzLnByZXZbcy5zdHJzdGFydCAmIHMud19tYXNrXSA9IHMuaGVhZFtzLmluc19oXTsKICAgICAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IHdoaWxlICgtLXMucHJldl9sZW5ndGggIT09IDApOwogICAgICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gTUlOX01BVENIIC0gMTsKICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKHMubWF0Y2hfYXZhaWxhYmxlKSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0IC0gMV0pOwogICAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMTsKICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5tYXRjaF9hdmFpbGFibGUpIHsKICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0IC0gMV0pOwogICAgICAgICAgcy5tYXRjaF9hdmFpbGFibGUgPSAwOwogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IHMuc3Ryc3RhcnQgPCBNSU5fTUFUQ0ggLSAxID8gcy5zdHJzdGFydCA6IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9ybGUocywgZmx1c2gpIHsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIHZhciBwcmV2OwogICAgICAgIHZhciBzY2FuLCBzdHJlbmQ7CiAgICAgICAgdmFyIF93aW4gPSBzLndpbmRvdzsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSBNQVhfTUFUQ0gpIHsKICAgICAgICAgICAgZmlsbF93aW5kb3cocyk7CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSBNQVhfTUFUQ0ggJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIICYmIHMuc3Ryc3RhcnQgPiAwKSB7CiAgICAgICAgICAgIHNjYW4gPSBzLnN0cnN0YXJ0IC0gMTsKICAgICAgICAgICAgcHJldiA9IF93aW5bc2Nhbl07CiAgICAgICAgICAgIGlmIChwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSkgewogICAgICAgICAgICAgIHN0cmVuZCA9IHMuc3Ryc3RhcnQgKyBNQVhfTUFUQ0g7CiAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIH0gd2hpbGUgKHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgc2NhbiA8IHN0cmVuZCk7CiAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBNQVhfTUFUQ0ggLSAoc3RyZW5kIC0gc2Nhbik7CiAgICAgICAgICAgICAgaWYgKHMubWF0Y2hfbGVuZ3RoID4gcy5sb29rYWhlYWQpIHsKICAgICAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gcy5sb29rYWhlYWQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAocy5tYXRjaF9sZW5ndGggPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAxLCBzLm1hdGNoX2xlbmd0aCAtIE1JTl9NQVRDSCk7CiAgICAgICAgICAgIHMubG9va2FoZWFkIC09IHMubWF0Y2hfbGVuZ3RoOwogICAgICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubWF0Y2hfbGVuZ3RoOwogICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgMCwgcy53aW5kb3dbcy5zdHJzdGFydF0pOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19CTE9DS19ET05FOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfaHVmZihzLCBmbHVzaCkgewogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgZmlsbF93aW5kb3cocyk7CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGlmIChmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgaWYgKGJmbHVzaCkgewogICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5sYXN0X2xpdCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gQlNfQkxPQ0tfRE9ORTsKICAgICAgfQogICAgICBmdW5jdGlvbiBDb25maWcoZ29vZF9sZW5ndGgsIG1heF9sYXp5LCBuaWNlX2xlbmd0aCwgbWF4X2NoYWluLCBmdW5jKSB7CiAgICAgICAgdGhpcy5nb29kX2xlbmd0aCA9IGdvb2RfbGVuZ3RoOwogICAgICAgIHRoaXMubWF4X2xhenkgPSBtYXhfbGF6eTsKICAgICAgICB0aGlzLm5pY2VfbGVuZ3RoID0gbmljZV9sZW5ndGg7CiAgICAgICAgdGhpcy5tYXhfY2hhaW4gPSBtYXhfY2hhaW47CiAgICAgICAgdGhpc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2ggPSBjb25maWd1cmF0aW9uX3RhYmxlW3MubGV2ZWxdLm5pY2VfbGVuZ3RoOwogICAgICAgIHMubWF4X2NoYWluX2xlbmd0aCA9IGNvbmZpZ3VyYXRpb25fdGFibGVbcy5sZXZlbF0ubWF4X2NoYWluOwogICAgICAgIHMuc3Ryc3RhcnQgPSAwOwogICAgICAgIHMuYmxvY2tfc3RhcnQgPSAwOwogICAgICAgIHMubG9va2FoZWFkID0gMDsKICAgICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBzLnByZXZfbGVuZ3RoID0gTUlOX01BVENIIC0gMTsKICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgcy5pbnNfaCA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gRGVmbGF0ZVN0YXRlKCkgewogICAgICAgIHRoaXMuc3RybSA9IG51bGw7CiAgICAgICAgdGhpcy5zdGF0dXMgPSAwOwogICAgICAgIHRoaXMucGVuZGluZ19idWYgPSBudWxsOwogICAgICAgIHRoaXMucGVuZGluZ19idWZfc2l6ZSA9IDA7CiAgICAgICAgdGhpcy5wZW5kaW5nX291dCA9IDA7CiAgICAgICAgdGhpcy5wZW5kaW5nID0gMDsKICAgICAgICB0aGlzLndyYXAgPSAwOwogICAgICAgIHRoaXMuZ3poZWFkID0gbnVsbDsKICAgICAgICB0aGlzLmd6aW5kZXggPSAwOwogICAgICAgIHRoaXMubWV0aG9kID0gWl9ERUZMQVRFRDsKICAgICAgICB0aGlzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICB0aGlzLndfc2l6ZSA9IDA7CiAgICAgICAgdGhpcy53X2JpdHMgPSAwOwogICAgICAgIHRoaXMud19tYXNrID0gMDsKICAgICAgICB0aGlzLndpbmRvdyA9IG51bGw7CiAgICAgICAgdGhpcy53aW5kb3dfc2l6ZSA9IDA7CiAgICAgICAgdGhpcy5wcmV2ID0gbnVsbDsKICAgICAgICB0aGlzL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9VTktOT1dOOwogICAgICAgIHMgPSBzdHJtLnN0YXRlOwogICAgICAgIHMucGVuZGluZyA9IDA7CiAgICAgICAgcy5wZW5kaW5nX291dCA9IDA7CiAgICAgICAgaWYgKHMud3JhcCA8IDApIHsKICAgICAgICAgIHMud3JhcCA9IC1zLndyYXA7CiAgICAgICAgfQogICAgICAgIHMuc3RhdHVzID0gcy53cmFwID8gSU5JVF9TVEFURSA6IEJVU1lfU1RBVEU7CiAgICAgICAgc3RybS5hZGxlciA9IHMud3JhcCA9PT0gMiA/IDAgOiAxOwogICAgICAgIHMubGFzdF9mbHVzaCA9IFpfTk9fRkxVU0g7CiAgICAgICAgdHJlZXMuX3RyX2luaXQocyk7CiAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZVJlc2V0KHN0cm0pIHsKICAgICAgICB2YXIgcmV0ID0gZGVmbGF0ZVJlc2V0S2VlcChzdHJtKTsKICAgICAgICBpZiAocmV0ID09PSBaX09LKSB7CiAgICAgICAgICBsbV9pbml0KHN0cm0uc3RhdGUpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmV0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVTZXRIZWFkZXIoc3RybSwgaGVhZCkgewogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBpZiAoc3RybS5zdGF0ZS53cmFwICE9PSAyKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0cm0uc3RhdGUuZ3poZWFkID0gaGVhZDsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlSW5pdDIoc3RybSwgbGV2ZWwsIG1ldGhvZCwgd2luZG93Qml0cywgbWVtTGV2ZWwsIHN0cmF0ZWd5KSB7CiAgICAgICAgaWYgKCFzdHJtKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHZhciB3cmFwID0gMTsKICAgICAgICBpZiAobGV2ZWwgPT09IFpfREVGQVVMVF9DT01QUkVTU0lPTikgewogICAgICAgICAgbGV2ZWwgPSA2OwogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyA8IDApIHsKICAgICAgICAgIHdyYXAgPSAwOwogICAgICAgICAgd2luZG93Qml0cyA9IC13aW5kb3dCaXRzOwogICAgICAgIH0gZWxzZSBpZiAod2luZG93Qml0cyA+IDE1KSB7CiAgICAgICAgICB3cmFwID0gMjsKICAgICAgICAgIHdpbmRvd0JpdHMgLT0gMTY7CiAgICAgICAgfQogICAgICAgIGlmIChtZW1MZXZlbCA8IDEgfHwgbWVtTGV2ZWwgPiBNQVhfTUVNX0xFVkVMIHx8IG1ldGhvZCAhPT0gWl9ERUZMQVRFRCB8fCB3aW5kb3dCaXRzIDwgOCB8fCB3aW5kb3dCaXRzID4gMTUgfHwgbGV2ZWwgPCAwIHx8IGxldmVsID4gOSB8fCBzdHJhdGVneSA8IDAgfHwgc3RyYXRlZ3kgPiBaX0ZJWEVEKSB7CiAgICAgICAgICByZXR1cm4gZXJyKHN0cm0sIFpfU1RSRUFNX0VSUk9SKTsKICAgICAgICB9CiAgICAgICAgaWYgKHdpbmRvd0JpdHMgPT09IDgpIHsKICAgICAgICAgIHdpbmRvd0JpdHMgPSA5OwogICAgICAgIH0KICAgICAgICB2YXIgcyA9IG5ldyBEZWZsYXRlU3RhdGUoKTsKICAgICAgICBzdHJtLnN0YXRlID0gczsKICAgICAgICBzLnN0cm0gPSBzdHJtOwogICAgICAgIHMud3JhcCA9IHdyYXA7CiAgICAgICAgcy5nemhlYWQgPSBudWxsOwogICAgICAgIHMud19iaXRzID0gd2luZG93Qml0czsKICAgICAgICBzLndfc2l6ZSA9IDEgPDwgcy53X2JpdHM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ywgMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5sZXZlbCA9PT0gOSA/IDIgOiBzLnN0cmF0ZWd5ID49IFpfSFVGRk1BTl9PTkxZIHx8IHMubGV2ZWwgPCAyID8gNCA6IDApOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIE9TX0NPREUpOwogICAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAocy5nemhlYWQudGV4dCA/IDEgOiAwKSArIChzLmd6aGVhZC5oY3JjID8gMiA6IDApICsgKCFzLmd6aGVhZC5leHRyYSA/IDAgOiA0KSArICghcy5nemhlYWQubmFtZSA/IDAgOiA4KSArICghcy5nemhlYWQuY29tbWVudCA/IDAgOiAxNikpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLnRpbWUgJiAyNTUpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLnRpbWUgPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiAxNiAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiAyNCAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5sZXZlbCA9PT0gOSA/IDIgOiBzLnN0cmF0ZWd5ID49IFpfSFVGRk1BTl9PTkxZIHx8IHMubGV2ZWwgPCAyID8gNCA6IDApOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLm9zICYgMjU1KTsKICAgICAgICAgICAgICBpZiAocy5nemhlYWQuZXh0cmEgJiYgcy5nemhlYWQuZXh0cmEubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYS5sZW5ndGggJiAyNTUpOwogICAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQuZXh0cmEubGVuZ3RoID4+IDggJiAyNTUpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYykgewogICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZywgMCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBFWFRSQV9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdmFyIGhlYWRlciA9IFpfREVGTEFURUQgKyAocy53X2JpdHMgLSA4IDw8IDQpIDw8IDg7CiAgICAgICAgICAgIHZhciBsZXZlbF9mbGFncyA9IC0xOwogICAgICAgICAgICBpZiAocy5zdHJhdGVneSA+PSBaX0hVRkZNQU5fT05MWSB8fCBzLmxldmVsIDwgMikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMDsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsIDwgNikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMTsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsID09PSA2KSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAyOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMzsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZWFkZXIgfD0gbGV2ZWxfZmxhZ3MgPDwgNjsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBoZWFkZXIgfD0gUFJFU0VUX0RJQ1Q7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaGVhZGVyICs9IDMxIC0gaGVhZGVyICUgMzE7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgICAgcHV0U2hvcnRNU0IocywgaGVhZGVyKTsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBzdHJtLmFkbGVyID4+PiAxNik7CiAgICAgICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxlciAmIDY1NTM1KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzdHJtLmFkbGVyID0gMTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBFWFRSQV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmV4dHJhKSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgd2hpbGUgKHMuZ3ppbmRleCA8IChzLmd6aGVhZC5leHRyYS5sZW5ndGggJiA2NTUzNSkpIHsKICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQuZXh0cmFbcy5nemluZGV4XSAmIDI1NSk7CiAgICAgICAgICAgICAgcy5nemluZGV4Kys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5nemluZGV4ID09PSBzLmd6aGVhZC5leHRyYS5sZW5ndGgpIHsKICAgICAgICAgICAgICBzLmd6aW5kZXggPSAwOwogICAgICAgICAgICAgIHMuc3RhdHVzID0gTkFNRV9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5zdGF0dXMgPSBOQU1FX1NUQVRFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IE5BTUVfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLmd6aGVhZC5uYW1lKSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICAgIHZhbCA9IDE7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAocy5nemluZGV4IDwgcy5nemhlYWQubmFtZS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHZhbCA9IHMuZ3poZWFkLm5hbWUuY2hhckNvZGVBdChzLmd6aW5kZXgrKykgJiAyNTU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHZhbCA9IDA7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHZhbCk7CiAgICAgICAgICAgIH0gd2hpbGUgKHZhbCAhPT0gMCk7CiAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHZhbCA9PT0gMCkgewogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBDT01NRU5UX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IENPTU1FTlRfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gQ09NTUVOVF9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmNvbW1lbnQpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgICAgdmFsID0gMTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPCBzLmd6aGVhZC5jb21tZW50Lmxlbmd0aCkgewogICAgICAgICAgICAgICAgdmFsID0gcy5nemhlYWQuY29tbWVudC5jaGFyQ29kZUF0KHMuZ3ppbmRleCsrKSAmIDI1NTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdmFsID0gMDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgdmFsKTsKICAgICAgICAgICAgfSB3aGlsZSAodmFsICE9PSAwKTsKICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodmFsID09PSAwKSB7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBIQ1JDX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IEhDUkNfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gSENSQ19TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMpIHsKICAgICAgICAgICAgaWYgKHMucGVuZGluZyArIDIgPiBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgKyAyIDw9IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgJiAyNTUpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IEJVU1lfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnBlbmRpbmcgIT09IDApIHsKICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgIHJldHVybiBaX09LOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSBpZiAoc3RybS5hdmFpbF9pbiA9PT0gMCAmJiByYW5rKGZsdXNoKSA8PSByYW5rKG9sZF9mbHVzaCkgJiYgZmx1c2ggIT09IFpfRklOSVNIKSB7CiAgICAgICAgICByZXR1cm4gZXJyKHN0cm0sIFpfQlVGX0VSUk9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3RyX2FsaWduKHMpOwogICAgICAgICAgICB9IGVsc2UgaWYgKGZsdXNoICE9PSBaX0JMT0NLKSB7CiAgICAgICAgICAgICAgdHJlZXMuX3RyX3N0b3JlZF9ibG9jayhzLCAwLCAwLCBmYWxzZSk7CiAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZVTExfRkxVU0gpIHsKICAgICAgICAgICAgICAgIHplcm8ocy5oZWFkKTsKICAgICAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGZsdXNoICE9PSBaX0ZJTklTSCkgewogICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChzLndyYXAgPD0gMCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VORDsKICAgICAgICB9CiAgICAgICAgaWYgKHMud3JhcCA9PT0gMikgewogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDggJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciA+PiAxNiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVy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KICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBzdHJtLnN0YXRlID0gbnVsbDsKICAgICAgICByZXR1cm4gc3RhdHVzID09PSBCVVNZX1NUQVRFID8gZXJyKHN0cm0sIFpfREFUQV9FUlJPUikgOiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVTZXREaWN0aW9uYXJ5KHN0cm0sIGRpY3Rpb25hcnkpIHsKICAgICAgICB2YXIgZGljdExlbmd0aCA9IGRpY3Rpb25hcnkubGVuZ3RoOwogICAgICAgIHZhciBzOwogICAgICAgIHZhciBzdHIsIG47CiAgICAgICAgdmFyIHdyYXA7CiAgICAgICAgdmFyIGF2YWlsOwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBpbnB1dDsKICAgICAgICB2YXIgdG1wRGljdDsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgd3JhcCA9IHMud3JhcDsKICAgICAgICBpZiAod3JhcCA9PT0gMiB8fCB3cmFwID09PSAxICYmIHMuc3RhdHVzICE9PSBJTklUX1NUQVRFIHx8IHMubG9va2FoZWFkKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmICh3cmFwID09PSAxKSB7CiAgICAgICAgICBzdHJtLmFkbGVyID0gYWRsZXIzMihzdHJtLmFkbGVyLCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoLCAwKTsKICAgICAgICB9CiAgICAgICAgcy53cmFwID0gMDsKICAgICAgICBpZiAoZGljdExlbmd0aCA+PSBzLndfc2l6ZSkgewogICAgICAgICAgaWYgKHdyYXAgPT09IDApIHsKICAgICAgICAgICAgemVybyhzLmhlYWQpOwogICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHRtcERpY3QgPSBuZXcgdXRpbHMuQnVmOChzLndfc2l6ZSk7CiAgICAgICAgICB1dGlscy5hcnJheVNldCh0bXBEaWN0LCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoIC0gcy53X3NpemUsIHMud19zaXplLCAwKTsKICAgICAgICAgIGRpY3Rpb25hcnkgPSB0bXBEaWN0OwogICAgICAgICAgZGljdExlbmd0aCA9IHMud19zaXplOwogICAgICAgIH0KICAgICAgICBhdmFpbCA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgbmV4dCA9IHN0cm0ubmV4dF9pbjsKICAgICAgICBpbnB1dCA9IHN0cm0uaW5wdXQ7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IGRpY3RMZW5ndGg7CiAgICAgICAgc3RybS5uZXh0X2luID0gMDsKICAgICAgICBzdHJtLmlucHV0ID0gZGljdGlvbmFyeTsKICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICB3aGlsZSAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICBzdHIgPSBzLnN0cnN0YXJ0OwogICAgICAgICAgbiA9IHMubG9va2FoZWFkIC0gKE1JTl9NQVRDSCAtIDEpOwogICAgICAgICAgZG8gewogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbc3RyICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHN0cjsKICAgICAgICAgICAgc3RyKys7CiAgICAgICAgICB9IHdoaWxlICgtL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aGFyQ29kZUF0KG1fcG9zICsgMSk7CiAgICAgICAgICAgIGlmICgoYzIgJiA2NDUxMikgPT09IDU2MzIwKSB7CiAgICAgICAgICAgICAgYyA9IDY1NTM2ICsgKGMgLSA1NTI5NiA8PCAxMCkgKyAoYzIgLSA1NjMyMCk7CiAgICAgICAgICAgICAgbV9wb3MrKzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKGMgPCAxMjgpIHsKICAgICAgICAgICAgYnVmW2krK10gPSBjOwogICAgICAgICAgfSBlbHNlIGlmIChjIDwgMjA0OCkgewogICAgICAgICAgICBidWZbaSsrXSA9IDE5MiB8IGMgPj4+IDY7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyAmIDYzOwogICAgICAgICAgfSBlbHNlIGlmIChjIDwgNjU1MzYpIHsKICAgICAgICAgICAgYnVmW2krK10gPSAyMjQgfCBjID4+PiAxMjsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjID4+PiA2ICYgNjM7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyAmIDYzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgYnVmW2krK10gPSAyNDAgfCBjID4+PiAxODsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjID4+PiAxMiAmIDYzOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDYgJiA2MzsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGJ1ZjJiaW5zdHJpbmcoYnVmLCBsZW4pIHsKICAgICAgICBpZiAobGVuIDwgNjU1MzQpIHsKICAgICAgICAgIGlmIChidWYuc3ViYXJyYXkgJiYgU1RSX0FQUExZX1VJQV9PSyB8fCAhYnVmLnN1YmFycmF5ICYmIFNUUl9BUFBMWV9PSykgewogICAgICAgICAgICByZXR1cm4gU3RyaW5nLmZyb21DaGFyQ29kZS5hcHBseShudWxsLCB1dGlscy5zaHJpbmtCdWYoYnVmLCBsZW4pKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdmFyIHJlc3VsdCA9ICIiOwogICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICAgIHJlc3VsdCArPSBTdHJpbmcuZnJvbUNoYXJDb2RlKGJ1ZltpXSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgIH0KICAgICAgZXhwb3J0czIuYnVmMmJpbnN0cmluZyA9IGZ1bmN0aW9uKGJ1ZikgewogICAgICAgIHJldHVybiBidWYyYmluc3RyaW5nKGJ1ZiwgYnVmLmxlbmd0aCk7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLmJpbnN0cmluZzJidWYgPSBmdW5jdGlvbihzdHIpIHsKICAgICAgICB2YXIgYnVmID0gbmV3IHV0aWxzLkJ1Zjgoc3RyLmxlbmd0aCk7CiAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IGJ1Zi5sZW5ndGg7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgYnVmW2ldID0gc3RyLmNoYXJDb2RlQXQoaSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLmJ1ZjJzdHJpbmcgPSBmdW5jdGlvbihidWYsIG1heCkgewogICAgICAgIHZhciBpLCBvdXQsIGMsIGNfbGVuOwogICAgICAgIHZhciBsZW4gPSBtYXggfHwgYnVmLmxlbmd0aDsKICAgICAgICB2YXIgdXRmMTZidWYgPSBuZXcgQXJyYXkobGVuICogMik7CiAgICAgICAgZm9yIChvdXQgPSAwLCBpID0gMDsgaSA8IGxlbjsgKSB7CiAgICAgICAgICBjID0gYnVmW2krK107CiAgICAgICAgICBpZiAoYyA8IDEyOCkgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSBjOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGNfbGVuID0gX3V0ZjhsZW5bY107CiAgICAgICAgICBpZiAoY19sZW4gPiA0KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IDY1NTMzOwogICAgICAgICAgICBpICs9IGNfbGVuIC0gMTsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBjICY9IGNfbGVuID09PSAyID8gMzEgOiBjX2xlbiA9PT0gMyA/IDE1IDogNzsKICAgICAgICAgIHdoaWxlIChjX2xlbiA+IDEgJiYgaSA8IGxlbikgewogICAgICAgICAgICBjID0gYyA8PCA2IHwgYnVmW2krK10gJiA2MzsKICAgICAgICAgICAgY19sZW4tLTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChjX2xlbiA+IDEpIHsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNjU1MzM7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGMgPCA2NTUzNikgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSBjOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgYyAtPSA2NTUzNjsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNTUyOTYgfCBjID4+IDEwICYgMTAyMzsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNTYzMjAgfCBjICYgMTAyMzsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjJiaW5zdHJpbmcodXRmMTZidWYsIG91dCk7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLnV0Zjhib3JkZXIgPSBmdW5jdGlvbihidWYsIG1heCkgewogICAgICAgIHZhciBwb3M7CiAgICAgICAgbWF4ID0gbWF4IHx8IGJ1Zi5sZW5ndGg7CiAgICAgICAgaWYgKG1heCA+IGJ1Zi5sZW5ndGgpIHsKICAgICAgICAgIG1heCA9IGJ1Zi5sZW5ndGg7CiAgICAgICAgfQogICAgICAgIHBvcyA9IG1heCAtIDE7CiAgICAgICAgd2hpbGUgKHBvcyA+PSAwICYmIChidWZbcG9zXSAmIDE5MikgPT09IDEyOCkgewogICAgICAgICAgcG9zLS07CiAgICAgICAgfQogICAgICAgIGlmIChwb3MgPCAwKSB7CiAgICAgICAgICByZXR1cm4gbWF4OwogICAgICAgIH0KICAgICAgICBpZiAocG9zID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gbWF4OwogICAgICAgIH0KICAgICAgICByZXR1cm4gcG9zICsgX3V0ZjhsZW5bYnVmW3Bvc11dID4gbWF4ID8gcG9zIDogbWF4OwogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvenN0cmVhbS5qcwogIHZhciByZXF1aXJlX3pzdHJlYW0gPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvenN0cmVhbS5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIGZ1bmN0aW9uIFpTdHJlYW0oKSB7CiAgICAgICAgdGhpcy5pbnB1dCA9IG51bGw7CiAgICAgICAgdGhpcy5uZXh0X2luID0gMDsKICAgICAgICB0aGlzLmF2YWlsX2luID0gMDsKICAgICAgICB0aGlzLnRvdGFsX2luID0gMDsKICAgICAgICB0aGlzLm91dHB1dCA9IG51bGw7CiAgICAgICAgdGhpcy5uZXh0X291dCA9IDA7CiAgICAgICAgdGhpcy5hdmFpbF9vdXQgPSAwOwogICAgICAgIHRoaXMudG90YWxfb3V0ID0gMDsKICAgICAgICB0aGl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RFRkxBVEVEID0gODsKICAgICAgZnVuY3Rpb24gRGVmbGF0ZShvcHRpb25zKSB7CiAgICAgICAgaWYgKCEodGhpcyBpbnN0YW5jZW9mIERlZmxhdGUpKQogICAgICAgICAgcmV0dXJuIG5ldyBEZWZsYXRlKG9wdGlvbnMpOwogICAgICAgIHRoaXMub3B0aW9ucyA9IHV0aWxzLmFzc2lnbih7CiAgICAgICAgICBsZXZlbDogWl9ERUZBVUxUX0NPTVBSRVNTSU9OLAogICAgICAgICAgbWV0aG9kOiBaX0RFRkxBVEVELAogICAgICAgICAgY2h1bmtTaXplOiAxNjM4NCwKICAgICAgICAgIHdpbmRvd0JpdHM6IDE1LAogICAgICAgICAgbWVtTGV2ZWw6IDgsCiAgICAgICAgICBzdHJhdGVneTogWl9ERUZBVUxUX1NUUkFURUdZLAogICAgICAgICAgdG86ICIiCiAgICAgICAgfSwgb3B0aW9ucyB8fCB7fSk7CiAgICAgICAgdmFyIG9wdCA9IHRoaXMub3B0aW9uczsKICAgICAgICBpZiAob3B0LnJhdyAmJiBvcHQud2luZG93Qml0cyA+IDApIHsKICAgICAgICAgIG9wdC53aW5kb3dCaXRzID0gLW9wdC53aW5kb3dCaXRzOwogICAgICAgIH0gZWxzZSBpZiAob3B0Lmd6aXAgJiYgb3B0LndpbmRvd0JpdHMgPiAwICYmIG9wdC53aW5kb3dCaXRzIDwgMTYpIHsKICAgICAgICAgIG9wdC53aW5kb3dCaXRzICs9IDE2OwogICAgICAgIH0KICAgICAgICB0aGlzLmVyciA9IDA7CiAgICAgICAgdGhpcy5tc2cgPSAiIjsKICAgICAgICB0aGlzLmVuZGVkID0gZmFsc2U7CiAgICAgICAgdGhpcy5jaHVua3MgPSBbXTsKICAgICAgICB0aGlzLnN0cm0gPSBuZXcgWlN0cmVhbSgpOwogICAgICAgIHRoaXMuc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgIHZhciBzdGF0dXMgPSB6bGliX2RlZmxhdGUuZGVmbGF0ZUluaXQyKHRoaXMuc3RybSwgb3B0LmxldmVsLCBvcHQubWV0aG9kLCBvcHQud2luZG93Qml0cywgb3B0Lm1lbUxldmVsLCBvcHQuc3RyYXRlZ3kpOwogICAgICAgIGlmIChzdGF0dXMgIT09IFpfT0spIHsKICAgICAgICAgIHRocm93IG5ldyBFcnJvcihtc2dbc3RhdHVzXSk7CiAgICAgICAgfQogICAgICAgIGlmIChvcHQuaGVhZGVyKSB7CiAgICAgICAgICB6bGliX2RlZmxhdGUuZGVmbGF0ZVNldEhlYWRlcih0aGlzLnN0cm0sIG9wdC5oZWFkZXIpOwogICAgICAgIH0KICAgICAgICBpZiAob3B0LmRpY3Rpb25hcnkpIHsKICAgICAgICAgIHZhciBkaWN0OwogICAgICAgICAgaWYgKHR5cGVvZiBvcHQuZGljdGlvbmFyeSA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgZGljdCA9IHN0cmluZ3Muc3RyaW5nMmJ1ZihvcHQuZGljdGlvbmFyeSk7CiAgICAgICAgICB9IGVsc2UgaWYgKHRvU3RyaW5nLmNhbGwob3B0LmRpY3Rpb25hcnkpID09PSAiW29iamVjdCBBcnJheUJ1ZmZlcl0iKSB7CiAgICAgICAgICAgIGRpY3QgPSBuZXcgVWludDhBcnJheShvcHQuZGljdGlvbmFyeSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkaWN0ID0gb3B0LmRpY3Rpb25hcnk7CiAgICAgICAgICB9CiAgICAgICAgICBzdGF0dXMgPSB6bGliX2RlZmxhdGUuZGVmbGF0ZVNldERpY3Rpb25hcnkodGhpcy5zdHJtLCBkaWN0KTsKICAgICAgICAgIGlmIChzdGF0dXMgIT09IFpfT0spIHsKICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKG1zZ1tzdGF0dXNdKTsKICAgICAgICAgIH0KICAgICAgICAgIHRoaXMuX2RpY3Rfc2V0ID0gdHJ1ZTsKICAgICAgICB9CiAgICAgIH0KICAgICAgRGVmbGF0ZS5wcm90b3R5cGUucHVzaCA9IGZ1bmN0aW9uKGRhdGEsIG1vZGUpIHsKICAgICAgICB2YXIgc3RybSA9IHRoaXMuc3RybTsKICAgICAgICB2YXIgY2h1bmtTaXplID0gdGhpcy5vcHRpb25zLmNodW5rU2l6ZTsKICAgICAgICB2YXIgc3RhdHVzLCBfbW9kZTsKICAgICAgICBpZiAodGhpcy5lbmRlZCkgewogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgICBfbW9kZSA9IG1vZGUgPT09IH5+bW9kZSA/IG1vZGUgOiBtb2RlID09PSB0cnVlID8gWl9GSU5JU0ggOiBaX05PX0ZMVVNIOwogICAgICAgIGlmICh0eXBlb2YgZGF0YSA9PT0gInN0cmluZyIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBzdHJpbmdzLnN0cmluZzJidWYoZGF0YSk7CiAgICAgICAgfSBlbHNlIGlmICh0b1N0cmluZy5jYWxsKGRhdGEpID09PSAiW29iamVjdCBBcnJheUJ1ZmZlcl0iKSB7CiAgICAgICAgICBzdHJtLmlucHV0ID0gbmV3IFVpbnQ4QXJyYXkoZGF0YSk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBkYXRhOwogICAgICAgIH0KICAgICAgICBzdHJtLm5leHRfaW4gPSAwOwogICAgICAgIHN0cm0uYXZhaWxfaW4gPSBzdHJtLmlucHV0Lmxlbmd0aDsKICAgICAgICBkbyB7CiAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgc3RybS5vdXRwdXQgPSBuZXcgdXRpbHMuQnVmOChjaHVua1NpemUpOwogICAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gMDsKICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBjaHVua1NpemU7CiAgICAgICAgICB9CiAgICAgICAgICBzdGF0dXMgPSB6bGliX2RlZmxhdGUuZGVmbGF0ZShzdHJtLCBfbW9kZSk7CiAgICAgICAgICBpZiAoc3RhdHVzICE9PSBaX1NUUkVBTV9FTkQgJiYgc3RhdHVzICE9PSBaX09LKSB7CiAgICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgICAgdGhpcy5lbmRlZCA9IHRydWU7CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCB8fCBzdHJtLmF2YWlsX2luID09PSAwICYmIChfbW9kZSA9PT0gWl9GSU5JU0ggfHwgX21vZGUgPT09IFpfU1lOQ19GTFVTSDIpKSB7CiAgICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgICAgdGhpcy5vbkRhdGEoc3RyaW5ncy5idWYyYmluc3RyaW5nKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICB0aGlzLm9uRGF0YSh1dGlscy5zaHJpbmtCdWYoc3RybS5vdXRwdXQsIHN0cm0ubmV4dF9vdXQpKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKChzdHJtLmF2YWlsX2luID4gMCB8fCBzdHJtLmF2YWlsX291dCA9PT0gMCkgJiYgc3RhdHVzICE9PSBaX1NUUkVBTV9FTkQpOwogICAgICAgIGlmIChfbW9kZSA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlRW5kKHRoaXMuc3RybSk7CiAgICAgICAgICB0aGlzLm9uRW5kKHN0YXR1cyk7CiAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgIHJldHVybiBzdGF0dXMgPT09IFpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChfbW9kZSA9PT0gWl9TWU5DX0ZMVVNIMikgewogICAgICAgICAgdGhpcy5vbkVuZChaX09LKTsKICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gMDsKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgfTsKICAgICAgRGVmbGF0ZS5wcm90b3R5cGUub25EYXRhID0gZnVuY3Rpb24oY2h1bmspIHsKICAgICAgICB0aGlzLmNodW5rcy5wdXNoKGNodW5rKTsKICAgICAgfTsKICAgICAgRGVmbGF0ZS5wcm90b3R5cGUub25FbmQgPSBmdW5jdGlvbihzdGF0dXMpIHsKICAgICAgICBpZiAoc3RhdHVzID09PSBaX09LKSB7CiAgICAgICAgICBpZiAodGhpcy5vcHRpb25zLnRvID09PSAic3RyaW5nIikgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHRoaXMuY2h1bmtzLmpvaW4oIiIpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdGhpcy5yZXN1bHQgPSB1dGlscy5mbGF0dGVuQ2h1bmtzKHRoaXMuY2h1bmtzKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdGhpcy5jaHVua3MgPSBbXTsKICAgICAgICB0aGlzLmVyciA9IHN0YXR1czsKICAgICAgICB0aGlzLm1zZyA9IHRoaXMuc3RybS5tc2c7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGUoaW5wdXQsIG9wdGlvbnMpIHsKICAgICAgICB2YXIgZGVmbGF0b3IgPSBuZXcgRGVmbGF0ZShvcHRpb25zKTsKICAgICAgICBkZWZsYXRvci5wdXNoKGlucHV0LCB0cnVlKTsKICAgICAgICBpZiAoZGVmbGF0b3IuZXJyKSB7CiAgICAgICAgICB0aHJvdyBkZWZsYXRvci5tc2cgfHwgbXNnW2RlZmxhdG9yLmVycl07CiAgICAgICAgfQogICAgICAgIHJldHVybiBkZWZsYXRvci5yZXN1bHQ7CiAgICAgIH0KICAgICAgZnVuY3Rp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AgICAgICAgdmFyIGxhc3Q7CiAgICAgICAgdmFyIF9vdXQ7CiAgICAgICAgdmFyIGJlZzsKICAgICAgICB2YXIgZW5kOwogICAgICAgIHZhciBkbWF4OwogICAgICAgIHZhciB3c2l6ZTsKICAgICAgICB2YXIgd2hhdmU7CiAgICAgICAgdmFyIHduZXh0OwogICAgICAgIHZhciBzX3dpbmRvdzsKICAgICAgICB2YXIgaG9sZDsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgbGNvZGU7CiAgICAgICAgdmFyIGRjb2RlOwogICAgICAgIHZhciBsbWFzazsKICAgICAgICB2YXIgZG1hc2s7CiAgICAgICAgdmFyIGhlcmU7CiAgICAgICAgdmFyIG9wOwogICAgICAgIHZhciBsZW47CiAgICAgICAgdmFyIGRpc3Q7CiAgICAgICAgdmFyIGZyb207CiAgICAgICAgdmFyIGZyb21fc291cmNlOwogICAgICAgIHZhciBpbnB1dCwgb3V0cHV0OwogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBfaW4gPSBzdHJtLm5leHRfaW47CiAgICAgICAgaW5wdXQgPSBzdHJtLmlucHV0OwogICAgICAgIGxhc3QgPSBfaW4gKyAoc3RybS5hdmFpbF9pbiAtIDUpOwogICAgICAgIF9vdXQgPSBzdHJtLm5leHRfb3V0OwogICAgICAgIG91dHB1dCA9IHN0cm0ub3V0cHV0OwogICAgICAgIGJlZyA9IF9vdXQgLSAoc3RhcnQgLSBzdHJtLmF2YWlsX291dCk7CiAgICAgICAgZW5kID0gX291dCArIChzdHJtLmF2YWlsX291dCAtIDI1Nyk7CiAgICAgICAgZG1heCA9IHN0YXRlLmRtYXg7CiAgICAgICAgd3NpemUgPSBzdGF0ZS53c2l6ZTsKICAgICAgICB3aGF2ZSA9IHN0YXRlLndoYXZlOwogICAgICAgIHduZXh0ID0gc3RhdGUud25leHQ7CiAgICAgICAgc193aW5kb3cgPSBzdGF0ZS53aW5kb3c7CiAgICAgICAgaG9sZCA9IHN0YXRlLmhvbGQ7CiAgICAgICAgYml0cyA9IHN0YXRlLmJpdHM7CiAgICAgICAgbGNvZGUgPSBzdGF0ZS5sZW5jb2RlOwogICAgICAgIGRjb2RlID0gc3RhdGUuZGlzdGNvZGU7CiAgICAgICAgbG1hc2sgPSAoMSA8PCBzdGF0ZS5sZW5iaXRzKSAtIDE7CiAgICAgICAgZG1hc2sgPSAoMSA8PCBzdGF0ZS5kaXN0Yml0cykgLSAxOwogICAgICAgIHRvcDoKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgaWYgKGJpdHMgPCAxNSkgewogICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICB9CiAgICAgICAgICAgIGhlcmUgPSBsY29kZVtob2xkICYgbG1hc2tdOwogICAgICAgICAgICBkb2xlbjoKICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgIGlmIChvcCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAob3AgJiAxNikgewogICAgICAgICAgICAgICAgICBsZW4gPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICAgIG9wICY9IDE1OwogICAgICAgICAgICAgICAgICBpZiAob3ApIHsKICAgICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBsZW4gKz0gaG9sZCAmICgxIDw8IG9wKSAtIDE7CiAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCAxNSkgewogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhlcmUgPSBkY29kZVtob2xkICYgZG1hc2tdOwogICAgICAgICAgICAgICAgICBkb2Rpc3Q6CiAgICAgICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgJiAxNikgewogICAgICAgICAgICAgICAgICAgICAgICBkaXN0ID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgICAgICBvcCAmPSAxNTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGRpc3QgKz0gaG9sZCAmICgxIDw8IG9wKSAtIDE7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkaXN0ID4gZG1heCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgdG9vIGZhciBiYWNrIjsKICAgICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgIG9wID0gX291dCAtIGJlZzsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGRpc3QgPiBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIG9wID0gZGlzdCAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA+IHdoYXZlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuc2FuZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IDA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBzX3dpbmRvdzsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAod25leHQgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gKz0gd3NpemUgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAod25leHQgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSArPSB3c2l6ZSArIHduZXh0IC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvcCAtPSB3bmV4dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHduZXh0IDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3AgPSB3bmV4dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tICs9IHduZXh0IC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGxlbiA+IDIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSAzOwogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuID4gMSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gMzsKICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlIChsZW4gPiAyKTsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbiA+IDEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoKG9wICYgNjQpID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGhlcmUgPSBkY29kZVsoaGVyZSAmIDY1NTM1KSArIChob2xkICYgKDEgPDwgb3ApIC0gMSldOwogICAgICAgICAgICAgICAgICAgICAgICBjb250aW51ZSBkb2Rpc3Q7CiAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIGNvZGUiOwogICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKChvcCAmIDY0KSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBoZXJlID0gbGNvZGVbKGhlcmUgJiA2NTUzNSkgKyAoaG9sZCAmICgxIDw8IG9wKSAtIDEpXTsKICAgICAgICAgICAgICAgICAgY29udGludWUgZG9sZW47CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKG9wICYgMzIpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRZUEU7CiAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgbGl0ZXJhbC9sZW5ndGggY29kZSI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgIH0gd2hpbGUgKF9pbiA8IGxhc3QgJiYgX291dCA8IGVuZCk7CiAgICAgICAgbGVuID0gYml0cyA+PiAzOwogICAgICAgIF9pbiAtPSBsZW47CiAgICAgICAgYml0cyAtPSBsZW4gPDwgMzsKICAgICAgICBob2xkICY9ICgxIDw8IGJpdHMpIC0gMTsKICAgICAgICBzdHJtLm5leHRfaW4gPSBfaW47CiAgICAgICAgc3RybS5uZXh0X291dCA9IF9vdXQ7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IF9pbiA8IGxhc3QgPyA1ICsgKGxhc3QgLSBfaW4pIDogNSAtIChfaW4gLSBsYXN0KTsKICAgICAgICBzdHJtLmF2YWlsX291dCA9IF9vdXQgPCBlbmQgPyAyNTcgKyAoZW5kIC0gX291dCkgOiAyNTcgLSAoX291dCAtIGVuZCk7CiAgICAgICAgc3RhdGUuaG9sZCA9IGhvbGQ7CiAgICAgICAgc3RhdGUuYml0cyA9IGJpdHM7CiAgICAgICAgcmV0dXJuOwogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mdHJlZXMuanMKICB2YXIgcmVxdWlyZV9pbmZ0cmVlcyA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9pbmZ0cmVlcy5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIHZhciB1dGlscyA9IHJlcXVpcmVfY29tbW9uKCk7CiAgICAgIHZhciBNQVhCSVRTID0gMTU7CiAgICAgIHZhciBFTk9VR0hfTEVOUyA9IDg1MjsKICAgICAgdmFyIEVOT1VHSF9ESVNUUyA9IDU5MjsKICAgICAgdmFyIENPREVTID0gMDsKICAgICAgdmFyIExFTlMgPSAxOwogICAgICB2YXIgRElTVFMgPSAyOwogICAgICB2YXIgbGJhc2UgPSBbCiAgICAgICAgMywKICAgICAgICA0LAogICAgICAgIDUsCiAgICAgICAgNiwKICAgICAgICA3LAogICAgICAgIDgsCiAgICAgICAgOSwKICAgICAgICAxMCwKICAgICAgICAxMSwKICAgICAgICAxMywKICAgICAgICAxNSwKICAgICAgICAxNywKICAgICAgICAxOSwKICAgICAgICAyMywKICAgICAgICAyNywKICAgICAgICAzMSwKICAgICAgICAzNSwKICAgICAgICA0MywKICAgICAgICA1MSwKICAgICAgICA1OSwKICAgICAgICA2NywKICAgICAgICA4MywKICAgICAgICA5OSwKICAgICAgICAxMTUsCiAgICAgICAgMTMxLAogICAgICAgIDE2MywKICAgICAgICAxOTUsCiAgICAgICAgMjI3LAogICAgICAgIDI1OCwKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGxleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMTYsCiAgICAgICAgNzIsCiAgICAgICAgNzgKICAgICAgXTsKICAgICAgdmFyIGRiYXNlID0gWwogICAgICAgIDEsCiAgICAgICAgMiwKICAgICAgICAzLAogICAgICAgIDQsCiAgICAgICAgNSwKICAgICAgICA3LAogICAgICAgIDksCiAgICAgICAgMTMsCiAgICAgICAgMTcsCiAgICAgICAgMjUsCiAgICAgICAgMzMsCiAgICAgICAgNDksCiAgICAgICAgNjUsCiAgICAgICAgOTcsCiAgICAgICAgMTI5LAogICAgICAgIDE5MywKICAgICAgICAyNTcsCiAgICAgICAgMzg1LAogICAgICAgIDUxMywKICAgICAgICA3NjksCiAgICAgICAgMTAyNSwKICAgICAgICAxNTM3LAogICAgICAgIDIwNDksCiAgICAgICAgMzA3MywKICAgICAgICA0MDk3LAogICAgICAgIDYxNDUsCiAgICAgICAgODE5MywKICAgICAgICAxMjI4OSwKICAgICAgICAxNjM4NSwKICAgICAgICAyNDU3NywKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGRleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjIsCiAgICAgICAgMjIsCiAgICAgICAgMjMsCiAgICAgICAgMjMsCiAgICAgICAgMjQsCiAgICAgICAgMjQsCiAgICAgICAgMjUsCiAgICAgICAgMjUsCiAgICAgICAgMjYsCiAgICAgICAgMjYsCiAgICAgICAgMjcsCiAgICAgICAgMjcsCiAgICAgICAgMjgsCiAgICAgICAgMjgsCiAgICAgICAgMjksCiAgICAgICAgMjksCiAgICAgICAgNjQsCiAgICAgICAgNjQKICAgICAgXTsKICAgICAgbW9kdWxlMi5leHBvcnRzID0gZnVuY3Rpb24gaW5mbGF0ZV90YWJsZSh0eXBlLCBsZW5zLCBsZW5zX2luZGV4LCBjb2RlcywgdGFibGUsIHRhYmxlX2luZGV4LCB3b3JrLCBvcHRzKSB7CiAgICAgICAgdmFyIGJpdHMgPSBvcHRzLmJpdHM7CiAgICAgICAgdmFyIGxlbiA9IDA7CiAgICAgICAgdmFyIHN5bSA9IDA7CiAgICAgICAgdmFyIG1pbiA9IDAsIG1heCA9IDA7CiAgICAgICAgdmFyIHJvb3QyID0gMDsKICAgICAgICB2YXIgY3VyciA9IDA7CiAgICAgICAgdmFyIGRyb3AgPSAwOwogICAgICAgIHZhciBsZWZ0ID0gMDsKICAgICAgICB2YXIgdXNlZCA9IDA7CiAgICAgICAgdmFyIGh1ZmYgPSAwOwogICAgICAgIHZhciBpbmNyOwogICAgICAgIHZhciBmaWxsOwogICAgICAgIHZhciBsb3c7CiAgICAgICAgdmFyIG1hc2s7CiAgICAgICAgdmFyIG5leHQ7CiAgICAgICAgdmFyIGJhc2UgPSBudWxsOwogICAgICAgIHZhciBiYXNlX2luZGV4ID0gMDsKICAgICAgICB2YXIgZW5kOwogICAgICAgIHZhciBjb3VudCA9IG5ldyB1dGlscy5CdWYxNihNQVhCSVRTICsgMSk7CiAgICAgICAgdmFyIG9mZnMgPSBuZXcgdXRpbHMuQnVmMTYoTUFYQklUUyArIDEpOwogICAgICAgIHZhciBleHRyYSA9IG51bGw7CiAgICAgICAgdmFyIGV4dHJhX2luZGV4ID0gMDsKICAgICAgICB2YXIgaGVyZV9iaXRzLCBoZXJlX29wLCBoZXJlX3ZhbDsKICAgICAgICBmb3IgKGxlbiA9IDA7IGxlbiA8PSBNQVhCSVRTOyBsZW4rKykgewogICAgICAgICAgY291bnRbbGVuXSA9IDA7CiAgICAgICAgfQogICAgICAgIGZvciAoc3ltID0gMDsgc3ltIDwgY29kZXM7IHN5bSsrKSB7CiAgICAgICAgICBjb3VudFtsZW5zW2xlbnNfaW5kZXggKyBzeW1dXSsrOwogICAgICAgIH0KICAgICAgICByb290MiA9IGJpdHM7CiAgICAgICAgZm9yIChtYXggPSBNQVhCSVRTOyBtYXggPj0gMTsgbWF4LS0pIHsKICAgICAgICAgIGlmIChjb3VudFttYXhdICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocm9vdDIgPiBtYXgpIHsKICAgICAgICAgIHJvb3QyID0gbWF4OwogICAgICAgIH0KICAgICAgICBpZiAobWF4ID09PSAwKSB7CiAgICAgICAgICB0YWJsZVt0YWJsZV9pbmRleCsrXSA9IDEgPDwgMjQgfCA2NCA8PCAxNiB8IDA7CiAgICAgICAgICB0YWJsZVt0YWJsZV9pbmRleCsrXSA9IDEgPDwgMjQgfCA2NCA8PCAxNiB8IDA7CiAgICAgICAgICBvcHRzLmJpdHMgPSAxOwogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfQogICAgICAgIGZvciAobWluID0gMTsgbWluIDwgbWF4OyBtaW4rKykgewogICAgICAgICAgaWYgKGNvdW50W21pbl0gIT09IDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChyb290MiA8IG1pbikgewogICAgICAgICAgcm9vdDIgPSBtaW47CiAgICAgICAgfQogICAgICAgIGxlZnQgPSAxOwogICAgICAgIGZvciAobGVuID0gMTsgbGVuIDw9IE1BWEJJVFM7IGxlbisrKSB7CiAgICAgICAgICBsZWZ0IDw8PSAxOwogICAgICAgICAgbGVmdCAtPSBjb3VudFtsZW5dOwogICAgICAgICAgaWYgKGxlZnQgPCAwKSB7CiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGxlZnQgPiAwICYmICh0eXBlID09PSBDT0RFUyB8fCBtYXggIT09IDEpKSB7CiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgfQogICAgICAgIG9mZnNbMV0gPSAwOwogICAgICAgIGZvciAobGVuID0gMTsgbGVuIDwgTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIG9mZnNbbGVuICsgMV0gPSBvZmZzW2xlbl0gKyBjb3VudFtsZW5dOwogICAgICAgIH0KICAgICAgICBmb3IgKHN5bSA9IDA7IHN5bSA8IGNvZGVzOyBzeW0rKykgewogICAgICAgICAgaWYgKGxlbnNbbGVuc19pbmRleCArIHN5bV0gIT09IDApIHsKICAgICAgICAgICAgd29ya1tvZmZzW2xlbnNbbGVuc19pbmRleCArIHN5bV1dKytdID0gc3ltOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAodHlwZSA9PT0gQ09ERVMpIHsKICAgICAgICAgIGJhc2UgPSBleHRyYSA9IHdvcms7CiAgICAgICAgICBlbmQgPSAxOTsKICAgICAgICB9IGVsc2UgaWYgKHR5cGUgPT09IExFTlMpIHsKICAgICAgICAgIGJhc2UgPSBsYmFzZTsKICAgICAgICAgIGJhc2VfaW5kZXggLT0gMjU3OwogICAgICAgICAgZXh0cmEgPSBsZXh0OwogICAgICAgICAgZXh0cmFfaW5kZXggLT0gMjU3OwogICAgICAgICAgZW5kID0gMjU2OwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBiYXNlID0gZGJhc2U7CiAgICAgICAgICBleHRyYSA9IGRleHQ7CiAgICAgICAgICBlbmQgPSAtMTsKICAgICAgICB9CiAgICAgICAgaHVmZiA9IDA7CiAgICAgICAgc3ltID0gMDsKICAgICAgICBsZW4gPSBtaW47CiAgICAgICAgbmV4dCA9IHRhYmxlX2luZGV4OwogICAgICAgIGN1cnIgPSByb290MjsKICAgICAgICBkcm9wID0gMDsKICAgICAgICBsb3cgPSAtMTsKICAgICAgICB1c2VkID0gMSA8PCByb290MjsKICAgICAgICBtYXNrID0gdXNlZCAtIDE7CiAgICAgICAgaWYgKHR5cGUgPT09IExFTlMgJiYgdXNlZCA+IEVOT1VHSF9MRU5TIHx8IHR5cGUgPT09IERJU1RTICYmIHVzZWQgPiBFTk9VR0hfRElTVFMpIHsKICAgICAgICAgIHJldHVybiAxOwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGhlcmVfYml0cyA9IGxlbiAtIGRyb3A7CiAgICAgICAgICBpZiAod29ya1tzeW1dIDwgZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAwOwogICAgICAgICAgICBoZXJlX3ZhbCA9IHdvcmtbc3ltXTsKICAgICAgICAgIH0gZWxzZSBpZiAod29ya1tzeW1dID4gZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSBleHRyYVtleHRyYV9pbmRleCArIHdvcmtbc3ltXV07CiAgICAgICAgICAgIGhlcmVfdmFsID0gYmFzZVtiYXNlX2luZGV4ICsgd29ya1tzeW1dXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAzMiArIDY0OwogICAgICAgICAgICBoZXJlX3ZhbCA9IDA7CiAgICAgICAgICB9CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSBkcm9wOwogICAgICAgICAgZmlsbCA9IDEgPDwgY3VycjsKICAgICAgICAgIG1pbiA9IGZpbGw7CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGZpbGwgLT0gaW5jcjsKICAgICAgICAgICAgdGFibGVbbmV4dCArIChodWZmID4+IGRyb3ApICsgZmlsbF0gPSBoZXJlX2JpdHMgPDwgMjQgfCBoZXJlX29wIDw8IDE2IHwgaGVyZV92YWwgfCAwOwogICAgICAgICAgfSB3aGlsZSAoZmlsbCAhPT0gMCk7CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSAxOwogICAgICAgICAgd2hpbGUgKGh1ZmYgJiBpbmNyKSB7CiAgICAgICAgICAgIGluY3IgPj49IDE7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaW5jciAhPT0gMCkgewogICAgICAgICAgICBodWZmICY9IGluY3IgLSAxOwogICAgICAgICAgICBodWZmICs9IGluY3I7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBodWZmID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHN5bSsrOwogICAgICAgICAgaWYgKC0tY291bnRbbGVuXSA9PT0gMCkgewogICAgICAgICAgICBpZiAobGVuID09PSBtYXgpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBsZW4gPSBsZW5zW2xlbnNfaW5kZXggKyB3b3JrW3N5bV1dOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGxlbiA+IHJvb3QyICYmIChodWZmICYgbWFzaykgIT09IGxvdykgewogICAgICAgICAgICBpZiAoZHJvcCA9PT0gMCkgewogICAgICAgICAgICAgIGRyb3AgPSByb290MjsKICAgICAgICAgICAgfQogICAgICAgICAgICBuZXh0ICs9IG1pbjsKICAgICAgICAgICAgY3VyciA9IGxlbiAtIGRyb3A7CiAgICAgICAgICAgIGxlZnQgPSAxIDw8IGN1cnI7CiAgICAgICAgICAgIHdoaWxlIChjdXJyICsgZHJvcCA8IG1heCkgewogICAgICAgICAgICAgIGxlZnQgLT0gY291bnRbY3VyciArIGRyb3BdOwogICAgICAgICAgICAgIGlmIChsZWZ0IDw9IDApIHsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBjdXJyKys7CiAgICAgICAgICAgICAgbGVmdCA8PD0gMTsKICAgICAgICAgICAgfQogICAgICAgICAgICB1c2VkICs9IDEgPDwgY3VycjsKICAgICAgICAgICAgaWYgKHR5cGUgPT09IExFTlMgJiYgdXNlZCA+IEVOT1VHSF9MRU5TIHx8IHR5cGUgPT09IERJU1RTICYmIHVzZWQgPiBFTk9VR0hfRElTVFMpIHsKICAgICAgICAgICAgICByZXR1cm4gMTsKICAgICAgICAgICAgfQogICAgICAgICAgICBsb3cgPSBodWZmICYgbWFzazsKICAgICAgICAgICAgdGFibGVbbG93XSA9IHJvb3QyIDw8IDI0IHwgY3VyciA8PCAxNiB8IG5leHQgLSB0YWJsZV9pbmRleCB8IDA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChodWZmICE9PSAwKSB7CiAgICAgICAgICB0YWJsZVtuZXh0ICsgaHVmZl0gPSBsZW4gLSBkcm9wIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgIH0KICAgICAgICBvcHRzLmJpdHMgPSByb290MjsKICAgICAgICByZXR1cm4gMDsKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZmxhdGUuanMKICB2YXIgcmVxdWlyZV9pbmZsYXRlID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZmxhdGUuanMiKGV4cG9ydHMyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgdXRpbHMgPSByZXF1aXJlX2NvbW1vbigpOwogICAgICB2YXIgYWRsZXIzMiA9IHJlcXVpcmVfYWRsZXIzMigpOwogICAgICB2YXIgY3JjMzIgPSByZXF1aXJlX2NyYzMyKCk7CiAgICAgIHZhciBpbmZsYXRlX2Zhc3QgPSByZXF1aXJlX2luZmZhc3QoKTsKICAgICAgdmFyIGluZmxhdGVfdGFibGUgPSByZXF1aXJlX2luZnRyZWVzKCk7CiAgICAgIHZhciBDT0RFUyA9IDA7CiAgICAgIHZhciBMRU5TID0gMTsKICAgICAgdmFyIERJU1RTID0gMjsKICAgICAgdmFyIFpfRklOSVNIID0gNDsKICAgICAgdmFyIFpfQkxPQ0sgPSA1OwogICAgICB2YXIgWl9UUkVFUyA9IDY7CiAgICAgIHZhciBaX09LID0gMDsKICAgICAgdmFyIFpfU1RSRUFNX0VORCA9IDE7CiAgICAgIHZhciBaX05FRURfRElDVCA9IDI7CiAgICAgIHZhciBaX1NUUkVBTV9FUlJPUiA9IC0yOwogICAgICB2YXIgWl9EQVRBX0VSUk9SID0gLTM7CiAgICAgIHZhciBaX01FTV9FUlJPUiA9IC00OwogICAgICB2YXIgWl9CVUZfRVJST1IgPSAtNTsKICAgICAgdmFyIFpfREVGTEFURUQgPSA4OwogICAgICB2YXIgSEVBRCA9IDE7CiAgICAgIHZhciBGTEFHUyA9IDI7CiAgICAgIHZhciBUSU1FID0gMzsKICAgICAgdmFyIE9TID0gNDsKICAgICAgdmFyIEVYTEVOID0gNTsKICAgICAgdmFyIEVYVFJBID0gNjsKICAgICAgdmFyIE5BTUUgPSA3OwogICAgICB2YXIgQ09NTUVOVCA9IDg7CiAgICAgIHZhciBIQ1JDID0gOTsKICAgICAgdmFyIERJQ1RJRCA9IDEwOwogICAgICB2YXIgRElDVCA9IDExOwogICAgICB2YXIgVFlQRSA9IDEyOwogICAgICB2YXIgVFlQRURPID0gMTM7CiAgICAgIHZhciBTVE9SRUQgPSAxNDsKICAgICAgdmFyIENPUFlfID0gMTU7CiAgICAgIHZhciBDT1BZID0gMTY7CiAgICAgIHZhciBUQUJMRSA9IDE3OwogICAgICB2YXIgTEVOTEVOUyA9IDE4OwogICAgICB2YXIgQ09ERUxFTlMgPSAxOTsKICAgICAgdmFyIExFTl8gPSAyMDsKICAgICAgdmFyIExFTiA9IDIxOwogICAgICB2YXIgTEVORVhUID0gMjI7CiAgICAgIHZhciBESVNUID0gMjM7CiAgICAgIHZhciBESVNURVhUID0gMjQ7CiAgICAgIHZhciBNQVRDSCA9IDI1OwogICAgICB2YXIgTElUID0gMjY7CiAgICAgIHZhciBDSEVDSyA9IDI3OwogICAgICB2YXIgTEVOR1RIID0gMjg7CiAgICAgIHZhciBET05FID0gMjk7CiAgICAgIHZhciBCQUQgPSAzMDsKICAgICAgdmFyIE1FTSA9IDMxOwogICAgICB2YXIgU1lOQyA9IDMyOwogICAgICB2YXIgRU5PVUdIX0xFTlMgPSA4NTI7CiAgICAgIHZhciBFTk9VR0hfRElTVFMgPSA1OTI7CiAgICAgIHZhciBNQVhfV0JJVFMgPSAxNTsKICAgICAgdmFyIERFRl9XQklUUyA9IE1BWF9XQklUUzsKICAgICAgZnVuY3Rpb24genN3YXAzMihxKSB7CiAgICAgICAgcmV0dXJuIChxID4+PiAyNCAmIDI1NSkgKyAocSA+Pj4gOCAmIDY1MjgwKSArICgocSAmIDY1MjgwKSA8PCA4KSArICgocSAmIDI1NSkgPDwgMjQpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIEluZmxhdGVTdGF0ZSgpIHsKICAgICAgICB0aGlzLm1vZGUgPSAwOwogICAgICAgIHRoaXMubGFzdCA9IGZhbHNlOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5oYXZlZGljdCA9IGZhbHNlOwogICAgICAgIHRoaXMuZmxhZ3MgPSAwOwogICAgICAgIHRoaXMuZG1heCA9IDA7CiAgICAgICAgdGhpcy5jaGVjayA9IDA7CiAgICAgICAgdGhpcy50b3RhbCA9IDA7CiAgICAgICAgdGhpcy5oZWFkID0gbnVsbDsKICAgICAgICB0aGlzLndiaXRzID0gMDsKICAgICAgICB0aGlzLndzaXplID0gMDsKICAgICAgICB0aGlzLndoYXZlID0gMDsKICAgICAgICB0aGlzLnduZXh0ID0gMDsKICAgICAgICB0aGlzLndpbmRvdyA9IG51bGw7CiAgICAgICAgdGhpcy5ob2xkID0gMDsKICAgICAgICB0aGlzLmJpdHMgPSAwOwogICAgICAgIHRoaXMubGVuZ3RoID0gMDsKICAgICAgICB0aGlzLm9mZnNldCA9IDA7CiAgICAgICAgdGhpcy5leHRyYSA9IDA7CiAgICAgICAgdGhpcy5sZW5jb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmRpc3Rjb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmxlbmJpdHMgPSAwOwogICAgICAgIHRoaXMuZGlzdGJpdHMgPSAwOwogICAgICAgIHRoaXMubmNvZGUgPSAwOwogICAgICAgIHRoaXMubmxlbiA9IDA7CiAgICAgICAgdGhpcy5uZGlzdCA9IDA7CiAgICAgICAgdGhpcy5oYXZlID0gMDsKICAgICAgICB0aGlzLm5leHQgPSBudWxsOwogICAgICAgIHRoaXMubGVucyA9IG5ldyB1dGlscy5CdWYxNigzMjApOwogICAgICAgIHRoaXMud29yayA9IG5ldyB1dGlscy5CdWYxNigyODgpOwogICAgICAgIHRoaXMubGVuZHluID0gbnVsbDsKICAgICAgICB0aGlzLmRpc3RkeW4gPSBudWxsOwogICAgICAgIHRoaXMuc2FuZSA9IDA7CiAgICAgICAgdGhpcy5iYWNrID0gMDsKICAgICAgICB0aGlzLndhcyA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZVJlc2V0S2VlcChzdHJtKSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgc3RybS50b3RhbF9pbiA9IHN0cm0udG90YWxfb3V0ID0gc3RhdGUudG90YWwgPSAwOwogICAgICAgIHN0cm0ubXNnID0gIiI7CiAgICAgICAgaWYgKHN0YXRlLndyYXApIHsKICA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FzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAod2luZG93Qml0cyA8IDApIHsKICAgICAgICAgIHdyYXAgPSAwOwogICAgICAgICAgd2luZG93Qml0cyA9IC13aW5kb3dCaXRzOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB3cmFwID0gKHdpbmRvd0JpdHMgPj4gNCkgKyAxOwogICAgICAgICAgaWYgKHdpbmRvd0JpdHMgPCA0OCkgewogICAgICAgICAgICB3aW5kb3dCaXRzICY9IDE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyAmJiAod2luZG93Qml0cyA8IDggfHwgd2luZG93Qml0cyA+IDE1KSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhdGUud2luZG93ICE9PSBudWxsICYmIHN0YXRlLndiaXRzICE9PSB3aW5kb3dCaXRzKSB7CiAgICAgICAgICBzdGF0ZS53aW5kb3cgPSBudWxsOwogICAgICAgIH0KICAgICAgICBzdGF0ZS53cmFwID0gd3JhcDsKICAgICAgICBzdGF0ZS53Yml0cyA9IHdpbmRvd0JpdHM7CiAgICAgICAgcmV0dXJuIGluZmxhdGVSZXNldChzdHJtKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlSW5pdDIoc3RybSwgd2luZG93Qml0cykgewogICAgICAgIHZhciByZXQ7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIGlmICghc3RybSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IG5ldyBJbmZsYXRlU3RhdGUoKTsKICAgICAgICBzdHJtLnN0YXRlID0gc3RhdGU7CiAgICAgICAgc3RhdGUud2luZG93ID0gbnVsbDsKICAgICAgICByZXQgPSBpbmZsYXRlUmVzZXQyKHN0cm0sIHdpbmRvd0JpdHMpOwogICAgICAgIGlmIChyZXQgIT09IFpfT0spIHsKICAgICAgICAgIHN0cm0uc3RhdGUgPSBudWxsOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmV0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVJbml0KHN0cm0pIHsKICAgICAgICByZXR1cm4gaW5mbGF0ZUluaXQyKHN0cm0sIERFRl9XQklUUyk7CiAgICAgIH0KICAgICAgdmFyIHZpcmdpbiA9IHRydWU7CiAgICAgIHZhciBsZW5maXg7CiAgICAgIHZhciBkaXN0Zml4OwogICAgICBmdW5jdGlvbiBmaXhlZHRhYmxlcyhzdGF0ZSkgewogICAgICAgIGlmICh2aXJnaW4pIHsKICAgICAgICAgIHZhciBzeW07CiAgICAgICAgICBsZW5maXggPSBuZXcgdXRpbHMuQnVmMzIoNTEyKTsKICAgICAgICAgIGRpc3RmaXggPSBuZXcgdXRpbHMuQnVmMzIoMzIpOwogICAgICAgICAgc3ltID0gMDsKICAgICAgICAgIHdoaWxlIChzeW0gPCAxNDQpIHsKICAgICAgICAgICAgc3RhdGUubGVuc1tzeW0rK10gPSA4OwogICAgICAgICAgfQogICAgICAgICAgd2hpbGUgKHN5bSA8IDI1NikgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDk7CiAgICAgICAgICB9CiAgICAgICAgICB3aGlsZSAoc3ltIDwgMjgwKSB7CiAgICAgICAgICAgIHN0YXRlLmxlbnNbc3ltKytdID0gNzsKICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzeW0gPCAyODgpIHsKICAgICAgICAgICAgc3RhdGUubGVuc1tzeW0rK10gPSA4OwogICAgICAgICAgfQogICAgICAgICAgaW5mbGF0ZV90YWJsZShMRU5TLCBzdGF0ZS5sZW5zLCAwLCAyODgsIGxlbmZpeCwgMCwgc3RhdGUud29yaywgeyBiaXRzOiA5IH0pOwogICAgICAgICAgc3ltID0gMDsKICAgICAgICAgIHdoaWxlIChzeW0gPCAzMikgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDU7CiAgICAgICAgICB9CiAgICAgICAgICBpbmZsYXRlX3RhYmxlKERJU1RTLCBzdGF0ZS5sZW5zLCAwLCAzMiwgZGlzdGZpeCwgMCwgc3RhdGUud29yaywgeyBiaXRzOiA1IH0pOwogICAgICAgICAgdmlyZ2luID0gZmFsc2U7CiAgICAgICAgfQogICAgICAgIHN0YXRlLmxlbmNvZGUgPSBsZW5maXg7CiAgICAgICAgc3RhdGUubGVuYml0cyA9IDk7CiAgICAgICAgc3RhdGUuZGlzdGNvZGUgPSBkaXN0Zml4OwogICAgICAgIHN0YXRlLmRpc3RiaXRzID0gNTsKICAgICAgfQogICAgICBmdW5jdGlvbiB1cGRhdGV3aW5kb3coc3RybSwgc3JjLCBlbmQsIGNvcHkpIHsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS53aW5kb3cgPT09IG51bGwpIHsKICAgICAgICAgIHN0YXRlLndzaXplID0gMSA8PCBzdGF0ZS53Yml0czsKICAgICAgICAgIHN0YXRlLnduZXh0ID0gMDsKICAgICAgICAgIHN0YXRlLndoYXZlID0gMDsKICAgICAgICAgIHN0YXRlLndpbmRvdyA9IG5ldyB1dGlscy5CdWY4KHN0YXRlLndzaXplKTsKICAgICAgICB9CiAgICAgICAgaWYgKGNvcHkgPj0gc3RhdGUud3NpemUpIHsKICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHN0YXRlLndpbmRvdywgc3JjLCBlbmQgLSBzdGF0ZS53c2l6ZSwgc3RhdGUud3NpemUsIDApOwogICAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgICAgc3RhdGUud2hhdmUgPSBzdGF0ZS53c2l6ZTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGlzdCA9IHN0YXRlLndzaXplIC0gc3RhdGUud25leHQ7CiAgICAgICAgICBpZiAoZGlzdCA+IGNvcHkpIHsKICAgICAgICAgICAgZGlzdCA9IGNvcHk7CiAgICAgICAgICB9CiAgICAgICAgICB1dGlscy5hcnJheVNldChzdGF0ZS53aW5kb3csIHNyYywgZW5kIC0gY29weSwgZGlzdCwgc3RhdGUud25leHQpOwogICAgICAgICAgY29weSAtPSBkaXN0OwogICAgICAgICAgaWYgKGNvcHkpIHsKICAgICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RhdGUud2luZG93LCBzcmMsIGVuZCAtIGNvcHksIGNvcHksIDApOwogICAgICAgICAgICBzdGF0ZS53bmV4dCA9IGNvcHk7CiAgICAgICAgICAgIHN0YXRlLndoYXZlID0gc3RhdGUud3NpemU7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzdGF0ZS53bmV4dCArPSBkaXN0OwogICAgICAgICAgICBpZiAoc3RhdGUud25leHQgPT09IHN0YXRlLndzaXplKSB7CiAgICAgICAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzdGF0ZS53aGF2ZSA8IHN0YXRlLndzaXplKSB7CiAgICAgICAgICAgICAgc3RhdGUud2hhdmUgKz0gZGlzdDsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlKHN0cm0sIGZsdXNoKSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIHZhciBpbnB1dCwgb3V0cHV0OwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBwdXQ7CiAgICAgICAgdmFyIGhhdmUsIGxlZnQ7CiAgICAgICAgdmFyIGhvbGQ7CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIF9pbiwgX291dDsKICAgICAgICB2YXIgY29weTsKICAgICAgICB2YXIgZnJvbTsKICAgICAgICB2YXIgZnJvbV9zb3VyY2U7CiAgICAgICAgdmFyIGhlcmUgPSAwOwogICAgICAgIHZhciBoZXJlX2JpdHMsIGhlcmVfb3AsIGhlcmVfdmFsOwogICAgICAgIHZhciBsYXN0X2JpdHMsIGxhc3Rfb3AsIGxhc3RfdmFsOwogICAgICAgIHZhciBsZW47CiAgICAgICAgdmFyIHJldDsKICAgICAgICB2YXIgaGJ1ZiA9IG5ldyB1dGlscy5CdWY4KDQpOwogICAgICAgIHZhciBvcHRzOwogICAgICAgIHZhciBuOwogICAgICAgIHZhciBvcmRlciA9IFsxNiwgMTcsIDE4LCAwLCA4LCA3LCA5LCA2LCAxMCwgNSwgMTEsIDQsIDEyLCAzLCAxMywgMiwgMTQsIDEsIDE1XTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUgfHwgIXN0cm0ub3V0cHV0IHx8ICFzdHJtLmlucHV0ICYmIHN0cm0uYXZhaWxfaW4gIT09IDApIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS5tb2RlID09PSBUWVBFKSB7CiAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRURPOwogICAgICAgIH0KICAgICAgICBwdXQgPSBzdHJtLm5leHRfb3V0OwogICAgICAgIG91dHB1dCA9IHN0cm0ub3V0cHV0OwogICAgICAgIGxlZnQgPSBzdHJtLmF2YWlsX291dDsKICAgICAgICBuZXh0ID0gc3RybS5uZXh0X2luOwogICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICBoYXZlID0gc3RybS5hdmFpbF9pbjsKICAgICAgICBob2xkID0gc3RhdGUuaG9sZDsKICAgICAgICBiaXRzID0gc3RhdGUuYml0czsKICAgICAgICBfaW4gPSBoYXZlOwogICAgICAgIF9vdXQgPSBsZWZ0OwogICAgICAgIHJldCA9IFpfT0s7CiAgICAgICAgaW5mX2xlYXZlOgogICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgIHN3aXRjaCAoc3RhdGUubW9kZSkgewogICAgICAgICAgICAgIGNhc2UgSEVBRDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFRE87CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUud3JhcCAmIDIgJiYgaG9sZCA9PT0gMzU2MTUpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSAwOwogICAgICAgICAgICAgICAgICBoYnVmWzBdID0gaG9sZCAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlsxXSA9IGhvbGQgPj4+IDggJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGhidWYsIDIsIDApOwogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBGTEFHUzsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5mbGFncyA9IDA7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmRvbmUgPSBmYWxzZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICghKHN0YXRlLndyYXAgJiAxKSB8fCAoKChob2xkICYgMjU1KSA8PCA4KSArIChob2xkID4+IDgpKSAlIDMxKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImluY29ycmVjdCBoZWFkZXIgY2hlY2siOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICgoaG9sZCAmIDE1KSAhPT0gWl9ERUZMQVRFRCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJ1bmtub3duIGNvbXByZXNzaW9uIG1ldGhvZCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA+Pj49IDQ7CiAgICAgICAgICAgICAgICBiaXRzIC09IDQ7CiAgICAgICAgICAgICAgICBsZW4gPSAoaG9sZCAmIDE1KSArIDg7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUud2JpdHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgc3RhdGUud2JpdHMgPSBsZW47CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGxlbiA+IHN0YXRlLndiaXRzKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgd2luZG93IHNpemUiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmRtYXggPSAxIDw8IGxlbjsKICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IDE7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gaG9sZCAmIDUxMiA/IERJQ1RJRCA6IFRZUEU7CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBGTEFHUzoKICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMTYpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZmxhZ3MgPSBob2xkOwogICAgICAgICAgICAgICAgaWYgKChzdGF0ZS5mbGFncyAmIDI1NSkgIT09IFpfREVGTEFURUQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAidW5rbm93biBjb21wcmVzc2lvbiBtZXRob2QiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDU3MzQ0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gInVua25vd24gaGVhZGVyIGZsYWdzIHNldCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC50ZXh0ID0gaG9sZCA+PiA4ICYgMTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICBoYnVmWzBdID0gaG9sZCAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlsxXSA9IGhvbGQgPj4+IDggJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGhidWYsIDIsIDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUSU1FOwogICAgICAgICAgICAgIGNhc2UgVElNRToKICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC50aW1lID0gaG9sZDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICBoYnVmWzBdID0gaG9sZCAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlsxXSA9IGhvbGQgPj4+IDggJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhidWZbMl0gPSBob2xkID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlszXSA9IGhvbGQgPj4+IDI0ICYgMjU1OwogICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IGNyYzMyKHN0YXRlLmNoZWNrLCBoYnVmLCA0LCAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gT1M7CiAgICAgICAgICAgICAgY2FzZSBPUzoKICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMTYpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC54ZmxhZ3MgPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLm9zID0gaG9sZCA+PiA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEVYTEVOOwogICAgICAgICAgICAgIGNhc2UgRVhMRU46CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiAxMDI0KSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMTYpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCA9IGhvbGQ7CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5leHRyYV9sZW4gPSBob2xkOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhidWZbMV0gPSBob2xkID4+PiA4ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGhidWYsIDIsIDApOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmV4dHJhID0gbnVsbDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBFWFRSQTsKICAgICAgICAgICAgICBjYXNlIEVYVFJBOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgMTAyNCkgewogICAgICAgICAgICAgICAgICBjb3B5ID0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgICBpZiAoY29weSA+IGhhdmUpIHsKICAgICAgICAgICAgICAgICAgICBjb3B5ID0gaGF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoY29weSkgewogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgICAgICBsZW4gPSBzdGF0ZS5oZWFkLmV4dHJhX2xlbiAtIHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgICAgICAgIGlmICghc3RhdGUuaGVhZC5leHRyYSkgewogICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmV4dHJhID0gbmV3IEFycmF5KHN0YXRlLmhlYWQuZXh0cmFfbGVuKTsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHN0YXRlLmhlYWQuZXh0cmEsIGlucHV0LCBuZXh0LCBjb3B5LCBsZW4pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1MTIpIHsKICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGlucHV0LCBjb3B5LCBuZXh0KTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZSAtPSBjb3B5OwogICAgICAgICAgICAgICAgICAgIG5leHQgKz0gY29weTsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoc3RhdGUubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IE5BTUU7CiAgICAgICAgICAgICAgY2FzZSBOQU1FOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgMjA0OCkgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBjb3B5ID0gMDsKICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgIGxlbiA9IGlucHV0W25leHQgKyBjb3B5KytdOwogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkICYmIGxlbiAmJiBzdGF0ZS5sZW5ndGggPCA2NTUzNikgewogICAgICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5uYW1lICs9IFN0cmluZy5mcm9tQ2hhckNvZGUobGVuKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKGxlbiAmJiBjb3B5IDwgaGF2ZSk7CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGlucHV0LCBjb3B5LCBuZXh0KTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlIC09IGNvcHk7CiAgICAgICAgICAgICAgICAgIG5leHQgKz0gY29weTsKICAgICAgICAgICAgICAgICAgaWYgKGxlbikgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQubmFtZSA9IG51bGw7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENPTU1FTlQ7CiAgICAgICAgICAgICAgY2FzZSBDT01NRU5UOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNDA5NikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBjb3B5ID0gMDsKICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgIGxlbiA9IGlucHV0W25leHQgKyBjb3B5KytdOwogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkICYmIGxlbiAmJiBzdGF0ZS5sZW5ndGggPCA2NTUzNikgewogICAgICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5jb21tZW50ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUobGVuKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKGxlbiAmJiBjb3B5IDwgaGF2ZSk7CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGlucHV0LCBjb3B5LCBuZXh0KTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlIC09IGNvcHk7CiAgICAgICAgICAgICAgICAgIG5leHQgKz0gY29weTsKICAgICAgICAgICAgICAgICAgaWYgKGxlbikgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuY29tbWVudCA9IG51bGw7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gSENSQzsKICAgICAgICAgICAgICBjYXNlIEhDUkM6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1MTIpIHsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGhvbGQgIT09IChzdGF0ZS5jaGVjayAmIDY1NTM1KSkgewogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImhlYWRlciBjcmMgbWlzbWF0Y2giOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5oY3JjID0gc3RhdGUuZmxhZ3MgPj4gOSAmIDE7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZG9uZSA9IHRydWU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRZUEU7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIERJQ1RJRDoKICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLmNoZWNrID0genN3YXAzMihob2xkKTsKICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gRElDVDsKICAgICAgICAgICAgICBjYXNlIERJQ1Q6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGF2ZWRpY3QgPT09IDApIHsKICAgICAgICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBsZWZ0OwogICAgICAgICAgICAgICAgICBzdHJtLm5leHRfaW4gPSBuZXh0OwogICAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX2luID0gaGF2ZTsKICAgICAgICAgICAgICAgICAgc3RhdGUuaG9sZCA9IGhvbGQ7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzOwogICAgICAgICAgICAgICAgICByZXR1cm4gWl9ORUVEX0RJQ1Q7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSAxOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRZUEU7CiAgICAgICAgICAgICAgY2FzZSBUWVBFOgogICAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX0JMT0NLIHx8IGZsdXNoID09PSBaX1RSRUVTKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBjYXNlIFRZUEVETzoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5sYXN0KSB7CiAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBiaXRzICYgNzsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBiaXRzICYgNzsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENIRUNLOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMykgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sYXN0ID0gaG9sZCAmIDE7CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gMTsKICAgICAgICAgICAgICAgIGJpdHMgLT0gMTsKICAgICAgICAgICAgICAgIHN3aXRjaCAoaG9sZCAmIDMpIHsKICAgICAgICAgICAgICAgICAgY2FzZSAwOgogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBTVE9SRUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIGNhc2UgMToKICAgICAgICAgICAgICAgICAgICBmaXhlZHRhYmxlcyhzdGF0ZSk7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTl87CiAgICAgICAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX1RSRUVTKSB7CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gMjsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gMjsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVEFCTEU7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIGNhc2UgMzoKICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGJsb2NrIHR5cGUiOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gMjsKICAgICAgICAgICAgICAgIGJpdHMgLT0gMjsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgU1RPUkVEOgogICAgICAgICAgICAgICAgaG9sZCA+Pj49IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgYml0cyAtPSBiaXRzICYgNzsKICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKChob2xkICYgNjU1MzUpICE9PSAoaG9sZCA+Pj4gMTYgXiA2NTUzNSkpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBzdG9yZWQgYmxvY2sgbGVuZ3RocyI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubGVuZ3RoID0gaG9sZCAmIDY1NTM1OwogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBDT1BZXzsKICAgICAgICAgICAgICAgIGlmIChmbHVzaCA9PT0gWl9UUkVFUykgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgY2FzZSBDT1BZXzoKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBDT1BZOwogICAgICAgICAgICAgIGNhc2UgQ09QWToKICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICBpZiAoY29weSkgewogICAgICAgICAgICAgICAgICBpZiAoY29weSA+IGhhdmUpIHsKICAgICAgICAgICAgICAgICAgICBjb3B5ID0gaGF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoY29weSA+IGxlZnQpIHsKICAgICAgICAgICAgICAgICAgICBjb3B5ID0gbGVmdDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoY29weSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB1dGlscy5hcnJheVNldChvdXRwdXQsIGlucHV0LCBuZXh0LCBjb3B5LCBwdXQpOwogICAgICAgICAgICAgICAgICBoYXZlIC09IGNvcHk7CiAgICAgICAgICAgICAgICAgIG5leHQgKz0gY29weTsKICAgICAgICAgICAgICAgICAgbGVmdCAtPSBjb3B5OwogICAgICAgICAgICAgICAgICBwdXQgKz0gY29weTsKICAgICAgICAgICAgICAgICAgc3RhdGUubGVuZ3RoIC09IGNvcHk7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRZUEU7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIFRBQkxFOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNCkgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5ubGVuID0gKGhvbGQgJiAzMSkgKyAyNTc7CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gNTsKICAgICAgICAgICAgICAgIGJpdHMgLT0gNTsKICAgICAgICAgICAgICAgIHN0YXRlLm5kaXN0ID0gKGhvbGQgJiAzMSkgKyAxOwogICAgICAgICAgICAgICAgaG9sZCA+Pj49IDU7CiAgICAgICAgICAgICAgICBiaXRzIC09IDU7CiAgICAgICAgICAgICAgICBzdGF0ZS5uY29kZSA9IChob2xkICYgMTUpICsgNDsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA0OwogICAgICAgICAgICAgICAgYml0cyAtPSA0OwogICAgICAgICAgICAgICAgaWYgKHN0YXRlLm5sZW4gPiAyODYgfHwgc3RhdGUubmRpc3QgPiAzMCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJ0b28gbWFueSBsZW5ndGggb3IgZGlzdGFuY2Ugc3ltYm9scyI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuaGF2ZSA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOTEVOUzsKICAgICAgICAgICAgICBjYXNlIExFTkxFTlM6CiAgICAgICAgICAgICAgICB3aGlsZSAoc3RhdGUuaGF2ZSA8IHN0YXRlLm5jb2RlKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMykgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgc3RhdGUubGVuc1tvcmRlcltzdGF0ZS5oYXZlKytdXSA9IGhvbGQgJiA3OwogICAgICAgICAgICAgICAgICBob2xkID4+Pj0gMzsKICAgICAgICAgICAgICAgICAgYml0cyAtPSAzOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgd2hpbGUgKHN0YXRlLmhhdmUgPCAxOSkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW29yZGVyW3N0YXRlLmhhdmUrK11dID0gMDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxlbmNvZGUgPSBzdGF0ZS5sZW5keW47CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5iaXRzID0gNzsKICAgICAgICAgICAgICAgIG9wdHMgPSB7IGJpdHM6IHN0YXRlLmxlbmJpdHMgfTsKICAgICAgICAgICAgICAgIHJldCA9IGluZmxhdGVfdGFibGUoQ09ERVMsIHN0YXRlLmxlbnMsIDAsIDE5LCBzdGF0ZS5sZW5jb2RlLCAwLCBzdGF0ZS53b3JrLCBvcHRzKTsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSBvcHRzLmJpdHM7CiAgICAgICAgICAgICAgICBpZiAocmV0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgY29kZSBsZW5ndGhzIHNldCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuaGF2ZSA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQ09ERUxFTlM7CiAgICAgICAgICAgICAgY2FzZSBDT0RFTEVOUzoKICAgICAgICAgICAgICAgIHdoaWxlIChzdGF0ZS5oYXZlIDwgc3RhdGUubmxlbiArIHN0YXRlLm5kaXN0KSB7CiAgICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICAgIGhlcmUgPSBzdGF0ZS5sZW5jb2RlW2hvbGQgJiAoMSA8PCBzdGF0ZS5sZW5iaXRzKSAtIDFdOwogICAgICAgICAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICAgIGhlcmVfb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgICBoZXJlX3ZhbCA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgICBpZiAoaGVyZV9iaXRzIDw9IGJpdHMpIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChoZXJlX3ZhbCA8IDE2KSB7CiAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW3N0YXRlLmhhdmUrK10gPSBoZXJlX3ZhbDsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGVyZV92YWwgPT09IDE2KSB7CiAgICAgICAgICAgICAgICAgICAgICBuID0gaGVyZV9iaXRzICsgMjsKICAgICAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgbikgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGJpdCBsZW5ndGggcmVwZWF0IjsKICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBsZW4gPSBzdGF0ZS5sZW5zW3N0YXRlLmhhdmUgLSAxXTsKICAgICAgICAgICAgICAgICAgICAgIGNvcHkgPSAzICsgKGhvbGQgJiAzKTsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAyOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSAyOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoaGVyZV92YWwgPT09IDE3KSB7CiAgICAgICAgICAgICAgICAgICAgICBuID0gaGVyZV9iaXRzICsgMzsKICAgICAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgbikgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBsZW4gPSAwOwogICAgICAgICAgICAgICAgICAgICAgY29weSA9IDMgKyAoaG9sZCAmIDcpOwogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IDM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IDM7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyA3OwogICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IDA7CiAgICAgICAgICAgICAgICAgICAgICBjb3B5ID0gMTEgKyAoaG9sZCAmIDEyNyk7CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gNzsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gNzsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhhdmUgKyBjb3B5ID4gc3RhdGUubmxlbiArIHN0YXRlLm5kaXN0KSB7CiAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGJpdCBsZW5ndGggcmVwZWF0IjsKICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGNvcHktLSkgewogICAgICAgICAgICAgICAgICAgICAgc3RhdGUubGVuc1tzdGF0ZS5oYXZlKytdID0gbGVuOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IEJBRCkgewogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5sZW5zWzI1Nl0gPT09IDApIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBjb2RlIC0tIG1pc3NpbmcgZW5kLW9mLWJsb2NrIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5iaXRzID0gOTsKICAgICAgICAgICAgICAgIG9wdHMgPSB7IGJpdHM6IHN0YXRlLmxlbmJpdHMgfTsKICAgICAgICAgICAgICAgIHJldCA9IGluZmxhdGVfdGFibGUoTEVOUywgc3RhdGUubGVucywgMCwgc3RhdGUubmxlbiwgc3RhdGUubGVuY29kZSwgMCwgc3RhdGUud29yaywgb3B0cyk7CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5iaXRzID0gb3B0cy5iaXRzOwogICAgICAgICAgICAgICAgaWYgKHJldCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGxpdGVyYWwvbGVuZ3RocyBzZXQiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmRpc3RiaXRzID0gNjsKICAgICAgICAgICAgICAgIHN0YXRlLmRpc3Rjb2RlID0gc3RhdGUuZGlzdGR5bjsKICAgICAgICAgICAgICAgIG9wdHMgPSB7IGJpdHM6IHN0YXRlLmRpc3RiaXRzIH07CiAgICAgICAgICAgICAgICByZXQgPSBpbmZsYXRlX3RhYmxlKERJU1RTLCBzdGF0ZS5sZW5zLCBzdGF0ZS5ubGVuLCBzdGF0ZS5uZGlzdCwgc3RhdGUuZGlzdGNvZGUsIDAsIHN0YXRlLndvcmssIG9wdHMpOwogICAgICAgICAgICAgICAgc3RhdGUuZGlzdGJpdHMgPSBvcHRzLmJpdHM7CiAgICAgICAgICAgICAgICBpZiAocmV0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2VzIHNldCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTl87CiAgICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfVFJFRVMpIHsKICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGNhc2UgTEVOXzoKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU47CiAgICAgICAgICAgICAgY2FzZSBMRU46CiAgICAgICAgICAgICAgICBpZiAoaGF2ZSA+PSA2ICYmIGxlZnQgPj0gMjU4KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSBwdXQ7CiAgICAgICAgICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gbGVmdDsKICAgICAgICAgICAgICAgICAgc3RybS5uZXh0X2luID0gbmV4dDsKICAgICAgICAgICAgICAgICAgc3RybS5hdmFpbF9pbiA9IGhhdmU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhvbGQgPSBob2xkOwogICAgICAgICAgICAgICAgICBzdGF0ZS5iaXRzID0gYml0czsKICAgICAgICAgICAgICAgICAgaW5mbGF0ZV9mYXN0KHN0cm0sIF9vdXQpOwogICAgICAgICAgICAgICAgICBwdXQgPSBzdHJtLm5leHRfb3V0OwogICAgICAgICAgICAgICAgICBvdXRwdXQgPSBzdHJtLm91dHB1dDsKICAgICAgICAgICAgICAgICAgbGVmdCA9IHN0cm0uYXZhaWxfb3V0OwogICAgICAgICAgICAgICAgICBuZXh0ID0gc3RybS5uZXh0X2luOwogICAgICAgICAgICAgICAgICBpbnB1dCA9IHN0cm0uaW5wdXQ7CiAgICAgICAgICAgICAgICAgIGhhdmUgPSBzdHJtLmF2YWlsX2luOwogICAgICAgICAgICAgICAgICBob2xkID0gc3RhdGUuaG9sZDsKICAgICAgICAgICAgICAgICAgYml0cyA9IHN0YXRlLmJpdHM7CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5tb2RlID09PSBUWVBFKSB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUuYmFjayA9IC0xOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuYmFjayA9IDA7CiAgICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgICAgaGVyZSA9IHN0YXRlLmxlbmNvZGVbaG9sZCAmICgxIDw8IHN0YXRlLmxlbmJpdHMpIC0gMV07CiAgICAgICAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICBoZXJlX29wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICBpZiAoaGVyZV9iaXRzIDw9IGJpdHMpIHsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoaGVyZV9vcCAmJiAoaGVyZV9vcCAmIDI0MCkgPT09IDApIHsKICAgICAgICAgICAgICAgICAgbGFzdF9iaXRzID0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICBsYXN0X29wID0gaGVyZV9vcDsKICAgICAgICAgICAgICAgICAgbGFzdF92YWwgPSBoZXJlX3ZhbDsKICAgICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgICAgaGVyZSA9IHN0YXRlLmxlbmNvZGVbbGFzdF92YWwgKyAoKGhvbGQgJiAoMSA8PCBsYXN0X2JpdHMgKyBsYXN0X29wKSAtIDEpID4+IGxhc3RfYml0cyldOwogICAgICAgICAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICAgIGhlcmVfb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgICBoZXJlX3ZhbCA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgICBpZiAobGFzdF9iaXRzICsgaGVyZV9iaXRzIDw9IGJpdHMpIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgLT0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrICs9IGxhc3RfYml0czsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgc3RhdGUubGVuZ3RoID0gaGVyZV92YWw7CiAgICAgICAgICAgICAgICBpZiAoaGVyZV9vcCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTElUOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChoZXJlX29wICYgMzIpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuYmFjayA9IC0xOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoaGVyZV9vcCAmIDY0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgbGl0ZXJhbC9sZW5ndGggY29kZSI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZXh0cmEgPSBoZXJlX29wICYgMTU7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVORVhUOwogICAgICAgICAgICAgIGNhc2UgTEVORVhUOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmV4dHJhKSB7CiAgICAgICAgICAgICAgICAgIG4gPSBzdGF0ZS5leHRyYTsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggKz0gaG9sZCAmICgxIDw8IHN0YXRlLmV4dHJhKSAtIDE7CiAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBzdGF0ZS5leHRyYTsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBzdGF0ZS5leHRyYTsKICAgICAgICAgICAgICAgICAgc3RhdGUuYmFjayArPSBzdGF0ZS5leHRyYTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLndhcyA9IHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBESVNUOwogICAgICAgICAgICAgIGNhc2UgRElTVDoKICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUuZGlzdGNvZGVbaG9sZCAmICgxIDw8IHN0YXRlLmRpc3RiaXRzKSAtIDFdOwogICAgICAgICAgICAgICAgICBoZXJlX2JpdHMgPSBoZXJlID4+PiAyNDsKICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICBoZXJlX3ZhbCA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgaWYgKGhlcmVfYml0cyA8PSBiaXRzKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKChoZXJlX29wICYgMjQwKSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBsYXN0X2JpdHMgPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgIGxhc3Rfb3AgPSBoZXJlX29wOwogICAgICAgICAgICAgICAgICBsYXN0X3ZhbCA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUuZGlzdGNvZGVbbGFzdF92YWwgKyAoKGhvbGQgJiAoMSA8PCBsYXN0X2JpdHMgKyBsYXN0X29wKSAtIDEpID4+IGxhc3RfYml0cyldOwogICAgICAgICAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICAgIGhlcmVfb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgICBoZXJlX3ZhbCA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgICBpZiAobGFzdF9iaXRzICsgaGVyZV9iaXRzIDw9IGJpdHMpIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgLT0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrICs9IGxhc3RfYml0czsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgaWYgKGhlcmVfb3AgJiA2NCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIGNvZGUiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm9mZnNldCA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgc3RhdGUuZXh0cmEgPSBoZXJlX29wICYgMTU7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gRElTVEVYVDsKICAgICAgICAgICAgICBjYXNlIERJU1RFWFQ6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZXh0cmEpIHsKICAgICAgICAgICAgICAgICAgbiA9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHN0YXRlLm9mZnNldCArPSBob2xkICYgKDEgPDwgc3RhdGUuZXh0cmEpIC0gMTsKICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBiaXRzIC09IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrICs9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLm9mZnNldCA+IHN0YXRlLmRtYXgpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2siOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBNQVRDSDsKICAgICAgICAgICAgICBjYXNlIE1BVENIOgogICAgICAgICAgICAgICAgaWYgKGxlZnQgPT09IDApIHsKICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgY29weSA9IF9vdXQgLSBsZWZ0OwogICAgICAgICAgICAgICAgaWYgKHN0YXRlLm9mZnNldCA+IGNvcHkpIHsKICAgICAgICAgICAgICAgICAgY29weSA9IHN0YXRlLm9mZnNldCAtIGNvcHk7CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gc3RhdGUud2hhdmUpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuc2FuZSkgewogICAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2siOwogICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoY29weSA+IHN0YXRlLnduZXh0KSB7CiAgICAgICAgICAgICAgICAgICAgY29weSAtPSBzdGF0ZS53bmV4dDsKICAgICAgICAgICAgICAgICAgICBmcm9tID0gc3RhdGUud3NpemUgLSBjb3B5OwogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIGZyb20gPSBzdGF0ZS53bmV4dCAtIGNvcHk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGNvcHkgPiBzdGF0ZS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgICAgICBjb3B5ID0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gc3RhdGUud2luZG93OwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7CiAgICAgICAgICAgICAgICAgIGZyb20gPSBwdXQgLSBzdGF0ZS5vZmZzZXQ7CiAgICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoY29weSA+IGxlZnQpIHsKICAgICAgICAgICAgICAgICAgY29weSA9IGxlZnQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBsZWZ0IC09IGNvcHk7CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTsKICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgb3V0cHV0W3B1dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICB9IHdoaWxlICgtLWNvcHkpOwogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmxlbmd0aCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBMSVQ6CiAgICAgICAgICAgICAgICBpZiAobGVmdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBvdXRwdXRbcHV0KytdID0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgbGVmdC0tOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTjsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgQ0hFQ0s6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUud3JhcCkgewogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDMyKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgfD0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBfb3V0IC09IGxlZnQ7CiAgICAgICAgICAgICAgICAgIHN0cm0udG90YWxfb3V0ICs9IF9vdXQ7CiAgICAgICAgICAgICAgICAgIHN0YXRlLnRvdGFsICs9IF9vdXQ7CiAgICAgICAgICAgICAgICAgIGlmIChfb3V0KSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLmNoZWNrID0gc3RhdGUuZmxhZ3MgPyBjcmMzMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBwdXQgLSBfb3V0KSA6IGFkbGVyMzIoc3RhdGUuY2hlY2ssIG91dHB1dCwgX291dCwgcHV0IC0gX291dCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgX291dCA9IGxlZnQ7CiAgICAgICAgICAgICAgICAgIGlmICgoc3RhdGUuZmxhZ3MgPyBob2xkIDogenN3YXAzMihob2xkKSkgIT09IHN0YXRlLmNoZWNrKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW5jb3JyZWN0IGRhdGEgY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTkdUSDsKICAgICAgICAgICAgICBjYXNlIExFTkdUSDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwICYmIHN0YXRlLmZsYWdzKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChob2xkICE9PSAoc3RhdGUudG90YWwgJiA0Mjk0OTY3Mjk1KSkgewogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImluY29ycmVjdCBsZW5ndGggY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IERPTkU7CiAgICAgICAgICAgICAgY2FzZSBET05FOgogICAgICAgICAgICAgICAgcmV0ID0gWl9TVFJFQU1fRU5EOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgQkFEOgogICAgICAgICAgICAgICAgcmV0ID0gWl9EQVRBX0VSUk9SOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgTUVNOgogICAgICAgICAgICAgICAgcmV0dXJuIFpfTUVNX0VSUk9SOwogICAgICAgICAgICAgIGNhc2UgU1lOQzoKICAgICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICBzdHJtLmF2YWlsX291dCA9IGxlZnQ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9PT0gVFlQRSA/IDEyOCA6IDApICsgKHN0YXRlLm1vZGUgPT09IExFTl8gfHwgc3RhdGUubW9kZSA9PT0gQ09QWV8gPyAyNTYgOiAwKTsKICAgICAgICBpZiAoKF9pbiA9PT0gMCAmJiBfb3V0ID09PSAwIHx8IGZsdXNoID09PSBaX0ZJTklTSCkgJiYgcmV0ID09PSBaX09LKSB7CiAgICAgICAgICByZXQgPSBaX0JVRl9FUlJPUjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlRW5kKHN0cm0pIHsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgdmFyIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAoc3RhdGUud2luZG93KSB7CiAgICAgICAgICBzdGF0ZS53aW5kb3cgPSBudWxsOwogICAgICAgIH0KICAgICAgICBzdHJtLnN0YXRlID0gbnVsbDsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlR2V0SGVhZGVyKHN0cm0sIGhlYWQpIHsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAoKHN0YXRlLndyYXAgJiAyKSA9PT0gMCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZS5oZWFkID0gaGVhZDsKICAgICAgICBoZWFkLmRvbmUgPSBmYWxzZTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYX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6IDQsCiAgICAgICAgWl9CTE9DSzogNSwKICAgICAgICBaX1RSRUVTOiA2LAogICAgICAgIFpfT0s6IDAsCiAgICAgICAgWl9TVFJFQU1fRU5EOiAxLAogICAgICAgIFpfTkVFRF9ESUNUOiAyLAogICAgICAgIFpfRVJSTk86IC0xLAogICAgICAgIFpfU1RSRUFNX0VSUk9SOiAtMiwKICAgICAgICBaX0RBVEFfRVJST1I6IC0zLAogICAgICAgIFpfQlVGX0VSUk9SOiAtNSwKICAgICAgICBaX05PX0NPTVBSRVNTSU9OOiAwLAogICAgICAgIFpfQkVTVF9TUEVFRDogMSwKICAgICAgICBaX0JFU1RfQ09NUFJFU1NJT046IDksCiAgICAgICAgWl9ERUZBVUxUX0NPTVBSRVNTSU9OOiAtMSwKICAgICAgICBaX0ZJTFRFUkVEOiAxLAogICAgICAgIFpfSFVGRk1BTl9PTkxZOiAyLAogICAgICAgIFpfUkxFOiAzLAogICAgICAgIFpfRklYRUQ6IDQsCiAgICAgICAgWl9ERUZBVUxUX1NUUkFURUdZOiAwLAogICAgICAgIFpfQklOQVJZOiAwLAogICAgICAgIFpfVEVYVDogMSwKICAgICAgICBaX1VOS05PV046IDIsCiAgICAgICAgWl9ERUZMQVRFRDogOAogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvZ3poZWFkZXIuanMKICB2YXIgcmVxdWlyZV9nemhlYWRlciA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9nemhlYWRlci5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIGZ1bmN0aW9uIEdaaGVhZGVyKCkgewogICAgICAgIHRoaXMudGV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ZzsKICAgICAgZnVuY3Rpb24gSW5mbGF0ZTIob3B0aW9ucykgewogICAgICAgIGlmICghKHRoaXMgaW5zdGFuY2VvZiBJbmZsYXRlMikpCiAgICAgICAgICByZXR1cm4gbmV3IEluZmxhdGUyKG9wdGlvbnMpOwogICAgICAgIHRoaXMub3B0aW9ucyA9IHV0aWxzLmFzc2lnbih7CiAgICAgICAgICBjaHVua1NpemU6IDE2Mzg0LAogICAgICAgICAgd2luZG93Qml0czogMCwKICAgICAgICAgIHRvOiAiIgogICAgICAgIH0sIG9wdGlvbnMgfHwge30pOwogICAgICAgIHZhciBvcHQgPSB0aGlzLm9wdGlvbnM7CiAgICAgICAgaWYgKG9wdC5yYXcgJiYgb3B0LndpbmRvd0JpdHMgPj0gMCAmJiBvcHQud2luZG93Qml0cyA8IDE2KSB7CiAgICAgICAgICBvcHQud2luZG93Qml0cyA9IC1vcHQud2luZG93Qml0czsKICAgICAgICAgIGlmIChvcHQud2luZG93Qml0cyA9PT0gMCkgewogICAgICAgICAgICBvcHQud2luZG93Qml0cyA9IC0xNTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKG9wdC53aW5kb3dCaXRzID49IDAgJiYgb3B0LndpbmRvd0JpdHMgPCAxNiAmJiAhKG9wdGlvbnMgJiYgb3B0aW9ucy53aW5kb3dCaXRzKSkgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgKz0gMzI7CiAgICAgICAgfQogICAgICAgIGlmIChvcHQud2luZG93Qml0cyA+IDE1ICYmIG9wdC53aW5kb3dCaXRzIDwgNDgpIHsKICAgICAgICAgIGlmICgob3B0LndpbmRvd0JpdHMgJiAxNSkgPT09IDApIHsKICAgICAgICAgICAgb3B0LndpbmRvd0JpdHMgfD0gMTU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHRoaXMuZXJyID0gMDsKICAgICAgICB0aGlzLm1zZyA9ICIiOwogICAgICAgIHRoaXMuZW5kZWQgPSBmYWxzZTsKICAgICAgICB0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ICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBJbmZsYXRlMi5wcm90b3R5cGUucHVzaCA9IGZ1bmN0aW9uKGRhdGEsIG1vZGUpIHsKICAgICAgICB2YXIgc3RybSA9IHRoaXMuc3RybTsKICAgICAgICB2YXIgY2h1bmtTaXplID0gdGhpcy5vcHRpb25zLmNodW5rU2l6ZTsKICAgICAgICB2YXIgZGljdGlvbmFyeSA9IHRoaXMub3B0aW9ucy5kaWN0aW9uYXJ5OwogICAgICAgIHZhciBzdGF0dXMsIF9tb2RlOwogICAgICAgIHZhciBuZXh0X291dF91dGY4LCB0YWlsLCB1dGY4c3RyOwogICAgICAgIHZhciBhbGxvd0J1ZkVycm9yID0gZmFsc2U7CiAgICAgICAgaWYgKHRoaXMuZW5kZWQpIHsKICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICAgICAgX21vZGUgPSBtb2RlID09PSB+fm1vZGUgPyBtb2RlIDogbW9kZSA9PT0gdHJ1ZSA/IGMuWl9GSU5JU0ggOiBjLlpfTk9fRkxVU0g7CiAgICAgICAgaWYgKHR5cGVvZiBkYXRhID09PSAic3RyaW5nIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IHN0cmluZ3MuYmluc3RyaW5nMmJ1ZihkYXRhKTsKICAgICAgICB9IGVsc2UgaWYgKHRvU3RyaW5nLmNhbGwoZGF0YSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBuZXcgVWludDhBcnJheShkYXRhKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgc3RybS5pbnB1dCA9IGRhdGE7CiAgICAgICAgfQogICAgICAgIHN0cm0ubmV4dF9pbiA9IDA7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IHN0cm0uaW5wdXQubGVuZ3RoOwogICAgICAgIGRvIHsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzdHJtLm91dHB1dCA9IG5ldyB1dGlscy5CdWY4KGNodW5rU2l6ZSk7CiAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSAwOwogICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfaW5mbGF0ZS5pbmZsYXRlKHN0cm0sIGMuWl9OT19GTFVTSCk7CiAgICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfTkVFRF9ESUNUICYmIGRpY3Rpb25hcnkpIHsKICAgICAgICAgICAgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGVTZXREaWN0aW9uYXJ5KHRoaXMuc3RybSwgZGljdGlvbmFyeSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfQlVGX0VSUk9SICYmIGFsbG93QnVmRXJyb3IgPT09IHRydWUpIHsKICAgICAgICAgICAgc3RhdHVzID0gYy5aX09LOwogICAgICAgICAgICBhbGxvd0J1ZkVycm9yID0gZmFsc2U7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RhdHVzICE9PSBjLlpfU1RSRUFNX0VORCAmJiBzdGF0dXMgIT09IGMuWl9PSykgewogICAgICAgICAgICB0aGlzLm9uRW5kKHN0YXR1cyk7CiAgICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RybS5uZXh0X291dCkgewogICAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDAgfHwgc3RhdHVzID09PSBjLlpfU1RSRUFNX0VORCB8fCBzdHJtLmF2YWlsX2luID09PSAwICYmIChfbW9kZSA9PT0gYy5aX0ZJTklTSCB8fCBfbW9kZSA9PT0gYy5aX1NZTkNfRkxVU0gpKSB7CiAgICAgICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICAgIG5leHRfb3V0X3V0ZjggPSBzdHJpbmdzLnV0Zjhib3JkZXIoc3RybS5vdXRwdXQsIHN0cm0ubmV4dF9vdXQpOwogICAgICAgICAgICAgICAgdGFpbCA9IHN0cm0ubmV4dF9vdXQgLSBuZXh0X291dF91dGY4OwogICAgICAgICAgICAgICAgdXRmOHN0ciA9IHN0cmluZ3MuYnVmMnN0cmluZyhzdHJtLm91dHB1dCwgbmV4dF9vdXRfdXRmOCk7CiAgICAgICAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gdGFpbDsKICAgICAgICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gY2h1bmtTaXplIC0gdGFpbDsKICAgICAgICAgICAgICAgIGlmICh0YWlsKSB7CiAgICAgICAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHN0cm0ub3V0cHV0LCBzdHJtLm91dHB1dCwgbmV4dF9vdXRfdXRmOCwgdGFpbCwgMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB0aGlzLm9uRGF0YSh1dGY4c3RyKTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdGhpcy5vbkRhdGEodXRpbHMuc2hyaW5rQnVmKHN0cm0ub3V0cHV0LCBzdHJtLm5leHRfb3V0KSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RybS5hdmFpbF9pbiA9PT0gMCAmJiBzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBhbGxvd0J1ZkVycm9yID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlICgoc3RybS5hdmFpbF9pbiA+IDAgfHwgc3RybS5hdmFpbF9vdXQgPT09IDApICYmIHN0YXR1cyAhPT0gYy5aX1NUUkVBTV9FTkQpOwogICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9TVFJFQU1fRU5EKSB7CiAgICAgICAgICBfbW9kZSA9IGMuWl9GSU5JU0g7CiAgICAgICAgfQogICAgICAgIGlmIChfbW9kZSA9PT0gYy5aX0ZJTklTSCkgewogICAgICAgICAgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGVFbmQodGhpcy5zdHJtKTsKICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgcmV0dXJuIHN0YXR1cyA9PT0gYy5aX09LOwogICAgICAgIH0KICAgICAgICBpZiAoX21vZGUgPT09IGMuWl9TWU5DX0ZMVVNIKSB7CiAgICAgICAgICB0aGlzLm9uRW5kKGMuWl9PSyk7CiAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IDA7CiAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgIH07CiAgICAgIEluZmxhdGUyLnByb3RvdHlwZS5vbkRhdGEgPSBmdW5jdGlvbihjaHVuaykgewogICAgICAgIHRoaXMuY2h1bmtzLnB1c2goY2h1bmspOwogICAgICB9OwogICAgICBJbmZsYXRlMi5wcm90b3R5cGUub25FbmQgPSBmdW5jdGlvbihzdGF0dXMpIHsKICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfT0spIHsKICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdGhpcy5jaHVua3Muam9pbigiIik7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHV0aWxzLmZsYXR0ZW5DaHVua3ModGhpcy5jaHVua3MpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuZXJyID0gc3RhdHVzOwogICAgICAgIHRoaXMubXNnID0gdGhp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ZV9jb21tb24oKS5hc3NpZ247CiAgICAgIHZhciBkZWZsYXRlID0gcmVxdWlyZV9kZWZsYXRlMigpOwogICAgICB2YXIgaW5mbGF0ZSA9IHJlcXVpcmVfaW5mbGF0ZTIoKTsKICAgICAgdmFyIGNvbnN0YW50cyA9IHJlcXVpcmVfY29uc3RhbnRzKCk7CiAgICAgIHZhciBwYWtvID0ge307CiAgICAgIGFzc2lnbihwYWtvLCBkZWZsYXRlLCBpbmZsYXRlLCBjb25zdGFudHMpOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBwYWtvOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vbG9uZ0A0LjAuMC9ub2RlX21vZHVsZXMvbG9uZy9zcmMvbG9uZy5qcwogIHZhciByZXF1aXJlX2xvbmcgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vbG9uZ0A0LjAuMC9ub2RlX21vZHVsZXMvbG9uZy9zcmMvbG9uZy5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBMb25nNDsKICAgICAgdmFyIHdhc20gPSBudWxsOwogICAgICB0cnkgewogICAgICAgIHdhc20gPSBuZXcgV2ViQXNzZW1ibHkuSW5zdGFuY2UobmV3IFdlYkFzc2VtYmx5Lk1vZHVsZShuZXcgVWludDhBcnJheShbCiAgICAgICAgICAwLAogICAgICAgICAgOTcsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxLAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEzLAogICAgICAgICAgMiwKICAgICAgICAgIDk2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICA5NiwKICAgICAgICAgIDQsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMywKICAgICAgICAgIDcsCiAgICAgICAgICA2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgNiwKICAgICAgICAgIDYsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMSwKICAgICAgICAgIDY1LAogICAgICAgICAgMCwKICAgICAgICAgIDExLAogICAgICAgICAgNywKICAgICAgICAgIDUwLAogICAgICAgICAgNiwKICAgICAgICAgIDMsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxMTcsCiAgICAgICAgICAxMDgsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDUsCiAgICAgICAgICAxMDAsCiAgICAgICAgICAxMDUsCiAgICAgICAgICAxMTgsCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNSwKICAgICAgICAgIDAsCiAgICAgICAgICAyLAogICAgICAgICAgNSwKICAgICAgICAgIDEwMCwKICAgICAgICAgIDEwNSwKICAgICAgICAgIDExOCwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE3LAogICAgICAgICAgMCwKICAgICAgICAgIDMsCiAgICAgICAgICA1LAogICAgICAgICAgMTE0LAogICAgICAgICAgMTAxLAogICAgICAgICAgMTA5LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAwLAogICAgICAgICAgNCwKICAgICAgICAgIDUsCiAgICAgICAgICAxMTQsCiAgICAgICAgICAxMDEsCiAgICAgICAgICAxMDksCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNywKICAgICAgICAgIDAsCiAgICAgICAgICA1LAogICAgICAgICAgOCwKICAgICAgICAgIDEwMywKICAgICAgICAgIDEwMSwKICAgICAgICAgIDExNiwKICAgICAgICAgIDk1LAogICAgICAgICAgMTA0LAogICAgICAgICAgMTA1LAogICAgICAgICAgMTAzLAogICAgICAgICAgMTA0LAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAxMCwKICAgICAgICAgIDE5MSwKICAgICAgICAgIDEsCiAgICAgICAgICA2LAogICAgICAgICAgNCwKICAgICAgICAgIDAsCiAgICAgICAgICAzNSwKICAgICAgICAgIDAsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNywKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOSwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEzMCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMQogICAgICAgIF0pKSwge30pLmV4cG9ydHM7CiAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgfQogICAgICBmdW5jdGlvbiBMb25nNChsb3csIGhpZ2gsIHVuc2lnbmVkKSB7CiAgICAgICAgdGhpcy5sb3cgPSBsb3cgfCAwOwogICAgICAgIHRoaXMuaGlnaCA9IGhpZ2ggfCAwOwogICAgICAgIHRoaXMudW5zaWduZWQgPSAhIXVuc2lnbmVkOwogICAgICB9CiAgICAgIExvbmc0LnByb3RvdHlwZS5fX2lzTG9uZ19fOwogICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoTG9uZzQucHJvdG90eXBlLCAiX19pc0xvbmdfXyIsIHsgdmFsdWU6IHRydWUgfSk7CiAgICAgIGZ1bmN0aW9uIGlzTG9uZyhvYmopIHsKICAgICAgICByZXR1cm4gKG9iaiAmJiBvYmpbIl9faXNMb25nX18iXSkgPT09IHRydWU7CiAgICAgIH0KICAgICAgTG9uZzQuaXNMb25nID0gaXNMb25nOwogICAgICB2YXIgSU5UX0NBQ0hFID0ge307CiAgICAgIHZhciBVSU5UX0NBQ0hFID0ge307CiAgICAgIGZ1bmN0aW9uIGZyb21JbnQodmFsdWUsIHVuc2lnbmVkKSB7CiAgICAgICAgdmFyIG9iaiwgY2FjaGVkT2JqLCBjYWNoZTsKICAgICAgICBpZiAodW5zaWduZWQpIHsKICAgICAgICAgIHZhbHVlID4+Pj0gMDsKICAgICAgICAgIGlmIChjYWNoZSA9IDAgPD0gdmFsdWUgJiYgdmFsdWUgPCAyNTYpIHsKICAgICAgICAgICAgY2FjaGVkT2JqID0gVUlOVF9DQUNIRVt2YWx1ZV07CiAgICAgICAgICAgIGlmIChjYWNoZWRPYmopCiAgICAgICAgICAgICAgcmV0dXJuIGNhY2hlZE9iajsKICAgICAgICAgIH0KICAgICAgICAgIG9iaiA9IGZyb21CaXRzKHZhbHVlLCAodmFsdWUgfCAwKSA8IDAgPyAtMSA6IDAsIHRydWUpOwogICAgICAgICAgaWYgKGNhY2hlKQogICAgICAgICAgICBVSU5UX0NBQ0hFW3ZhbHVlXSA9IG9iajsKICAgICAgICAgIHJldHVybiBvYmo7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHZhbHVlIHw9IDA7CiAgICAgICAgICBpZiAoY2FjaGUgPSAtMTI4IDw9IHZhbHVlICYmIHZhbHVlIDwgMTI4KSB7CiAgICAgICAgICAgIGNhY2hlZE9iaiA9IElOVF9DQUNIRVt2YWx1ZV07CiAgICAgICAgICAgIGlmIChjYWNoZWRPYmopCiAgICAgICAgICAgICAgcmV0dXJuIGNhY2hlZE9iajsKICAgICAgICAgIH0KICAgICAgICAgIG9iaiA9IGZyb21CaXRzKHZhbHVlLCB2YWx1ZSA8IDAgPyAtMSA6IDAsIGZhbHNlKTsKICAgICAgICAgIGlmIChjYWNoZSkKICAgICAgICAgICAgSU5UX0NBQ0hFW3ZhbHVlXSA9IG9iajsKICAgICAgICAgIHJldHVybiBvYmo7CiAgICAgICAgfQogICAgICB9CiAgICAgIExvbmc0LmZyb21JbnQgPSBmcm9tSW50OwogICAgICBmdW5jdGlvbiBmcm9tTnVtYmVyKHZhbHVlLCB1bnNpZ25lZCkgewogICAgICAgIGlmIChpc05hTih2YWx1ZSkpCiAgICAgICAgICByZXR1cm4gdW5zaWduZWQgPyBVWkVSTyA6IFpFUk87CiAgICAgICAgaWYgKHVuc2lnbmVkKSB7CiAgICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAodmFsdWUgPj0gVFdPX1BXUl82NF9EQkwpCiAgICAgICAgICAgIHJldHVybiBNQVhfVU5TSUdORURfVkFMVUU7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGlmICh2YWx1ZSA8PSAtVFdPX1BXUl82M19EQkwpCiAgICAgICAgICAgIHJldHVybiBNSU5fVkFMVUU7CiAgICAgICAgICBpZiAodmFsdWUgKyAxID49IFRXT19QV1JfNjNfREJMKQogICAgICAgICAgICByZXR1cm4gTUFYX1ZBTFVFOwogICAgICAgIH0KICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgcmV0dXJuIGZyb21OdW1iZXIoLXZhbHVlLCB1bnNpZ25lZCkubmVnKCk7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHZhbHVlICUgVFdPX1BXUl8zMl9EQkwgfCAwLCB2YWx1ZSAvIFRXT19QV1JfMzJfREJMIHwgMCwgdW5zaWduZWQpOwogICAgICB9CiAgICAgIExvbmc0LmZyb21OdW1iZXIgPSBmcm9tTnVtYmVyOwogICAgICBmdW5jdGlvbiBmcm9tQml0cyhsb3dCaXRzLCBoaWdoQml0cywgdW5zaWduZWQpIHsKICAgICAgICByZXR1cm4gbmV3IExvbmc0KGxvd0JpdHMsIGhpZ2hCaXRzLCB1bnNpZ25lZCk7CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbUJpdHMgPSBmcm9tQml0czsKICAgICAgdmFyIHBvd19kYmwgPSBNYXRoLnBvdzsKICAgICAgZnVuY3Rpb24gZnJvbVN0cmluZyhzdHIsIHVuc2lnbmVkLCByYWRpeCkgewogICAgICAgIGlmIChzdHIubGVuZ3RoID09PSAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImVtcHR5IHN0cmluZyIpOwogICAgICAgIGlmIChzdHIgPT09ICJOYU4iIHx8IHN0ciA9PT0gIkluZmluaXR5IiB8fCBzdHIgPT09ICIrSW5maW5pdHkiIHx8IHN0ciA9PT0gIi1JbmZpbml0eSIpCiAgICAgICAgICByZXR1cm4gWkVSTzsKICAgICAgICBpZiAodHlwZW9mIHVuc2lnbmVkID09PSAibnVtYmVyIikgewogICAgICAgICAgcmFkaXggPSB1bnNpZ25lZCwgdW5zaWduZWQgPSBmYWxzZTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdW5zaWduZWQgPSAhIXVuc2lnbmVkOwogICAgICAgIH0KICAgICAgICByYWRpeCA9IHJhZGl4IHx8IDEwOwogICAgICAgIGlmIChyYWRpeCA8IDIgfHwgMzYgPCByYWRpeCkKICAgICAgICAgIHRocm93IFJhbmdlRXJyb3IoInJhZGl4Iik7CiAgICAgICAgdmFyIHA7CiAgICAgICAgaWYgKChwID0gc3RyLmluZGV4T2YoIi0iKSkgPiAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImludGVyaW9yIGh5cGhlbiIpOwogICAgICAgIGVsc2UgaWYgKHAgPT09IDApIHsKICAgICAgICAgIHJldHVybiBmcm9tU3RyaW5nKHN0ci5zdWJzdHJpbmcoMSksIHVuc2lnbmVkLCByYWRpeCkubmVnKCk7CiAgICAgICAgfQogICAgICAgIHZhciByYWRpeFRvUG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIDgpKTsKICAgICAgICB2YXIgcmVzdWx0ID0gWkVSTzsKICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IHN0ci5sZW5ndGg7IGkgKz0gOCkgewogICAgICAgICAgdmFyIHNpemUgPSBNYXRoLm1pbig4LCBzdHIubGVuZ3RoIC0gaSksIHZhbHVlID0gcGFyc2VJbnQoc3RyLnN1YnN0cmluZyhpLCBpICsgc2l6ZSksIHJhZGl4KTsKICAgICAgICAgIGlmIChzaXplIDwgOCkgewogICAgICAgICAgICB2YXIgcG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIHNpemUpKTsKICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0Lm11bChwb3dlcikuYWRkKGZyb21OdW1iZXIodmFsdWUpKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdC5tdWwocmFkaXhUb1Bvd2VyKTsKICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0LmFkZChmcm9tTnVtYmVyKHZhbHVlKSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJlc3VsdC51bnNpZ25lZCA9IHVuc2lnb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pcy5oaWdoICogVFdPX1BXUl8zMl9EQkwgKyAodGhpcy5sb3cgPj4+IDApOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnRvU3RyaW5nID0gZnVuY3Rpb24gdG9TdHJpbmcocmFkaXgpIHsKICAgICAgICByYWRpeCA9IHJhZGl4IHx8IDEwOwogICAgICAgIGlmIChyYWRpeCA8IDIgfHwgMzYgPCByYWRpeCkKICAgICAgICAgIHRocm93IFJhbmdlRXJyb3IoInJhZGl4Iik7CiAgICAgICAgaWYgKHRoaXMuaXNaZXJvKCkpCiAgICAgICAgICByZXR1cm4gIjAiOwogICAgICAgIGlmICh0aGlzLmlzTmVnYXRpdmUoKSkgewogICAgICAgICAgaWYgKHRoaXMuZXEoTUlOX1ZBTFVFKSkgewogICAgICAgICAgICB2YXIgcmFkaXhMb25nID0gZnJvbU51bWJlcihyYWRpeCksIGRpdiA9IHRoaXMuZGl2KHJhZGl4TG9uZyksIHJlbTEgPSBkaXYubXVsKHJhZGl4TG9uZykuc3ViKHRoaXMpOwogICAgICAgICAgICByZXR1cm4gZGl2LnRvU3RyaW5nKHJhZGl4KSArIHJlbTEudG9JbnQoKS50b1N0cmluZyhyYWRpeCk7CiAgICAgICAgICB9IGVsc2UKICAgICAgICAgICAgcmV0dXJuICItIiArIHRoaXMubmVnKCkudG9TdHJpbmcocmFkaXgpOwogICAgICAgIH0KICAgICAgICB2YXIgcmFkaXhUb1Bvd2VyID0gZnJvbU51bWJlcihwb3dfZGJsKHJhZGl4LCA2KSwgdGhpcy51bnNpZ25lZCksIHJlbSA9IHRoaXM7CiAgICAgICAgdmFyIHJlc3VsdCA9ICIiOwogICAgICAgIHdoaWxlICh0cnVlKSB7CiAgICAgICAgICB2YXIgcmVtRGl2ID0gcmVtLmRpdihyYWRpeFRvUG93ZXIpLCBpbnR2YWwgPSByZW0uc3ViKHJlbURpdi5tdWwocmFkaXhUb1Bvd2VyKSkudG9JbnQoKSA+Pj4gMCwgZGlnaXRzID0gaW50dmF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1bmN0aW9uIGVxdWFscyhvdGhlcikgewogICAgICAgIGlmICghaXNMb25nKG90aGVyKSkKICAgICAgICAgIG90aGVyID0gZnJvbVZhbHVlKG90aGVyKTsKICAgICAgICBpZiAodGhpcy51bnNpZ25lZCAhPT0gb3RoZXIudW5zaWduZWQgJiYgdGhpcy5oaWdoID4+PiAzMSA9PT0gMSAmJiBvdGhlci5oaWdoID4+PiAzMSA9PT0gMSkKICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICByZXR1cm4gdGhpcy5oaWdoID09PSBvdGhlci5oaWdoICYmIHRoaXMubG93ID09PSBvdGhlci5sb3c7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZXEgPSBMb25nUHJvdG90eXBlLmVxdWFsczsKICAgICAgTG9uZ1Byb3RvdHlwZS5ub3RFcXVhbHMgPSBmdW5jdGlvbiBub3RFcXVhbHMob3RoZXIpIHsKICAgICAgICByZXR1cm4gIXRoaXMuZXEob3RoZXIpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm5lcSA9IExvbmdQcm90b3R5cGUubm90RXF1YWxzOwogICAgICBMb25nUHJvdG90eXBlLm5lID0gTG9uZ1Byb3RvdHlwZS5ub3RFcXVhbHM7CiAgICAgIExvbmdQcm90b3R5cGUubGVzc1RoYW4gPSBmdW5jdGlvbiBsZXNzVGhhbihvdGhlcikgewogICAgICAgIHJldHVybiB0aGlzLmNvbXAob3RoZXIpIDwgMDsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5sdCA9IExvbmdQcm90b3R5cGUubGVzc1RoYW47CiAgICAgIExvbmdQcm90b3R5cGUubGVzc1RoYW5PckVxdWFsID0gZnVuY3Rpb24gbGVzc1RoYW5PckVxdWFsKG90aGVyKSB7CiAgICAgICAgcmV0dXJuIHRoaXMuY29tcChvdGhlcikgPD0gMDsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5sdGUgPSBMb25nUHJvdG90eXBlLmxlc3NUa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pKQogICAgICAgICAgbXVsdGlwbGllciA9IGZyb21WYWx1ZShtdWx0aXBsaWVyKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgdmFyIGxvdyA9IHdhc20ubXVsKHRoaXMubG93LCB0aGlzLmhpZ2gsIG11bHRpcGxpZXIubG93LCBtdWx0aXBsaWVyLmhpZ2gpOwogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGxvdywgd2FzbS5nZXRfaGlnaCgpLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICB9CiAgICAgICAgaWYgKG11bHRpcGxpZXIuaXNaZXJvKCkpCiAgICAgICAgICByZXR1cm4gWkVSTzsKICAgICAgICBpZiAodGhpcy5lcShNSU5fVkFMVUUpKQogICAgICAgICAgcmV0dXJuIG11bHRpcGxpZXIuaXNPZGQoKSA/IE1JTl9WQUxVRSA6IFpFUk87CiAgICAgICAgaWYgKG11bHRpcGxpZXIuZXEoTUlOX1ZBTFVFKSkKICAgICAgICAgIHJldHVybiB0aGlzLmlzT2RkKCkgPyBNSU5fVkFMVUUgOiBaRVJPOwogICAgICAgIGlmICh0aGlzLmlzTmVnYXRpdmUoKSkgewogICAgICAgICAgaWYgKG11bHRpcGxpZXIuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgICByZXR1cm4gdGhpcy5uZWcoKS5tdWwobXVsdGlwbGllci5uZWcoKSk7CiAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHJldHVybiB0aGlzLm5lZygpLm11bChtdWx0aXBsaWVyKS5uZWcoKTsKICAgICAgICB9IGVsc2UgaWYgKG11bHRpcGxpZXIuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgcmV0dXJuIHRoaXMubXVsKG11bHRpcGxpZXIubmVnKCkpLm5lZygpOwogICAgICAgIGlmICh0aGlzLmx0KFRXT19QV1JfMjQpICYmIG11bHRpcGxpZXIubHQoVFdPX1BXUl8yNCkpCiAgICAgICAgICByZXR1cm4gZnJvbU51bWJlcih0aGlzLnRvTnVtYmV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51bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICB2YXIgYXBwcm94LCByZW0sIHJlczsKICAgICAgICBpZiAoIXRoaXMudW5zaWduZWQpIHsKICAgICAgICAgIGlmICh0aGlzLmVxKE1JTl9WQUxVRSkpIHsKICAgICAgICAgICAgaWYgKGRpdmlzb3IuZXEoT05FKSB8fCBkaXZpc29yLmVxKE5FR19PTkUpKQogICAgICAgICAgICAgIHJldHVybiBNSU5fVkFMVUU7CiAgICAgICAgICAgIGVsc2UgaWYgKGRpdmlzb3IuZXEoTUlOX1ZBTFVFKSkKICAgICAgICAgICAgICByZXR1cm4gT05FOwogICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICB2YXIgaGFsZlRoaXMgPSB0aGlzLnNocigxKTsKICAgICAgICAgICAgICBhcHByb3ggPSBoYWxmVGhpcy5kaXYoZGl2aXNvcikuc2hsKDEpOwogICAgICAgICAgICAgIGlmIChhcHByb3guZXEoWkVSTykpIHsKICAgICAgICAgICAgICAgIHJldHVybiBkaXZpc29yLmlzTmVnYXRpdmUoKSA/IE9ORSA6IE5FR19PTkU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHJlbSA9IHRoaXMuc3ViKGRpdmlzb3IubXVsKGFwcHJveCkpOwogICAgICAgICAgICAgICAgcmVzID0gYXBwcm94LmFkZChyZW0uZGl2KGRpdmlzb3IpKTsKICAgICAgICAgICAgICAgIHJldHVybiByZXM7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKGRpdmlzb3IuZXEoTUlOX1ZBTFVFKSkKICAgICAgICAgICAgcmV0dXJuIHRoaXMudW5zaWduZWQgPyBVWkVSTyA6IFpFUk87CiAgICAgICAgICBpZiAodGhpcy5pc05lZ2F0aXZlKCkpIHsKICAgICAgICAgICAgaWYgKGRpdmlzb3IuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgICAgIHJldHVybiB0aGlzLm5lZygpLmRpdihkaXZpc29yLm5lZygpKTsKICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVnKCkuZGl2KGRpdmlzb3IpLm5lZygpOwogICAgICAgICAgfSBlbHNlIGlmIChkaXZpc29yLmlzTmVnYXRpdmUoKSkKICAgICAgICAgICAgcmV0dXJuIHRoaXMuZGl2KGRpdmlzb3IubmVnKCkpLm5lZygpOwogICAgICAgICAgcmVzID0gWkVSTzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKCFkaXZpc29yLnVuc2lnbmVkKQogICAgICAgICAgICBkaXZpc29yID0gZGl2aXNvci50b1Vuc2lnbmVkKCk7CiAgICAgICAgICBpZiAoZGl2aXNvci5ndCh0aGlzKSkKICAgICAgICAgICAgcmV0dXJuIFVaRVJPOwogICAgICAgICAgaWYgKGRpdmlzb3IuZ3QodGhpcy5zaHJ1KDEpKSkKICAgICAgICAgICAgcmV0dXJuIFVPTkU7CiAgICAgICAgICByZXMgPSBVWkVSTzsKICAgICAgICB9CiAgICAgICAgcmVtID0gdGhpczsKICAgICAgICB3aGlsZSAocmVtLmd0ZShkaXZpc29yKSkgewogICAgICAgICAgYXBwcm94ID0gTWF0aC5tYXgoMSwgTWF0aC5mbG9vcihyZW0udG9OdW1iZXIoKSAvIGRpdmlzb3IudG9OdW1iZXIoKSkpOwogICAgICAgICAgdmFyIGxvZzIgPSBNYXRoLmNlaWwoTWF0aC5sb2coYXBwcm94KSAvIE1hdGguTE4yKSwgZGVsdGEgPSBsb2cyIDw9IDQ4ID8gMSA6IHBvd19kYmwoMiwgbG9nMiAtIDQ4KSwgYXBwcm94UmVzID0gZnJvbU51bWJlcihhcHByb3gpLCBhcHByb3hSZW0gPSBhcHByb3hSZXMubXVsKGRpdmlzb3IpOwogICAgICAgICAgd2hpbGUgKGFwcHJveFJlbS5pc05lZ2F0aXZlKCkgfHwgYXBwcm94UmVtLmd0KHJlbSkpIHsKICAgICAgICAgICAgYXBwcm94IC09IGRlbHRhOwogICAgICAgICAgICBhcHByb3hSZXMgPSBmcm9tTnVtYmVyKGFwcHJveCwgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgICAgIGFwcHJveFJlbSA9IGFwcHJveFJlcy5tdWwoZGl2aXNvcik7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYXBwcm94UmVzLmlzWmVybygpKQogICAgICAgICAgICBhcHByb3hSZXMgPSBPTkU7CiAgICAgICAgICByZXMgPSByZXMuYWRkKGFwcHJveFJlcyk7CiAgICAgICAgICByZW0gPSByZW0uc3ViKGFwcHJveFJlbSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZGl2ID0gTG9uZ1Byb3RvdHlwZS5kaXZpZGU7CiAgICAgIExvbmdQcm90b3R5cGUubW9kdWxvID0gZnVuY3Rpb24gbW9kdWxvKGRpdmlzb3IpIHsKICAgICAgICBpZiAoIWlzTG9uZyhkaXZpc29yKSkKICAgICAgICAgIGRpdmlzb3IgPSBmcm9tVmFsdWUoZGl2aXNvcik7CiAgICAgICAgaWYgKHdhc20pIHsKICAgICAgICAgIHZhciBsb3cgPSAodGhpcy51bnNpZ25lZCA/IHdhc20ucmVtX3UgOiB3YXNtLnJlbV9zKSh0aGlzLmxvdywgdGhpcy5oaWdoLCBkaXZpc29yLmxvdywgZGl2aXNvci5oaWdoKTsKICAgICAgICAgIHJldHVybiBmcm9tQml0cyhsb3csIHdhc20uZ2V0X2hpZ2goKSwgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0aGlzLnN1Yih0aGlzLmRpdihkaXZpc29yKS5tdWwoZGl2aXNvcikpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm1vZCA9IExvbmdQcm90b3R5cGUubW9kdWxvOwogICAgICBMb25nUHJvdG90eXBlLnJlbSA9IExvbmdQcm90b3R5cGUubW9kdWxvOwogICAgICBMb25nUHJvdG90eXBlLm5vdCA9IGZ1bm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ICAgIExvbmdQcm90b3R5cGUuc2hpZnRSaWdodFVuc2lnbmVkID0gZnVuY3Rpb24gc2hpZnRSaWdodFVuc2lnbmVkKG51bUJpdHMpIHsKICAgICAgICBpZiAoaXNMb25nKG51bUJpdHMpKQogICAgICAgICAgbnVtQml0cyA9IG51bUJpdHMudG9JbnQoKTsKICAgICAgICBudW1CaXRzICY9IDYzOwogICAgICAgIGlmIChudW1CaXRzID09PSAwKQogICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgZWxzZSB7CiAgICAgICAgICB2YXIgaGlnaCA9IHRoaXMuaGlnaDsKICAgICAgICAgIGlmIChudW1CaXRzIDwgMzIpIHsKICAgICAgICAgICAgdmFyIGxvdyA9IHRoaXMubG93OwogICAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93ID4+PiBudW1CaXRzIHwgaGlnaCA8PCAzMiAtIG51bUJpdHMsIGhpZ2ggPj4+IG51bUJpdHMsIHRoaXMudW5zaWduZWQpOwogICAgICAgICAgfSBlbHNlIGlmIChudW1CaXRzID09PSAzMikKICAgICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGhpZ2gsIDAsIHRoaXMudW5zaWduZWQpOwogICAgICAgICAgZWxzZQogICAgICAgICAgICByZXR1cm4gZnJvbUJpdHMoaGlnaCA+Pj4gbnVtQml0cyAtIDMyLCAwLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuc2hydSA9IExvbmdQcm90b3R5cGUuc2hpZnRSaWdodFVuc2lnbmVkOwogICAgICBMb25nUHJvdG90eXBlLnNocl91ID0gTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0VW5zaWduZWQ7CiAgICAgIExvbmdQcm90b3R5cGUudG9TaWduZWQgPSBmdW5jdGlvbiB0b1NpZ25lZCgpIHsKICAgICAgICBpZiAoIXRoaXMudW5zaWduZWQpCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3csIHRoaXMuaGlnaCwgZmFsc2UpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnRvVW5zaWduZWQgPSBmdW5jdGlvbiB0b1Vuc2lnbmVkKCkgewogICAgICAgIGlmICh0aGlzLnVuc2lnbmVkKQogICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93LCB0aGlzLmhpZ2gsIHRydWUpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnRvQnl0ZXMgPSBmdW5jdGlvbiB0b0J5dGVzKGxlKSB7CiAgICAgICAgcmV0dXJuIGxlID8gdGhpcy50b0J5dGVzTEUoKSA6IHRoaXMudG9CeXRlc0JFKCk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9CeXRlc0xFID0gZnVuY3Rpb24gdG9CeXRlc0xFKCkgewogICAgICAgIHZhciBoaSA9IHRoaXMuaGlnaCwgbG8gPSB0aGlzLmxvdzsKICAgICAgICByZXR1cm4gWwogICAgICAgICAgbG8gJiAyNTUsCiAgICAgICAgICBsbyA+Pj4gOCAmIDI1NSwKICAgICAgICAgIGxvID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGxvID4+PiAyNCwKICAgICAgICAgIGhpICYgMjU1LAogICAgICAgICAgaGkgPj4+IDggJiAyNTUsCiAgICAgICAgICBoaSA+Pj4gMTYgJiAyNTUsCiAgICAgICAgICBoaSA+Pj4gMjQKICAgICAgICBdOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnRvQnl0ZXNCRSA9IGZ1bmN0aW9uIHRvQnl0ZXNCRSgpIHsKICAgICAgICB2YXIgaGkgPSB0aGlzLmhpZ2gsIGxvID0gdGhpcy5sb3c7CiAgICAgICAgcmV0dXJuIFsKICAgICAgICAgIGhpID4+PiAyNCwKICAgICAgICAgIGhpID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGhpID4+PiA4ICYgMjU1L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JuIE9iamVjdC5hc3NpZ24oRXJyb3IobWVzc2FnZS5tZXNzYWdlKSwgewogICAgICAgICAgICBuYW1lOiBtZXNzYWdlLm5hbWUsCiAgICAgICAgICAgIHN0YWNrOiBtZXNzYWdlLnN0YWNrCiAgICAgICAgICB9KTsKICAgICAgICB9LAogICAgICAgIHNlcmlhbGl6ZShlcnJvcikgewogICAgICAgICAgcmV0dXJuIHsKICAgICAgICAgICAgX19lcnJvcl9tYXJrZXI6ICIkJGVycm9yIiwKICAgICAgICAgICAgbWVzc2FnZTogZXJyb3IubWVzc2FnZSwKICAgICAgICAgICAgbmFtZTogZXJyb3IubmFtZSwKICAgICAgICAgICAgc3RhY2s6IGVycm9yLnN0YWNrCiAgICAgICAgICB9OwogICAgICAgIH0KICAgICAgfTsKICAgICAgdmFyIGlzU2VyaWFsaXplZEVycm9yID0gKHRoaW5nKSA9PiB0aGluZyAmJiB0eXBlb2YgdGhpbmcgPT09ICJvYmplY3QiICYmICJfX2Vycm9yX21hcmtlciIgaW4gdGhpbmcgJiYgdGhpbmcuX19lcnJvcl9tYXJrZXIgPT09ICIkJGVycm9yIjsKICAgICAgZXhwb3J0czIuRGVmYXVsdFNlcmlhbGl6ZXIgPSB7CiAgICAgICAgZGVzZXJpYWxpemUobWVzc2FnZSkgewogICAgICAgICAgaWYgKGlzU2VyaWFsaXplZEVycm9yKG1lc3NhZ2UpKSB7CiAgICAgICAgICAgIHJldHVybiBEZWZhdWx0RXJyb3JTZXJpYWxpemVyLmRlc2VyaWFsaXplKG1lc3NhZ2UpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmV0dXJuIG1lc3NhZ2U7CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBzZXJpYWxpemUoaW5wdXQpIHsKICAgICAgICAgIGlmIChpbnB1dCBpbnN0YW5jZW9mIEVycm9yKSB7CiAgICAgICAgICAgIHJldHVybiBEZWZhdWx0RXJyb3JTZXJpYWxpemVyLnNlcmlhbGl6ZSh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3Rpb24gYWRvcHQodmFsdWUpIHsKICAgICAgICAgIHJldHVybiB2YWx1ZSBpbnN0YW5jZW9mIFAgPyB2YWx1ZSA6IG5ldyBQKGZ1bmN0aW9uKHJlc29sdmUpIHsKICAgICAgICAgICAgcmVzb2x2ZSh2YWx1ZSk7CiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG5ldyAoUCB8fCAoUCA9IFByb21pc2UpKShmdW5jdGlvbihyZXNvbHZlLCByZWplY3QpIHsKICAgICAgICAgIGZ1bmN0aW9uIGZ1bGZpbGxlZCh2YWx1ZSkgewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIHN0ZXAoZ2VuZXJhdG9yLm5leHQodmFsdWUpKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIHJlamVjdChlKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gcmVqZWN0ZWQodmFsdWUpIHsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBzdGVwKGdlbmVyYXRvclsidGhyb3ciXSh2YWx1ZSkpOwogICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgcmVqZWN0KGUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBzdGVwKHJlc3VsdCkgewogICAgICAgICAgICByZXN1bHQuZG9uZSA/IHJlc29sdmUocmVzdWx0LnZhbHVlKSA6IGFkb3B0KHJlc3VsdC52YWx1ZSkudGhlbihmdWxmaWxsZWQsIHJlamVjdGVkKTsKICAgICAgICAgIH0KICAgICAgICAgIHN0ZXAoKGdlbmVyYXRvciA9IGdlbmVyYXRvci5hcHBseSh0aGlzQXJnLCBfYXJndW1lbnRzIHx8IFtdKSkubmV4dCgpKTsKICAgICAgICB9KTsKICAgICAgfTsKICAgICAgdmFyIF9faW1wb3J0RGVmYXVsdCA9IGV4cG9ydHMyICYmIGV4cG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aW5nICR7aW5wdXR9IHRvIGF0dGVtcHQgdG8gd29yayBhcm91bmQgY2hyb21lIENPUlMgaGVhZGVyIGNhY2hpbmcgYnVnYCk7CiAgICAgICAgICByZXNwb25zZSA9IGF3YWl0IHRoaXMuZmV0Y2hJbXBsZW1lbnRhdGlvbihpbnB1dCwgewogICAgICAgICAgICAuLi5pbml0MiwKICAgICAgICAgICAgY2FjaGU6ICJyZWxvYWQiCiAgICAgICAgICB9KTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdGhyb3cgZTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIHJlc3BvbnNlOwogICAgfQogICAgYXN5bmMgcmVhZChidWZmZXIsIG9mZnNldCA9IDAsIGxlbmd0aCwgcG9zaXRpb24gPSAwLCBvcHRzID0ge30pIHsKICAgICAgY29uc3QgeyBoZWFkZXJzID0ge30sIHNpZ25hbCwgb3ZlcnJpZGVzID0ge30gfSA9IG9wdHM7CiAgICAgIGlmIChsZW5ndGggPCBJbmZpbml0eSkgewogICAgICAgIGhlYWRlcnMucmFuZ2UgPSBgYnl0ZXM9JHtwb3NpdGlvbn0tJHtwb3NpdGlvbiArIGxlbmd0aH1gOwogICAgICB9IGVsc2UgaWYgKGxlbmd0aCA9PT0gSW5maW5pdHkgJiYgcG9zaXRpb24gIT09IDApIHsKICAgICAgICBoZWFkZXJzLnJhbmdlID0gYGJ5dGVzPSR7cG9zaXRpb259LWA7CiAgICAgIH0KICAgICAgY29uc3QgYXJncyA9IHsKICAgICAgICAuLi50aGlzLmJhc2VPdmVycmlkZXMsCiAgICAgICAgLi4ub3ZlcnJpZGVzLAogICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgIC4uLmhlYWRlcnMsCiAgICAgICAgICAuLi5vdmVycmlkZXMuaGVhZGVycywKICAgICAgICAgIC4uLnRoaXMuYmFzZU92ZXJyaWRlcy5oZWFkZXJzCiAgICAgICAgfSwKICAgICAgICBtZXRob2Q6ICJHRVQiLAogICAgICAgI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AgdGhyb3cgbmV3IEVycm9yKCIke3RoaXMudXJsfSBmZXRjaCByZXR1cm5lZCBzdGF0dXMgMjAwLCBleHBlY3RlZCAyMDYiKTsKICAgICAgfQogICAgICB0aHJvdyBuZXcgRXJyb3IoYEhUVFAgJHtyZXNwb25zZS5zdGF0dXN9IGZldGNoaW5nICR7dGhpcy51cmx9YCk7CiAgICB9CiAgICBhc3luYyByZWFkRmlsZShvcHRpb25zID0ge30pIHsKICAgICAgbGV0IGVuY29kaW5nOwogICAgICBsZXQgb3B0czsKICAgICAgaWYgKHR5cGVvZiBvcHRpb25zID09PSAic3RyaW5nIikgewogICAgICAgIGVuY29kaW5nID0gb3B0aW9uczsKICAgICAgICBvcHRzID0ge307CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZW5jb2RpbmcgPSBvcHRpb25zLmVuY29kaW5nOwogICAgICAgIG9wdHMgPSBvcHRpb25zOwogICAgICAgIGRlbGV0ZSBvcHRzLmVuY29kaW5nOwogICAgICB9CiAgICAgIGNvbnN0IHsgaGVhZGVycyA9IHt9LCBzaWduYWwsIG92ZXJyaWRlcyA9IHt9IH0gPSBvcHRzOwogICAgICBjb25zdCBhcmdzID0gewogICAgICAgIGhlYWRlcnMsCiAgICAgICAgbWV0aG9kOiAiR0VUIiwKICAgICAgICByZWRpcmVjdDogImZvbGxvdyIsCiAgICAgICAgbW9kZTogImNvcnMiLAogICAgICAgIHNpZ25hbCwKICAgICAgICAuLi50aGlzLmJhc2VPdmVycmlkZXMsCiAgICAgICAgLi4ub3ZlcnJpZGVzCiAgICAgIH07CiAgICAgIGNvbnN0IHJlc3BvbnNlID0gYXdhaXQgdGhpcy5mZXRjaCh0aGlzLnVybCwgYXJncyk7CiAgICAgIGlmICghcmVzcG9uc2UpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImdlbmVyaWMtZmlsZWhhbmRsZSBmYWlsZWQgdG8gZmV0Y2giKTsKICAgICAgfQogICAgICBpZiAocmVzcG9uc2Uuc3Rhd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CiAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJwcm9ibGVtIGRlY29tcHJlc3NpbmcgYmxvY2s6IGluY29ycmVjdCBnemlwIGhlYWRlciBjaGVjayIpOwogICAgICB9CiAgICAgIHRocm93IGU7CiAgICB9CiAgfQogIGFzeW5jIGZ1bmN0aW9uIHVuemlwQ2h1bmtTbGljZShpbnB1dERhdGEsIGNodW5rKSB7CiAgICB0cnkgewogICAgICBsZXQgc3RybTsKICAgICAgY29uc3QgeyBtaW52LCBtYXh2IH0gPSBjaHVuazsKICAgICAgbGV0IGNwb3MgPSBtaW52LmJsb2NrUG9zaXRpb247CiAgICAgIGxldCBkcG9zID0gbWludi5kYXRhUG9zaXRpb247CiAgICAgIGNvbnN0IGNodW5rcyA9IFtdOwogICAgICBjb25zdCBjcG9zaXRpb25zID0gW107CiAgICAgIGNvbnN0IGRwb3NpdGlvbnMgPSBbXTsKICAgICAgbGV0IHRvdGFsU2l6ZSA9IDA7CiAgICAgIGxldCBpID0gMDsKICAgICAgZG8gewogICAgICAgIGNvbnN0IHJlbWFpbmluZ0lucHV0ID0gaW5wdXREYXRhLnN1YmFycmF5KGNwb3MgLSBtaW52LmJsb2NrUG9zaXRpb24pOwogICAgICAgIGNvbnN0IGluZmxhdG9yID0gbmV3IGltcG9ydF9wYWtvLkluZmxhdGUoKTsKICAgICAgICAoeyBzdHJtIH0gPSBpbmZsYXRvcik7CiAgICAgICAgaW5mbGF0b3IucHVzaChyZW1haW5pbmdJbnB1dCwgaW1wb3J0X3Bha28uWl9TWU5DX0ZMVVNIKTsKICAgICAgICBpZiAoaW5mbGF0b3IuZXJyKSB7CiAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoaW5mbGF0b3IubXNnKTsKICAgICAgICB9CiAgICAgICAgY29uc3QgYnVmZmVyMiA9IGluZmxhdG9yLnJlc3VsdDsKICAgICAgICBjaHVua3MucHVzaChidWZmZXIyKTsKICAgICAgICBsZXQgbGVuID0gYnVmZmVyMi5sZW5ndG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mdW5jdGlvbihjMCwgYzEpIHsKICAgICAgY29uc3QgZGlmID0gYzAubWludi5ibG9ja1Bvc2l0aW9uIC0gYzEubWludi5ibG9ja1Bvc2l0aW9uOwogICAgICBpZiAoZGlmICE9PSAwKSB7CiAgICAgICAgcmV0dXJuIGRpZjsKICAgICAgfSBlbHNlIHsKICAgICAgICByZXR1cm4gYzAubWludi5kYXRhUG9zaXRpb24gLSBjMS5taW52LmRhdGFQb3NpdGlvbjsKICAgICAgfQogICAgfSk7CiAgICBjaHVua3MuZm9yRWFjaCgoY2h1bmspID0+IHsKICAgICAgaWYgKCFsb3dlc3QgfHwgY2h1bmsubWF4di5jb21wYXJlVG8obG93ZXN0KSA+IDApIHsKICAgICAgICBpZiAobGFzdENodW5rID09PSBudWxsKSB7CiAgICAgICAgICBtZXJnZWRDaHVua3MucHVzaChjaHVuayk7CiAgICAgICAgICBsYXN0Q2h1bmsgPSBjaHVuazsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKGNhbk1lcmdlQmxvY2tzKGxhc3RDaHVuaywgY2h1bmspKSB7CiAgICAgICAgICAgIGlmIChjaHVuay5tYXh2LmNvbXBhcmVUbyhsYXN0Q2h1bmsubWF4dikgPiAwKSB7CiAgICAgICAgICAgICAgbGFzdENodW5rLm1heHYgPSBjaHVuay5tYXh2OwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtZXJnZWRDaHVua3MucHVzaChjaHVuayk7CiAgICAgICAgICAgIGxhc3RDaHVuayA9IGNodW5rOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgfSk7CiAgICByZXR1cm4gbWVyZ2VkQ2h1bmtzOwogIH0KCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL0BnbW9kK3RhYml4QDEuNS4xMS9ub2RlX21vZHVsZXMvQGdtb2QvdGFiaXgvZXNtL3RiaS5qcwogIGluaXRfYnVmZmVyX3NoaW0oKTsKICB2YXIgaW1wb3J0X2xv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2h1bmtDb3VudCA9PT0gMikgewogICAgICAgICAgICAgIHN0YXRzID0gdGhpcy5wYXJzZVBzZXVkb0JpbihieXRlcywgY3Vyck9mZnNldCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNiAqIGNodW5rQ291bnQ7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjb25zdCBjaHVua0NvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgICAgIGN1cnJPZmZzZXQgKz0gNDsKICAgICAgICAgICAgY29uc3QgY2h1bmtzID0gbmV3IEFycmF5KGNodW5rQ291bnQpOwogICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGNodW5rQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgICAgIGNvbnN0IHUgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgICAgIGNvbnN0IHYgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQgKyA4KTsKICAgICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDE2OwogICAgICAgICAgICAgIGZpcnN0RGF0YUxpbmUgPSB0aGlzLl9maW5kRmlyc3REYXRhKGZpcnN0RGF0YUxpbmUsIHUpOwogICAgICAgICAgICAgIGNodW5rc1trXSA9IG5ldyBDaHVuayh1LCB2LCBiaW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJpbkluZGV4W2Jpbl0gPSBjaHVua3M7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvbnN0IGxpbmVhckNvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgIGNvbnN0IGxpbmVhckluZGV4ID0gbmV3IEFycmF5KGxpbmVhckNvdW50KTsKICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbmVhckNvdW50OyBr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gcmVmTmFtZVRvSWQgPSB7fTsKICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBuYW1lc0J5dGVzLmxlbmd0aDsgaSArPSAxKSB7CiAgICAgICAgaWYgKCFuYW1lc0J5dGVzW2ldKSB7CiAgICAgICAgICBpZiAoY3Vyck5hbWVTdGFydCA8IGkpIHsKICAgICAgICAgICAgbGV0IHJlZk5hbWUgPSBuYW1lc0J5dGVzLnRvU3RyaW5nKCJ1dGY4IiwgY3Vyck5hbWVTdGFydCwgaSk7CiAgICAgICAgICAgIHJlZk5hbWUgPSB0aGlzLnJlbmFtZVJlZlNlcShyZWZOYW1lKTsKICAgICAgICAgICAgcmVmSWRUb05hbWVbY3VyclJlZklkXSA9IHJlZk5hbWU7CiAgICAgICAgICAgIHJlZk5hbWVUb0lkW3JlZk5hbWVdID0gY3VyclJlZklkOwogICAgICAgICAgfQogICAgICAgICAgY3Vyck5hbWVTdGFydCA9IGkgKyAxOwogICAgICAgICAgY3VyclJlZklkICs9IDE7CiAgICAgICAgfQogICAgICB9CiAgICAgIHJldHVybiB7IHJlZk5hbWVUb0lkLCByZWZJZFRvTmFtZSB9OwogICAgfQogICAgYXN5bmMgYmxvY2tzRm9yUmFuZ2UocmVmTmFtZSwgbWluLCBtYXgsIG9wdHMgPSB7fSkgewogICAgICBpZiAobWluIDwgMCkgewogICAgICAgIG1pbiA9IDA7CiAgICAgIH0KICAgICAgY29uc3QgaW5kZXhEYXRhID0gYXdhaXQgdGhpcy5wYXJzZShvcHRzKTsKICAgICAgaWYgKCFpbmRleERhdGEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3QgcmVmSWQgPSBpbmRleERhdGEucmVmTmFtZVRvSWRbcmVmTmFtZV07CiAgICAgIGNvbnN0IGJhID0gaW5kZXhEYXRhLmluZGljZXNbcmVmSWRdOwogICAgICBpZiAoIWJhKSB7CiAgICAgICAgcmV0dXJuIFtdOwogICAgICB9CiAgICAgIGNvbnN0IG1pbk9mZnNldCA9IGJhLmxpbmVhckluZGV4Lmxlbmd0aCA/IGJhLmxpbmVhckluZGV4W21pbiA+PiBUQURfTElEWF9TSElGVCA+PSBiYS5saW5lYXJJbmRleC5sZW5ndGggPyBiYS5saW5lYXJJbmRleC5sZW5ndGggLSAxIDogbWluID4+IFRBRF9MSURYX1NISUZUXSA6IG5ldyBWaXJ0dWFsT2Zmc2V0KDAsIDApOwogICAgICBpZiAoIW1pbk9mZnNldCkgewogICAgICAgIGNvbnNvbGUud2FybigicXVlcnlpbmcgb3V0c2lkZSBvZiBwb3NzaWJsZSB0YWJpeCByYW5nZSIpOwogICAgICB9CiAgICAgIGNvbnN0IG92ZXJsYXBwaW5nQmlucyA9IHJlZzJiaW5zKG1pbiwgbWF4KTsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGZvciAoY29uc3QgW3N0YXJ0LCBlbmRdIG9mIG92ZXJsYXBwaW5nQmlucykgewogICAgICAgIGZvciAobGV0IGJpbiA9IHN0YXJ0OyBiaW4gPD0gZW5kOyBiaW4rKykgewogICAgICAgICAgaWYgKGJhLmJpbkluZGV4W2Jpbl0pIHsKICAgICAgICAgICAgY29uc3QgYmluQ2h1bmtzID0gYmEuYmluSW5kZXhbYmluXTsKICAgICAgICAgICAgZm9yIChsZXQgYyA9IDA7IGMgPCBiaW5DaHVua3MubGVuZ3RoOyArK2MpIHsKICAgICAgICAgICAgICBjaHVua3MucHVzaChuZXcgQ2h1bmsoYmluQ2h1bmtzW2NdLm1pbnYsIGJpbkNodW5rc1tjXS5tYXh2LCBiaW4pKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBjb25zdCBuaW50diA9IGJhLmxpbmVhckluZGV4Lmxlbmd0aDsKICAgICAgbGV0IGxvd2VzdCA9IG51bGw7CiAgICAgIGNvbnN0IG1pbkxpbiA9IE1hdGgubWluKG1pbiA+PiAxNCwgbmludHYgLSAxKTsKICAgICAgY29uc3QgbWF4TGluID0gTWF0aC5taW4obWF4ID4+IDE0LCBuaW50diAtIDEpOwogICAgICBmb3IgKGxldCBpID0gbWluTGluOyBpIDw9IG1heExpbjsgKytpKSB7CiAgICAgICAgY29uc3QgdnAgPSBiYS5saW5lYXJJbmRleFtpXTsKICAgICAgICBpZiAodnApIHsKICAgICAgICAgIGlmICghbG93ZXN0IHx8IHZwLmNvbXBhcmVUbyhsb3dlc3QpIDwgMCkgewogICAgICAgICAgICBsb3dlc3QgPSB2cDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIG9wdGltaXplQ2h1bmtzKGNodW5rcywgbG93ZXN0KTsKICAgIH0KICB9OwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vQGdtb2QrdGFiaXhAMS41LjExL25vZGVfbW9kdWxlcy9AZ21vZC90YWJpeC9lc20vY3NpLmpzCiAgaW5pdF9idWZmZXJfc2hpbSgpOwogIHZhciBpbXBvcnRfbG9uZzMgPSBfX3RvTW9kdWxlKHJlcXVpcmVfbG9uZygpKTsKICB2YXIgQ1NJMV9NQUdJQyA9IDIxNTgyNjU5OwogIHZhciBDU0kyX01BR0lDID0gMzgzNTk4NzU7CiAgZnVuY3Rpb24gbHNoaWZ0KG51bSwgYml0cykgewogICAgcmV0dXJuIG51bSAqIDIgKiogYml0czsKICB9CiAgZnVuY3Rpb24gcnNoaWZ0KG51bSwgYml0cykgewogICAgcmV0dXJuIE1hdGguZmxvb3IobnVtIC8gMiAqKiBiaXRzKTsKICB9CiAgdmFyIENTSSA9IGNsYXNzIGV4dGVuZHMgSW5kZXhGaWxlIHsKICAgIGNvbnN0cnVjdG9yKGFyZ3MpIHsKICAgICAgc3VwZXIoYXJncyk7CiAgICAgIHRoaXMubWF4QmluTnVtYmVyID0gMDsKICAgICAgdGhpcy5kZXB0aCA9IDA7CiAgICAgIHRoaXMubWluU2hpZnQgPSAwOwogICAgfQogICAgYXN5bmMgbGluZUNvdW50KHJlZk5hbWUsIG9wdHM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zdCBiaW5JbmRleCA9IHt9OwogICAgICAgIGxldCBzdGF0czsKICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IGJpbkNvdW50OyBqICs9IDEpIHsKICAgICAgICAgIGNvbnN0IGJpbiA9IGJ5dGVzLnJlYWRVSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgIGlmIChiaW4gPiB0aGlzLm1heEJpbk51bWJlcikgewogICAgICAgICAgICBzdGF0cyA9IHRoaXMucGFyc2VQc2V1ZG9CaW4oYnl0ZXMsIGN1cnJPZmZzZXQgKyA0KTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSA0ICsgOCArIDQgKyAxNiArIDE2OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY29uc3QgbG9mZnNldCA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCArIDQpOwogICAgICAgICAgICBmaXJzdERhdGFMaW5lID0gdGhpcy5fZmluZEZpcnN0RGF0YShmaXJzdERhdGFMaW5lLCBsb2Zmc2V0KTsKICAgICAgICAgICAgY29uc3QgY2h1bmtDb3VudCA9IGJ5dGVzLnJlYWRJbnQzMkxFKGN1cnJPZmZzZXQgKyAxMik7CiAgICAgICAgICAgIGN1cnJPZmZzZXQgKz0gMTY7CiAgICAgICAgICAgIGNvbnN0IGNodW5rcyA9IG5ldyBBcnJheShjaHVua0NvdW50KTsKICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBjaHVua0NvdW50OyBrICs9IDEpIHsKICAgICAgICAgICAgICBjb25zdCB1ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgICBjb25zdCB2ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0ICsgOCk7CiAgICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgICBjaHVua3Nba10gPSBuZXcgQ2h1bmsodSwgdiwgYmluKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBiaW5JbmRleFtiaW5dID0gY2h1bmtzOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4geyBiaW5JbmRleCwgc3RhdHMgfTsKICAgICAgfSk7CiAgICAgIHJldHVybiB7CiAgICAgICAgLi4uYXV4LAogICAgICAgIGNzaTogdHJ1ZSwKICAgICAgICByZWZDb3VudCwKICAgICAgICBtYXhCbG9ja1NpemU6IDEgPDwgMTYsCiAgICAgICAgZmlyc3REYXRhTGluZSwKICAgICAgICBjc2lWZXJzaW9uLAogICAgICAgIGluZGljZXMsCiAgICAgICAgZGVwdGg6IHRoaXMuZGVwdGgsCiAgICAgICAgbWF4QmluTnVtYmVyOiB0aGlzLm1heEJpbk51bWJlciwKICAgICAgICBtYXhSZWZMZW5ndGgKICAgICAgfTsKICAgIH0KICAgIHBhcnNlUHNldWRvQmluKGJ5dGVzLCBvZmZzZXQpIHsKICAgICAgY29uc3QgbGluZUNvdW50ID0gbG9uZ1RvTnVtYmVyKGltcG9ydF9sb25nMy5kZWZhdWx0LmZyb21CeXRlc0xFKGJ5dGVzLnNsaWNlKG9mZnNldCArIDI4LCBvZmZzZXQgKyAzNiksIHRydWUpKTsKICAgICAgcmV0dXJuIHsgbGluZUNvdW50IH07CiAgICB9CiAgICBhc3luYyBibG9ja3NGb3JSYW5nZShyZWZOYW1lLCBtaW4sIG1heCwgb3B0cyA9IHt9KSB7CiAgICAgIGlmIChtaW4gPCAwKSB7CiAgICAgICAgbWluID0gMDsKICAgICAgfQogICAgICBjb25zdCBpbmRleERhdGEgPSBhd2FpdCB0aGlzLnBhcnNlKG9wdHMpOwogICAgICBpZiAoIWluZGV4RGF0YSkgewogICAgICAgIHJldHVybiBbXTsKICAgICAgfQogICAgICBjb25zdCByZWZJZCA9IGluZGV4RGF0YS5yZWZOYW1lVG9JZFtyZWZOYW1lXTsKICAgICAgY29uc3QgYmEgPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmICghYmEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3Qgb3ZlcmxhcHBpbmdCaW5zID0gdGhpcy5yZWcyYmlucyhtaW4sIG1heCk7CiAgICAgIGNvbnN0IGNodW5rcyA9IFtdOwogICAgICBmb3IgKGNvbnN0IFtzdGFydCwgZW5kXSBvZiBvdmVybGFwcGluZ0JpbnMpIHsKICAgICAgICBmb3IgKGxldCBiaW4gPSBzdGFydDsgYmluIDw9IGVuZDsgYmluKyspIHsKICAgICAgICAgIGlmIChiYS5iaW5JbmRleFtiaW5dKSB7CiAgICAgICAgICAgIGNvbnN0IGJpbkNodW5rcyA9IGJhLmJpbkluZGV4W2Jpbl07CiAgICAgICAgICAgIGZvciAobGV0IGMgPSAwOyBjIDwgYmluQ2h1bmtzLmxlbmd0aDsgKytjKSB7CiAgICAgICAgICAgICAgY2h1bmtzLnB1c2gobmV3IENodW5rKGJpbkNodW5rc1tjXS5taW52LCBiaW5DaHVua3NbY10ubWF4diwgYmluKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIG9wdGltaXplQ2h1bmtzKGNodW5rcywgbmV3IFZpcnR1YWxPZmZzZXQoMCwgMCkpOwogICAgfQogICAgcmVnMmJpbnMoYmVnLCBlbmQpIHsKICAgICAgYmVnIC09IDE7CiAgICAgIGlmIChiZWcgPCAxKSB7CiAgICAgICAgYmVnID0gMTsKICAgICAgfQogICAgICBpZiAoZW5kID4gMiAqKiA1MCkgewogICAgICAgIGVuZCA9IDIgKiogMzQ7CiAgICAgIH0KICAgICAgZW5kIC09IDE7CiAgICAgIGxldCBsID0gMDsKICAgICAgbGV0IHQgPSAwOwogICAgICBsZXQgcyA9IHRoaXMubWluU2hpZnQgKyB0aGlzLmRlcHRoICogMzsKICAgICAgY29uc3QgYmlucyA9IFtdOwogICAgICBmb3IgKDsgbCA8PSB0aGlzLmRlcHRoOyBzIC09IDMsIHQgKz0gbH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ge307CiAgICAgIGxldCBjYWxsYmFjazsKICAgICAgaWYgKHR5cGVvZiBvcHRzID09PSAidW5kZWZpbmVkIikgewogICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoImxpbmUgY2FsbGJhY2sgbXVzdCBiZSBwcm92aWRlZCIpOwogICAgICB9CiAgICAgIGlmICh0eXBlb2Ygb3B0cyA9PT0gImZ1bmN0aW9uIikgewogICAgICAgIGNhbGxiYWNrID0gb3B0czsKICAgICAgfSBlbHNlIHsKICAgICAgICBvcHRpb25zID0gb3B0czsKICAgICAgICBjYWxsYmFjayA9IG9wdHMubGluZUNhbGxiYWNrOwogICAgICB9CiAgICAgIGlmIChyZWZOYW1lID09PSB2b2lkIDApIHsKICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJtdXN0IHByb3ZpZGUgYSByZWZlcmVuY2Ugc2VxdWVuY2UgbmFtZSIpOwogICAgICB9CiAgICAgIGlmICghY2FsbGJhY2spIHsKICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJsaW5lIGNhbGxiYWNrIG11c3QgYmUgcHJvdmlkZWQiKTsKICAgICAgfQogICAgICBjb25zdCBtZXRhZGF0YSA9IGF3YWl0IHRoaXMuaW5kZXguZ2V0TWV0YWRhdGEob3B0aW9ucyk7CiAgICAgIGNoZWNrQWJvcnRTaWduYWwoc2lnbmFsKTsKICAgICAgaWYgKCFzdGFydCkgewogICAgICAgIHN0YXJ0ID0gMDsKICAgICAgfQogICAgICBpZiAoIWVuZCkgewogICAgICAgIGVuZCA9IG1ldGFkYXRhLm1heFJlZkxlbmd0aDsKICAgICAgfQogICAgICBpZiAoIShzdGFydCA8PSBlbmQpKSB7CiAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiaW52YWxpZCBzdGFydCBhbmQgZW5kIGNvb3JkaW5hdGVzLiBzdGFydCBtdXN0IGJlIGxlc3MgdGhhbiBvciBlcXVhbCB0byBlbmQiKTsKICAgICAgfQogICAgICBpZiAoc3Rh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RhcnQgPCBidWZmZXIubGVuZ3RoKSB7CiAgICAgICAgICBjb25zdCBuID0gYnVmZmVyLmluZGV4T2YoIlxuIiwgYmxvY2tTdGFydCk7CiAgICAgICAgICBpZiAobiA9PT0gLTEpIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBjb25zdCBiID0gYnVmZmVyLnNsaWNlKGJsb2NrU3RhcnQsIG4pOwogICAgICAgICAgY29uc3QgbGluZSA9IChkZWNvZGVyID09PSBudWxsIHx8IGRlY29kZXIgPT09IHZvaWQgMCA/IHZvaWQgMCA6IGRlY29kZXIuZGVjb2RlKGIpKSB8fCBiLnRvU3RyaW5nKCk7CiAgICAgICAgICBpZiAoZHBvc2l0aW9ucykgewogICAgICAgICAgICB3aGlsZSAoYmxvY2tTdGFydCArIGMubWludi5kYXRhUG9zaXRpb24gPj0gZHBvc2l0aW9uc1twb3MrK10pIHsKICAgICAgICAgICAgfQogICAgICAgICAgICBwb3MtLTsKICAgICAgICAgIH0KICAgICAgICAgIGNvbnN0IHsgc3RhcnRDb29yZGluYXRlLCBvdmVybGFwcyB9ID0gdGhpcy5jaGVja0xpbmUobWV0YWRhdGEsIHJlZk5hbWUsIHN0YXJ0LCBlbmQsIGxpbmUpOwogICAgICAgICAgaWYgKHByZXZpb3VzU3RhcnRDb29yZGluYXRlICE9PSB2b2lkIDAgJiYgc3RhcnRDb29yZGluYXRlICE9PSB2b2lkIDAgJiYgcHJldmlvdXNTdGFydENvb3JkaW5hdGUgPiBzdGFydENvb3JkaW5hdGUpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGBMaW5lcyBub3Qgc29ydGVkIGJ5IHN0YXJ0IGNvb3JkaW5hdGUgKCR7cHJldmlvdXNTdGFydENvb3JkaW5hdGV9ID4gJHtzdGFydENvb3JkaW5hdGV9KSwgdGhpcyBmaWxlIGlzIG5vdCB1c2FibGUgd2l0aCBUYWJpeC5gKTsKICAgICAgICAgIH0KICAgICAgICAgIHByZXZpb3VzU3RhcnRDb29yZGluYXRlID0gc3RhcnRDb29yZGluYXRlOwogICAgICAgICAgaWYgKG92ZXJsYXBzKSB7CiAgICAgICAgICAgIGNhbGxiYWNrKGxpbmUudHJpbSgpLCBjcG9zaXRpb25zW3Bvc10gKiAoMSA8PCA4KSArIChibG9ja1N0YXJ0IC0gZHBvc2l0aW9uc1twb3NdKSArIGMubWludi5kYXRhUG9zaXRpb24gKyAxKTsKICAgICAgICAgIH0gZWxzZSBpZiAoc3RhcnRDb29yZGluYXRlICE9PSB2b2lkIDAgJiYgc3RhcnRDb29yZGluYXRlID49IGVuZCkgewogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodGhpcy55aWVsZFRpbWUgJiYgbGFzdCAtIERhdGUubm93KCkgPiB0aGlzLnlpZWxkVGltZSkgewogICAgICAgICAgICBsYXN0ID0gRGF0ZS5ub3coKTsKICAgICAgICAgICAgY2hlY2tBYm9ydFNpZ25hbChzaWduYWwpOwogICAgICAgICAgICBhd2FpdCB0aW1lb3V0KDEpOwogICAgICAgICAgfQogICAgICAgICAgYmxvY2tTdGFydCA9IG4gKyAxOwogICAgICAgIH0KICAgICAgfQogICAgfQogICAgYXN5bmMgZ2V0TWV0YWRhdGEob3B0cyA9IHt9KSB7CiAgICAgIHJldHVybiB0aGlzLmluZGV4LmdldE1ldGFkYXRhKG9wdHMpOwogICAgfQogICAgYXN5bmMgZ2V0SGVhZGVyQnVmZmVyKG9wdHMgPSB7fSkgewogICAgICBjb25zdCB7IGZpcnN0RGF0YUxpbmUsIG1ldGFDaGFyLCBtYXhCbG9ja1NpemUgfSA9IGF3YWl0IHRoaXMuZ2V0TWV0YWRhdGEob3B0cyk7CiAgICAgIGNoZWNrQWJvcnRTaWduYWwob3B0cy5zaWduYWwpOwogICAgICBjb25zdCBtYXhGZXRjaCA9ICgoZmlyc3REYXRhTGluZSA9PT0gbnVsbCB8fCBmaXJzdERhdGFMaW5lID09PSB2b2l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HVtblN0YXJ0ID0gMDsKICAgICAgbGV0IHJlZlNlcSA9ICIiOwogICAgICBsZXQgc3RhcnRDb29yZGluYXRlID0gLUluZmluaXR5OwogICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxpbmUubGVuZ3RoICsgMTsgaSArPSAxKSB7CiAgICAgICAgaWYgKGxpbmVbaV0gPT09ICIJIiB8fCBpID09PSBsaW5lLmxlbmd0aCkgewogICAgICAgICAgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPT09IHJlZikgewogICAgICAgICAgICBpZiAodGhpcy5yZW5hbWVSZWZTZXEobGluZS5zbGljZShjdXJyZW50Q29sdW1uU3RhcnQsIGkpKSAhPT0gcmVnaW9uUmVmTmFtZSkgewogICAgICAgICAgICAgIHJldHVybiB7IG92ZXJsYXBzOiBmYWxzZSB9OwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPT09IHN0YXJ0KSB7CiAgICAgICAgICAgIHN0YXJ0Q29vcmRpbmF0ZSA9IHBhcnNlSW50KGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKSwgMTApOwogICAgICAgICAgICBpZiAoY29vcmRpbmF0ZVR5cGUgPT09ICIxLWJhc2VkLWNsb3NlZCIpIHsKICAgICAgICAgICAgICBzdGFydENvb3JkaW5hdGUgLT0gMTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoc3RhcnRDb29yZGluYXRlID49IHJlZ2lvbkVuZCkgewogICAgICAgICAgICAgIHJldHVybiB7IHN0YXJ0Q29vcmRpbmF0ZSwgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGVuZCA9PT0gMCB8fCBlbmQgPT09IHN0YXJ0KSB7CiAgICAgICAgICAgICAgaWYgKHN0YXJ0Q29vcmRpbmF0ZSArIDEgPD0gcmVnaW9uU3RhcnQpIHsKICAgICAgICAgICAgICAgIHJldHVybiB7IHN0YXJ0Q29vcmRpbmF0ZSwgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKGZvcm1hdCA9PT0gIlZDRiIgJiYgY3VycmVudENvbHVtbk51bWJlciA9PT0gNCkgewogICAgICAgICAgICByZWZTZXEgPSBsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSk7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPT09IGVuZCkgewogICAgICAgICAgICBsZXQgZW5kQ29vcmRpbmF0ZTsKICAgICAgICAgICAgaWYgKGZvcm1hdCA9PT0gIlZDRiIpIHsKICAgICAgICAgICAgICBlbmRDb29yZGluYXRlID0gdGhpcy5fZ2V0VmNmRW5kKHN0YXJ0Q29vcmRpbmF0ZSwgcmVmU2VxLCBsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSkpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGVuZENvb3JkaW5hdGUgPSBwYXJzZUludChsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSksIDEwKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoZW5kQ29vcmRpbmF0ZSA8PSByZWdpb25TdGFydCkgewogICAgICAgICAgICAgIHJldHVybiB7IG92ZXJsYXBzOiBmYWxzZSB9OwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBjdXJyZW50Q29sdW1uU3RhcnQgPSBpICsgMTsKICAgICAgICAgIGN1cnJlbnRDb2x1bW5OdW1iZXIgKz0gMTsKICAgICAgICAgIGlmIChjdXJyZW50Q29sdW1uTnVtYmVyID4gbWF4Q29sdW1uKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4geyBzdGFydENvb3JkaW5hdGUsIG92ZXJsYXBzOiB0cnVlIH07CiAgICB9CiAgICBfZ2V0VmNmRW5kKHN0YXJ0Q29vcmRpbmF0ZSwgcmVmU2VxLCBpbmZvKSB7CiAgICAgIGxldCBlbmRDb29yZGluYXRlID0gc3RhcnRDb29yZGluYXRlICsgcmVmU2VxLmxlbmd0aDsKICAgICAgY29uc3QgaXNUUkEgPSBpbmZvLmluZGV4T2YoIlNWVFlQRT1UUkEiKSAhPT0gLTE7CiAgICAgIGlmIChpbmZvWzBdICE9PSAiLiIgJiYgIWlzVFJBKSB7CiAgICAgICAgbGV0IHByZXZDaGFyID0gIjsiOwogICAgICAgIGZvciAobGV0IGogPSAwOyBqIDwgaW5mby5sZW5ndGg7IGogKz0gMSkgewogICAgICAgICAgaWYgKHByZXZDaGFyID09PSAiOyIgJiYgaW5mby5zbGljZShqLCBqICsgNCkgPT09ICJFTkQ9IikgewogICAgICAgICAgICBsZXQgdmFsdWVFbmQgPSBpbmZvLmluZGV4T2YoIjsiLCBqKTsKICAgICAgICAgICAgaWYgKHZhbHVlRW5kID09PSAtMSkgewogICAgICAgICAgICAgIHZhbHVlRW5kID0gaW5mby5sZW5ndGg7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZW5kQ29vcmRpbmF0ZSA9IHBhcnNlSW50KGluZm8uc2xpY2UoaiArIDQsIHZhbHVlRW5kKSwgMTApOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIHByZXZDaGFyID0gaW5mb1tqXTsKICAgICAgICB9CiAgICAgIH0gZWxzZSBpZiAoaXNUUkEpIHsKICAgICAgICByZXR1cm4gc3RhcnRDb29yZGluYXRlICsgMTsKICAgICAgfQogICAgICByZXR1cm4gZW5kQ29vcmRpbmF0ZTsKICAgIH0KICAgIGFzeW5jIGxpbmVDb3VudChyZWZOYW1lLCBvcHRzID0ge30pIHsKICAgICAgcmV0dXJuIHRoaXMuaW5kZXgubGluZUNvdW50KHJlZk5hbWUsIG9wdHMpOwogICAgfQ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XMgbGlzdGVkIChlc3RpbWF0ZWQgZnJvbSBwcmltYXJ5IGRhdGEsIG5vdCBjYWxsZWQgZ2Vub3R5cGVzKSIKICAgICAgfSwKICAgICAgQU46IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiVG90YWwgbnVtYmVyIG9mIGFsbGVsZXMgaW4gY2FsbGVkIGdlbm90eXBlcyIKICAgICAgfSwKICAgICAgQlE6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkZsb2F0IiwKICAgICAgICBEZXNjcmlwdGlvbjogIlJNUyBiYXNlIHF1YWxpdHkiCiAgICAgIH0sCiAgICAgIENJR0FSOiB7CiAgICAgICAgTnVtYmVyOiAxLAogICAgICAgIFR5cGU6ICJGbG9hdCIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDaWdhciBzdHJpbmcgZGVzY3JpYmluZyBob3cgdG8gYWxpZ24gYW4gYWx0ZXJuYXRlIGFsbGVsZSB0byB0aGUgcmVmZXJlbmNlIGFsbGVsZSIKICAgICAgfSwKICAgICAgREI6IHsKICAgICAgICBOdW1iZXI6IDAsCiAgICAgICAgVHlwZTogIkZsYWciLAogICAgICAgIERlc2NyaXB0aW9uOiAiZGJTTlAgbWVtYmVyc2hpcCIKICAgICAgfSwKICAgICAgRFA6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiY29tYmluZWQgZGVwdGggYWNyb3NzIHNhbXBsZXMiCiAgICAgIH0sCiAgICAgIEVORDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJFbmQgcG9zaXRpb24gKGZvciB1c2Ugd2l0aCBzeW1ib2xpYyBhbGxlbGVzKSIKICAgICAgfSwKICAgICAgSDI6IHsKICAgICAgICBOdW1iZXI6IDAsCiAgICAgICAgVHlwZTogIkZsYWciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSGFwTWFwMiBtZW1iZXJzaGlwIgogICAgICB9LAogICAgICBIMzogewogICAgICAgIE51bWJlcjogMCwKICAgICAgICBUeXBlOiAiRmxhZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJIYXBNYXAzIG1lbWJlcnNoaXAiCiAgICAgIH0sCiAgICAgIE1ROiB7CiAgICAgICAgTnVtYmVyOiAxLAogICAgICAgIFR5cGU6IG51bGwsCiAgICAgICAgRGVzY3JpcHRpb246ICJSTVMgbWFwcGluZyBxdWFsaXR5IgogICAgICB9LAogICAgICBNUTA6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiTnVtYmVyIG9mIE1BUFEgPT0gMCByZWFkcyIKICAgICAgfSwKICAgICAgTlM6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiTnVtYmVyIG9mIHNhbXBsZXMgd2l0aCBkYXRhIgogICAgICB9LAogICAgICBTQjogewogICAgICAgIE51bWJlcjogNCwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJTdHJhbmQgYmlhcyIKICAgICAgfSwKICAgICAgU09NQVRJQzogewogICAgICAgIE51bWJlcjogMCwKICAgICAgICBUeXBlOiAiRmxhZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJTb21hdGljIG11dGF0aW9uIChmb3IgY2FuY2VyIGdlbm9taWNzKSIKICAgICAgfSwKICAgICAgVkFMSURBVEVEOiB7CiAgICAgICAgTnVtYmVyOiAwLAogICAgICAgIFR5cGU6ICJGbGFnIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlZhbGlkYXRlZCBieSBmb2xsb3ctdXAgZXhwZXJpbWVudCIKICAgICAgfSwKICAgICAgIjEwMDBHIjogewogICAgICAgIE51bWJlcjogMCwKICAgICAgICBUeXBlOiAiRmxhZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICIxMDAwIEdlbm9tZXMgbWVtYmVyc2hpcCIKICAgICAgfSwKICAgICAgSU1QUkVDSVNFOiB7CiAgICAgICAgTnVtYmVyOiAwLAogICAgICAgIFR5cGU6ICJGbGFnIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkltcHJlY2lzZSBzdHJ1Y3R1cmFsIHZhcmlhdGlvbiIKICAgICAgfSwKICAgICAgTk9WRUw6IHsKICAgICAgICBOdW1iZXI6IDAsCiAgICAgICAgVHlwZTogIkZsYWciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSW5kaWNhdGVzIGEgbm92ZWwgc3RydWN0dXJhbCB2YXJpYXRpb24iCiAgICAgIH0sCiAgICAgIFNWVFlQRTogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlR5cGUgb2Ygc3RydWN0dXJhbCB2YXJpYW50IgogICAgICB9LAogICAgICBTVkxFTjogewogICAgICAgIE51bWJlcjogbnVsbCwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJEaWZmZXJlbmNlIGluIGxlbmd0aCBiZXR3ZWVuIFJFRiBhbmQgQUxUIGFsbGVsZXMiCiAgICAgIH0sCiAgICAgIENJUE9TOiB7CiAgICAgICAgTnVtYmVyOiAyLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkNvbmZpZGVuY2UgaW50ZXJ2YWwgYXJvdW5kIFBPUyBmb3IgaW1wcmVjaXNlIHZhcmlhbnRzIgogICAgICB9LAogICAgICBDSUVORDogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25maWRlbmNlIGludGVydmFsIGFyb3VuZCBFTkQgZm9yIGltcHJlY2lzZSB2YXJpYW50cyIKICAgICAgfSwKICAgICAgSE9NTEVOOiB7CiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiTGVuZ3RoIG9mIGJhc2UgcGFpciBpZGVudGljYWwgbWljcm8taG9tb2xvZ3kgYXQgZXZlbnQgYnJlYWtwb2ludHMiCiAgICAgIH0sCiAgICAgIEhPTVNFUTogewogICAgICAgIFR5cGU6ICJTdHJpbmciLAogICAgICAgIERlc2NyaXB0aW9uOiAiU2VxdWVuY2Ugb2YgYmFzZSBwYWlyIGlkZW50aWNhbCBtaWNyby1ob21vbG9neSBhdCBldmVudCBicmVha3BvaW50cyIKICAgICAgfSwKICAgICAgQktQVElEOiB7CiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJJRCBvZiB0aGUgYXNzZW1ibGVkIGFsdGVybmF0ZSBhbGxlbGUgaW4gdGhlIGFzc2VtYmx5IGZpbGUiCiAgICAgIH0sCiAgICAgIE1FSU5GTzogewogICAgICAgIE51bWJlcjogNCwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIk1vYmlsZSBlbGVtZW50IGluZm8gb2YgdGhlIGZvcm0gTkFNRSxTVEFSVCxFTkQsUE9MQVJJVFkiCiAgICAgIH0sCiAgICAgIE1FVFJBTlM6IHsKICAgICAgICBOdW1iZXI6IDQsCiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJNb2JpbGUgZWxlbWVudCB0cmFuc2R1Y3Rpb24gaW5mbyBvZiB0aGUgZm9ybSBDSFIsU1RBUlQsRU5ELFBPTEFSSVRZIgogICAgICB9LAogICAgICBER1ZJRDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIklEIG9mIHRoaXMgZWxlbWVudCBpbiBEYXRhYmFzZSBvZiBHZW5vbWljIFZhcmlhdGlvbiIKICAgICAgfSwKICAgICAgREJWQVJJRDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIklEIG9mIHRoaXMgZWxlbWVudCBpbiBEQlZBUiIKICAgICAgfSwKICAgICAgREJSSVBJRDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIklEIG9mIHRoaXMgZWxlbWVudCBpbiBEQlJJUCIKICAgICAgfSwKICAgICAgTUFURUlEOiB7CiAgICAgICAgTnVtYmVyOiBudWxsLAogICAgICAgIFR5cGU6ICJTdHJpbmciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSUQgb2YgbWF0ZSBicmVha2VuZHMiCiAgICAgIH0sCiAgICAgIFBBUklEOiB7CiAgICAgICAgTnVtYmVyOiAxLAogICAgICAgIFR5cGU6ICJTdHJpbmciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSUQgb2YgcGFydG5lciBicmVha2VuZCIKICAgICAgfSwKICAgICAgRVZFTlQ6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJJRCBvZiBldmVudCBhc3NvY2lhdGVkIHRvIGJyZWFrZW5kIgogICAgICB9LAogICAgICBDSUxFTjogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25maWRlbmNlIGludGVydmFsIGFyb3VuZCB0aGUgaW5zZXJ0ZWQgbWF0ZXJpYWwgYmV0d2VlbiBicmVha2VuZCIKICAgICAgfSwKICAgICAgRFBBREo6IHsgVHlwZTogIkludGVnZXIiLCBEZXNjcmlwdGlvbjogIlJlYWQgRGVwdGggb2YgYWRqYWNlbmN5IiB9LAogICAgICBDTjogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb3B5IG51bWJlciBvZiBzZWdtZW50IGNvbnRhaW5pbmcgYnJlYWtlbmQiCiAgICAgIH0sCiAgICAgIENOQURKOiB7CiAgICAgICAgTnVtYmVyOiBudWxsLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkNvcHkgbnVtYmVyIG9mIGFkamFjZW5jeSIKICAgICAgfSwKICAgICAgQ0lDTjogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25maWRlbmNlIGludGVydmFsIGFyb3VuZCBjb3B5IG51bWJlciBmb3IgdGhlIHNlZ21lbnQiCiAgICAgIH0sCiAgICAgIENJQ05BREo6IHsKICAgICAgICBOdW1iZXI6IG51bGwsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiQ29uZmlkZW5jZSBpbnRlcnZhbCBhcm91bmQgY29weSBudW1iZXIgZm9yIHRoZSBhZGphY2VuY3kiCiAgICAgIH0KICAgIH0sCiAgICBHZW5vdHlwZUZpZWxkczogewogICAgICBBRDogewogICAgICAgIE51bWJlcjogIlIiLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlJlYWQgZGVwdGggZm9yIGVhY2ggYWxsZWxlIgogICAgICB9LAogICAgICBBREY6IHsKICAgICAgICBOdW1iZXI6ICJSIiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJSZWFkIGRlcHRoIGZvciBlYWNoIGFsbGVsZSBvbiB0aGUgZm9yd2FyZCBzdHJhbmQiCiAgICAgIH0sCiAgICAgIEFEUjogewogICAgICAgIE51bWJlcjogIlIiLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlJlYWQgZGVwdGggZm9yIGVhY2ggYWxsZWxlIG9uIHRoZSByZXZlcnNlIHN0cmFuZCIKICAgICAgfSwKICAgICAgRFA6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiUmVhZCBkZXB0aCIKICAgICAgfSwKICAgICAgRUM6IHsKICAgICAgICBOdW1iZXI6ICJBIiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJFeHBlY3RlZCBhbHRlcm5hdGUgYWxsZWxlIGNvdW50cyIKICAgICAgfSwKICAgICAgRlQ6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICdGaWx0ZXIgaW5kaWNhdGluZyBpZiB0aGlzIGdlbm90eXBlIHdhcyAiY2FsbGVkIicKICAgICAgfSwKICAgICAgR0w6IHsKICAgICAgICBOdW1iZXI6ICJHIiwKICAgICAgICBUeXBlOiAiRmxvYXQiLAogICAgICAgIERlc2NyaXB0aW9uOiAiR2Vub3R5cGUgbGlrZWxpaG9vZHMiCiAgICAgIH0sCiAgICAgIEdQOiB7CiAgICAgICAgTnVtYmVyOiAiRyIsCiAgICAgICAgVHlwZTogIkZsb2F0IiwKICAgICAgICBEZXNjcmlwdGlvbjogIkdlbm90eXBlIHBvc3RlcmlvciBwcm9iYWJpbGl0aWVzIgogICAgICB9LAogICAgICBHUTogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25kaXRpb25hbCBnZW5vdHlwZSBxdWFsaXR5IgogICAgICB9LAogICAgICBHVDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkdlbm90eXBlIgogICAgICB9LAogICAgICBIUTogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJIYXBsb3R5cGUgcXVhbGl0eSIKICAgICAgfSwKICAgICAgTVE6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiUk1TIG1hcHBpbmcgcXVhbGl0eSIKICAgICAgfSwKICAgICAgUEw6IHsKICAgICAgICBOdW1iZXI6ICJHIiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJQaHJlZC1zY2FsZWQgZ2Vub3R5cGUgbGlrZWxpaG9vZHMgcm91bmRlZCB0byB0aGUgY2xvc2VzdCBpbnRlZ2VyIgogICAgICB9LAogICAgICBQUTogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJQaGFzaW5nIHF1YWxpdHkiCiAgICAgIH0sCiAgICAgIFBTOiB7CiAgICAgICAgTnVtYmVyOiAxLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlBoYXNlIHNldCIKICAgICAgfQogICAgfSwKICAgIEFsdFR5cGVzOiB7CiAgICAgIERFTDogewogICAgICAgIERlc2NyaXB0aW9uOiAiRGVsZXRpb24gcmVsYXRpdmUgdG8gdGhlIHJlZmVyZW5jZSIKICAgICAgfSwKICAgICAgSU5TOiB7CiAgICAgICAgRGVzY3JpcHRpb246ICJJbnNlcnRpb24gb2Ygbm92ZWwgc2VxdWVuY2UgcmVsYXRpdmUgdG8gdGhlIHJlZmVyZW5jZSIKICAgICAgfSwKICA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C5HZW5vdHlwZUZpZWxkcywKICAgICAgICBBTFQ6IHZjZlJlc2VydmVkX2RlZmF1bHQuQWx0VHlwZXMsCiAgICAgICAgRklMVEVSOiB2Y2ZSZXNlcnZlZF9kZWZhdWx0LkZpbHRlclR5cGVzCiAgICAgIH0pKTsKICAgICAgbGV0IGxhc3RMaW5lOwogICAgICBoZWFkZXJMaW5lcy5mb3JFYWNoKChsaW5lKSA9PiB7CiAgICAgICAgaWYgKCFsaW5lLnN0YXJ0c1dpdGgoIiMiKSkgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGBCYWQgbGluZSBpbiBoZWFkZXI6CiR7bGluZX1gKTsKICAgICAgICB9IGVsc2UgaWYgKGxpbmUuc3RhcnRzV2l0aCgiIyMiKSkgewogICAgICAgICAgdGhpcy5fcGFyc2VNZXRhZGF0YShsaW5lKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgbGFzdExpbmUgPSBsaW5lOwogICAgICAgIH0KICAgICAgfSk7CiAgICAgIGlmICghbGFzdExpbmUpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoIk5vIGZvcm1hdCBsaW5lIGZvdW5kIGluIGhlYWRlciIpOwogICAgICB9CiAgICAgIGNvbnN0IGZpZWxkcyA9IGxhc3RMaW5lLnRyaW0oKS5zcGxpdCgiCSIpOwogICAgICBjb25zdCB0aGlzSGVhZGVyID0gZmllbGRzLnNsaWNlKDAsIDgpOwogICAgICBjb25zdCBjb3JyZWN0SGVhZGVyID0gWwogICAgICAgICIjQ0hST00iLAogICAgICAgICJQT1MiLAogICAgICAgICJJRCIsCiAgICAgICAgIlJFRiIsCiAgICAgICAgIkFMVCIsCiAgICAgICAgIlFVQUwiLAogICAgICAgICJGSUxURVIiLAogICAgICAgICJJTkZPIgogICAgICBdOwogICAgICBpZiAoZmllbGRzLmxlbmd0aCA8IDgpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoYFZDRiBoZWFkZXIgbWlzc2luZyBjb2x1bW5zO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kTWV0YWRhdGFbYXJnc1tpXV07CiAgICAgICAgaWYgKCFmaWx0ZXJlZE1ldGFkYXRhKSB7CiAgICAgICAgICByZXR1cm4gZmlsdGVyZWRNZXRhZGF0YTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIGZpbHRlcmVkTWV0YWRhdGE7CiAgICB9CiAgICBfcGFyc2VLZXlWYWx1ZShzdHIsIHBhaXJTZXBhcmF0b3IgPSAiOyIpIHsKICAgICAgY29uc3QgZGF0YSA9IHt9OwogICAgICBsZXQgY3VycktleSA9ICIiOwogICAgICBsZXQgY3VyclZhbHVlID0gIiI7CiAgICAgIGxldCBzdGF0ZSA9IDE7CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgc3RyLmxlbmd0aDsgaSArPSAxKSB7CiAgICAgICAgaWYgKHN0YXRlID09PSAxKSB7CiAgICAgICAgICBpZiAoc3RyW2ldID09PSAiPSIpIHsKICAgICAgICAgICAgc3RhdGUgPSAyOwogICAgICAgICAgfSBlbHNlIGlmIChzdHJbaV0gIT09IHBhaXJTZXBhcmF0b3IpIHsKICAgICAgICAgICAgY3VycktleSArPSBzdHJbaV07CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cnJWYWx1ZSA9PT0gIiIpIHsKICAgICAgICAgICAgZGF0YVtjdXJyS2V5XSA9IG51bGw7CiAgICAgICAgICAgIGN1cnJLZXkgPSAiIjsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgaWYgKHN0YXRlID09PSAyKSB7CiAgICAgICAgICBpZiAoc3RyW2ldID09PSBwYWlyU2VwYXJhdG9yKSB7CiAgICAgICAgICAgIGRhdGFbY3VycktleV0gPSBjdXJyVmFsdWU7CiAgICAgICAgICAgIGN1cnJLZXkgPSAiIjsKICAgICAgICAgICAgY3VyclZhbHVlID0gIiI7CiAgICAgICAgICAgIHN0YXRlID0gMTsKICAgICAgICAgIH0gZWxzZSBpZiAoc3RyW2ldID09PSAnIicpIHsKICAgICAgICAgICAgc3RhdGUgPSAzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY3VyclZhbHVlICs9IHN0cltpXTsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgaWYgKHN0YXRlID09PSAzKSB7CiAgICAgICAgICBpZiAoc3RyW2ldICE9PSAnIicpIHsKICAgICAgICAgICAgY3VyclZhbHVlICs9IHN0cltpXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHN0YXRlID0gMjsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKHN0YXRlID09PSAyIHx8IHN0YXRlID09PSAzKSB7CiAgICAgICAgZGF0YVtjdXJyS2V5XSA9IGN1cnJWYWx1ZTsKICAgICAgfSBlbHNlIGlmIChzdGF0ZSA9PT0gMSkgewogICAgICAgIGRhdGFbY3VycktleV0gPSBudWxsOwogICAgICB9CiAgICAgIHJldHVybiBkYXRhOwogICAgfQogICAgcGFyc2VMaW5lKGxpbmUpIHsKICAgICAgbGluZSA9IGxpbmUudHJpbSgpOwogICAgICBpZiAoIWxpbmUubGVuZ3RoKSB7CiAgICAgICAgcmV0dXJuIHZvaWQgMDsKICAgICAgfQogICAgICBjb25zdCBwYXJzZXIgPSB0aGlzOwogICAgICBsZXQgY3VyckNoYXIgPSAwOwogICAgICBmb3IgKGxldCBjdXJyRmllbGQgPSAwOyBjdXJyQ2hhciA8IGxpbmUubGVuZ3RoOyBjdXJyQ2hhciArPSAxKSB7CiAgICAgICAgaWYgKGxpbmVbY3VyckNoYXJdID09PSAiCSIpIHsKICAgICAgICAgIGN1cnJGaWVsZCArPSAxOwogICAgICAgIH0KICAgICAgICBpZiAoY3VyckZpZWxkID09PSA5KSB7CiAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgIH0KICAgICAgY29uc3QgZmllbGRzID0gbGluZS5zdWJzdHIoMCwgY3VyckNoYXIpLnNwbGl0KCIJIik7CiAgICAgIGNvbnN0IHJlc3QgPSBsaW5lLnN1YnN0cihjdXJyQ2hhciArIDEpOwogICAgICBjb25zdCBbQ0hST00sIFBPUywgSUQsIFJFRiwgQUxULCBRVUFMLCBGSUxURVJdID0gZmllbGRzOwogICAgICBjb25zdCBjaHJvbSA9IENIUk9NOwogICAgICBjb25zdCBwb3MgPSArUE9TOwogICAgICBjb25zdCBpZCA9IElEID09PSAiLiIgPyBudWxsIDogSUQuc3BsaXQoIjsiKTsKICAgICAgY29uc3QgcmVmID0gUkVGOwogICAgICBjb25zdCBhbHQgPSBBTFQgPT09ICIuIiA/IG51bGwgOiBBTFQuc3BsaXQoIiwiKTsKICAgICAgY29uc3QgcXVhbCA9IFFVQUwgPT09ICIuIiA/IG51bGwgOiArUVVBTDsKICAgICAgY29uc3QgZmlsdGVyID0gRklMVEVSID09PSAiLiIgPyBudWxsIDogRklMVEVSLnNwbGl0KCI7Iik7CiAgICAgIGlmICh0aGlzLnN0cmljdCAmJiBmaWVsZHNbN10gPT09IHZvaWQgMCkgewogICAgICAgIHRocm93IG5ldyBFcnJvcigibm8gSU5GTyBmaWVsZCBzcGVjaWZpZWQsIG11c3QgY29udGFpbiBhdCBsZWFzdCBhICcuJyAodHVybiBvZmYgc3RyaWN0IG1vZGUgdG8gYWxsb3cpIik7CiAgICAgIH0KICAgICAgY29uc3QgaW5mbyA9IGZpZWxkc1s3XSA9PT0gdm9pZCAwIHx8IGZpZWxkc1s3XSA9PT0gIi4iID8ge30gOiB0aGlzLl9wYXJzZUtleVZhbHVlKGZpZWxkc1s3XSk7CiAgICAgIE9iamVjdC5rZXlzKGluZm8pLmZvckVhY2goKGtleSkgPT4gewogICAgICAgIGxldCBpdGVtczsKICAgICAgICBpZiAoaW5mb1trZXldKSB7CiAgICAgICAgICBpdGVtcyA9IGluZm9ba2V5XS5zcGxpdCgiLCIpLm1hcCgodmFsKSA9PiB2YWwgPT09ICIuIiA/IG51bGwgOiB2YWwpLm1hcCgoZikgPT4gZiA/IGRlY29kZVVSSUNvbXBvbmVudE5vVGhyb3coZikgOiBmKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaXRlbXMgPSBpbmZvW2tleV07CiAgICAgICAgfQogICAgICAgIGNvbnN0IGl0ZW1UeXBlID0gdGhpcy5nZXRNZXRhZGF0YSgiSU5GTyIsIGtleSwgIlR5cGUiKTsKICAgICAgICBpZiAoaXRlbVR5cGUpIHsKICAgICAgICAgIGlmIChpdGVtVHlwZSA9PT0gIkludGVnZXIiIHx8IGl0ZW1UeXBlID09PSAiRmxvYXQiKSB7CiAgICAgICAgICAgIGl0ZW1zID0gaXRlbXMubWFwKCh2YWwpID0+IHsKICAgICAgICAgICAgICBpZiAodmFsID09PSBudWxsKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gbnVsbDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcmV0dXJuIE51bWJlcih2YWwpOwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0gZWxzZSBpZiAoaXRlbVR5cGUgPT09ICJGbGFnIikgewogICAgICAgICAgICBpZiAoaW5mb1trZXldKSB7CiAgICAgICAgICAgICAgY29uc29sZS53YXJuKGBJbmZvIGZpZWxkICR7a2V5fSBpcyBhIEZsYWcgYW5kIHNob3VsZCBub3QgaGF2ZSBhIHZhbHVlIChnb3QgdmFsdWUgJHtpbmZvW2tleV19KWApOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGl0ZW1zID0gdHJ1ZTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpbmZvW2tleV0gPSBpdGVtczsKICAgICAgfSk7CiAgICAgIGNvbnN0IHZhcmlhbnQgPSBuZXcgVmFyaWFudCh7CiAgICAgICAgQ0hST006IGNocm9tLAogICAgICAgIFBPUzogcG9zLAogICAgICAgIEFMVDogYWx0LAogICAgICAgIElORk86IGluZm8sCiAgICAgICAgUkVGOiByZWYsCiAgICAgICAgRklMVEVSOiBmaWx0ZXIgJiYgZmlsdGVyLmxlbmd0aCA9PT0gMSAmJiBmaWx0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8sIGhpKSB7CiAgICAgIGlmIChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgd2hpbGUgKGxvIDwgaGkpIHsKICAgICAgICBjb25zdCBtaWQgPSBsbyArIGhpID4+PiAxOwogICAgICAgIGlmIChjb21wYXJlKGFbbWlkXSwgeCkgPCAwKQogICAgICAgICAgbG8gPSBtaWQgKyAxOwogICAgICAgIGVsc2UKICAgICAgICAgIGhpID0gbWlkOwogICAgICB9CiAgICAgIHJldHVybiBsbzsKICAgIH0KICAgIGZ1bmN0aW9uIHJpZ2h0KGEsIHgsIGxvLCBoaSkgewogICAgICBpZiAobG8gPT0gbnVsbCkKICAgICAgICBsbyA9IDA7CiAgICAgIGlmIChoaSA9PSBudWxsKQogICAgICAgIGhpID0gYS5sZW5ndGg7CiAgICAgIHdoaWxlIChsbyA8IGhpKSB7CiAgICAgICAgY29uc3QgbWlkID0gbG8gKyBoaSA+Pj4gMTsKICAgICAgICBpZiAoY29tcGFyZShhW21pZF0sIHgpID4gMCkKICAgICAgICAgIGhpID0gbWlkOwogICAgICAgIGVsc2UKICAgICAgICAgIGxvID0gbWlkICsgMTsKICAgICAgfQogICAgICByZXR1cm4gbG87CiAgICB9CiAgICBmdW5jdGlvbiBjZW50ZXIoYSwgeCwgbG8sIGhpKSB7CiAgICAgIGlmIChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgY29uc3QgaSA9IGxlZnQoYSwgeCwgbG8sIGhpIC0gMSk7CiAgICAgIHJldHVybiBpID4gbG8gJiYgZGVsdGEoYVtpIC0gMV0sIHgpID4gLWRlbHRhKGFbaV0sIHgpID8gaSAtIDEgOiBpOwogICAgfQogICAgcmV0dXJuIHsgbGVmdCwgY2VudGVyLCByaWdodCB9OwogIH0KICBmdW5jdG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lmxlbmd0aCkKICAgICAgcmV0dXJuICJpbnNlcnRpb24iOwogICAgcmV0dXJuICJ1bmtub3duIjsKICB9OwogIHZhciBnZXRTdWJzdGl0dXRpb25UeXBlID0gKHJlZiwgYWx0KSA9PiB7CiAgICBzd2l0Y2ggKHJlZiArIGFsdCkgewogICAgICBjYXNlICJDQSI6CiAgICAgIGNhc2UgIkdUIjoKICAgICAgICByZXR1cm4gIkM+QSI7CiAgICAgIGNhc2UgIkNHIjoKICAgICAgY2FzZSAiR0MiOgogICAgICAgIHJldHVybiAiQz5HIjsKICAgICAgY2FzZSAiQ1QiOgogICAgICBjYXNlICJHQSI6CiAgICAgICAgcmV0dXJuICJDPlQiOwogICAgICBjYXNlICJUQSI6CiAgICAgIGNhc2UgIkFUIjoKICAgICAgICByZXR1cm4gIlQ+QSI7CiAgICAgIGNhc2UgIlRDIjoKICAgICAgY2FzZSAiQUciOgogICAgICAgIHJldHVybiAiVD5DIjsKICAgICAgY2FzZSAiVEciOgogICAgICBjYXNlICJBQyI6CiAgICAgICAgcmV0dXJuICJUPkciOwogICAgICBkZWZhdWx0OgogICAgICAgIHJldHVybiAidW5rbm93biI7CiAgICB9CiAgfTsKICBmdW5jdGlvbiByZWNvcmRUb1RpbGUodmNmUmVjb3JkLCBjaHJQb3MsIHByZXZBYnNQb3MpIHsKICAgIGNvbnN0IGFic1BvcyA9IGNoclBvcyArIHZjZlJlY29yZC5QT1MgKyAxOwogICAgbGV0IEFMVDsKICAgIGlmIChBcnJheS5pc0FycmF5KHZjZlJlY29yZC5BTFQpICYmIHZjZlJlY29yZC5BTFQubGVuZ3RoID4gMCkgewogICAgICBBTFQgPSB2Y2ZSZWNvcmQuQUxUWzBdOwogICAgfQogICAgY29uc3QgRElTVFBSRVYgPSAhcHJldkFic1BvcyA/IG51bGwgOiBhYnNQb3MgLSBwcmV2QWJzUG9zOwogICAgY29uc3QgRElTVFBSRVZMT0dFID0gIXByZXZBYnNQb3MgPyBudWxsIDogTWF0aC5sb2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gIGZvciAoY29uc3QgY3VtUG9zIG9mIGN1bVBvc2l0aW9ucykgewogICAgICAgIGNvbnN0IGNocm9tTmFtZSA9IGN1bVBvcy5jaHI7CiAgICAgICAgY29uc3QgY2hyb21TdGFydCA9IGN1bVBvcy5wb3M7CiAgICAgICAgY29uc3QgY2hyb21FbmQgPSBjdW1Qb3MucG9zICsgY2hyb21MZW5ndGhzW2Nocm9tTmFtZV07CiAgICAgICAgbGV0IHN0YXJ0UG9zLCBlbmRQb3M7CiAgICAgICAgaWYgKGNocm9tU3RhcnQgPiBjdXJNaW5YIHx8IGN1ck1pblggPj0gY2hyb21FbmQpIHsKICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBsZXQgcHJldlBPUzsKICAgICAgICBjb25zdCB0aWxlc1Byb21pc2UgPSBuZXcgUHJvbWlzZSgocmVzb2x2ZSkgPT4gewogICAgICAgICAgY29uc3QgdGlsZXMgPSBbXTsKICAgICAgICAgIGNvbnN0IGxpbmVDYWxsYmFjayA9IChsaW5lKSA9PiB7CiAgICAgICAgICAgIGNvbnN0IHZjZlJlY29yZCA9IHBhcnNlci5wYXJzZUxpbmUobGluZSk7CiAgICAgICAgICAgIGNvbnN0IHZjZlRpbGUgPSByZWNvcmRUb1RpbGUodmNmUmVjb3JkLCBjaHJvbVN0YXJ0LCBwcmV2UE9TKTsKICAgICAgICAgICAgcHJldlBPUyA9IHZjZlRpbGUuUE9TOwogICAgICAgICAgICB0aWxlcy5wdXNoKHZjZlRpbGUpOwogICAgICAgICAgfTsKICAgICAgICAgIGlmIChtYXhYID4gY2hyb21FbmQpIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBjdXJNaW5YIC0gY2hyb21TdGFydDsKICAgICAgICAgICAgZW5kUG9zID0gY2hyb21FbmQgLSBjaHJvbVN0YXJ0OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBNYXRoLmZsb29yKGN1ck1pblggLSBjaHJvbVN0Y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uCiAqCiAqIEBhdXRob3IgICBGZXJvc3MgQWJvdWtoYWRpamVoIDxodHRwczovL2Zlcm9zcy5vcmc+CiAqIEBsaWNlbnNlICBNSVQKICovCi8qISBpZWVlNzU0LiBCU0QtMy1DbGF1c2UgTGljZW5zZS4gRmVyb3NzIEFib3VraGFkaWplaCA8aHR0cHM6Ly9mZXJvc3Mub3JnL29wZW5zb3VyY2U+ICovCi8qKgogKiBAbGljZW5zZQogKiBMb2Rhc2ggKEN1c3RvbSBCdWlsZCkgPGh0dHBzOi8vbG9kYXNoLmNvbS8+CiAqIEJ1aWxkOiBgbG9kYXNoIG1vZHVsYXJpemUgZXhwb3J0cz0iZXMiIC1vIC4vYAogKiBDb3B5cmlnaHQgT3BlbkpTIEZvdW5kYXRpb24gYW5kIG90aGVyIGNvbnRyaWJ1dG9ycyA8aHR0cHM6Ly9vcGVuanNmLm9yZy8+CiAqIFJlbGVhc2VkIHVuZGVyIE1JVCBsaWNlbnNlIDxodHRwczovL2xvZGFzaC5jb20vbGljZW5zZT4KICogQmFzZWQgb24gVW5kZXJzY29yZS5qcyAxLjguMyA8aHR0cDovL3VuZGVyc2NvcmVqcy5vcmcvTElDRU5TRT4KICogQ29weXJpZ2h0IEplcmVteSBBc2hrZW5hcywgRG9jdW1lbnRDbG91ZCBhbmQgSW52ZXN0aWdhdGl2ZSBSZXBvcnRlcnMgJiBFZGl0b3JzCiAqLwo=",lle=typeof window<"u"&&window.Blob&&new Blob([atob(A2e)],{type:"text/javascript;charset=utf-8"});function pgg(){const e=lle&&(window.URL||window.webkitURL).createObjectURL(lle);try{return e?new Worker(e):new Worker("data:application/javascript;base64,"+A2e,{type:"module"})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const bgg=200;class s2e{constructor(g,I){rt(this,"dataConfig",{}),rt(this,"uid"),rt(this,"prevRequestTime"),rt(this,"track"),rt(this,"toFetch"),rt(this,"fetchTimeout"),rt(this,"worker"),this.uid=g.libraries.slugid.nice(),this.prevRequestTime=0,this.toFetch=new Set;const{url:i,indexUrl:n,assembly:C,...r}=I;this.worker=JT(new pgg).then(async o=>{const a=Object.entries(bI(C).size);return await o.init(this.uid,{url:i,indexUrl:n},a,r),o})}async tilesetInfo(g){(await this.worker).tilesetInfo(this.uid).then(g)}fetchTilesDebounced(g,I){this.track.drawLoadingCue(),I.forEach(i=>this.toFetch.add(i)),this.fetchTimeout&&clearTimeout(this.fetchTimeout),this.fetchTimeout=setTimeout(()=>{this.sendFetch(g,[...this.toFetch]),this.toFetch.clear()},bgg)}async sendFetch(g,I){(await this.worker).fetchTilesDebounced(this.uid,I).then(g)}async getTabularData(g){const I=await(await this.worker).getTabularData(this.uid,g);return JSON.parse(new TextDecoder().decode(I))}}rt(s2e,"config",{type:"vcf"});const Qk=BigInt(32);function ygg(e,g,I){const i=+!!I,n=+!I;return BigInt(e.getInt32(g,I)*n+e.getInt32(g+4,I)*i)<>Qk),C=Number(I&BigInt(4294967295));i?(e.setInt32(g+4,n,i),e.setUint32(g,C,i)):(e.setInt32(g,n,i),e.setUint32(g+4,C,i))}function vgg(e,g,I,i){const n=Number(I>>Qk),C=Number(I&BigInt(4294967295));i?(e.setUint32(g+4,n,i),e.setUint32(g,C,i)):(e.setUint32(g,n,i),e.setUint32(g+4,C,i))}"getBigInt64"in DataView||(DataView.prototype.getBigInt64=function(e,g){return ygg(this,e,g)});"getBigUint64"in DataView||(DataView.prototype.getBigUint64=function(e,g){return Zgg(this,e,g)});"setBigInt64"in DataView||(DataView.prototype.setBigInt64=function(e,g,I){Ggg(this,e,g,I)});"setBigUint64"in DataView||(DataView.prototype.setBigUint64=function(e,g,I){vgg(this,e,g,I)});class Bgg{constructor(g,I){this.code="",this.scopes=[["vars"]],this.bitFields=[],this.tmpVariableCount=0,this.references=new Map,this.imports=[],this.reverseImports=new Map,this.useContextVariables=!1,this.importPath=g,this.useContextVariables=I}generateVariable(g){const I=[...this.scopes[this.scopes.length-1]];return g&&I.push(g),I.join(".")}generateOption(g){switch(typeof g){case"number":return g.toString();case"string":return this.generateVariable(g);case"function":return`${this.addImport(g)}.call(${this.generateVariable()}, vars)`}}generateError(g){this.pushCode(`throw new Error(${g});`)}generateTmpVariable(){return"$tmp"+this.tmpVariableCount++}pushCode(g){this.code+=g+` -`}pushPath(g){g&&this.scopes[this.scopes.length-1].push(g)}popPath(g){g&&this.scopes[this.scopes.length-1].pop()}pushScope(g){this.scopes.push([g])}popScope(){this.scopes.pop()}addImport(g){if(!this.importPath)return`(${g})`;let I=this.reverseImports.get(g);return I||(I=this.imports.push(g)-1,this.reverseImports.set(g,I)),`${this.importPath}[${I}]`}addReference(g){this.references.has(g)||this.references.set(g,{resolved:!1,requested:!1})}markResolved(g){const I=this.references.get(g);I&&(I.resolved=!0)}markRequested(g){g.forEach(I=>{const i=this.references.get(I);i&&(i.requested=!0)})}getUnresolvedReferences(){return Array.from(this.references).filter(([g,I])=>!I.resolved&&!I.requested).map(([g,I])=>g)}}const To=new Map,Fu="___parser_",No={uint8:1,uint16le:2,uint16be:2,uint32le:4,uint32be:4,int8:1,int16le:2,int16be:2,int32le:4,int32be:4,int64be:8,int64le:8,uint64be:8,uint64le:8,floatle:4,floatbe:4,doublele:8,doublebe:8},$R={uint8:"Uint8",uint16le:"Uint16",uint16be:"Uint16",uint32le:"Uint32",uint32be:"Uint32",int8:"Int8",int16le:"Int16",int16be:"Int16",int32le:"Int32",int32be:"Int32",int64be:"BigInt64",int64le:"BigInt64",uint64be:"BigUint64",uint64le:"BigUint64",floatle:"Float32",floatbe:"Float32",doublele:"Float64",doublebe:"Float64"},qR={uint8:!1,uint16le:!0,uint16be:!1,uint32le:!0,uint32be:!1,int8:!1,int16le:!0,int16be:!1,int32le:!0,int32be:!1,int64be:!1,int64le:!0,uint64be:!1,uint64le:!0,floatle:!0,floatbe:!1,doublele:!0,doublebe:!1};class kg{constructor(){this.varName="",this.type="",this.options={},this.endian="be",this.useContextVariables=!1}static start(){return new kg}primitiveGenerateN(g,I){const i=$R[g],n=qR[g];I.pushCode(`${I.generateVariable(this.varName)} = dataView.get${i}(offset, ${n});`),I.pushCode(`offset += ${No[g]};`)}primitiveN(g,I,i){return this.setNextParser(g,I,i)}useThisEndian(g){return g+this.endian.toLowerCase()}uint8(g,I={}){return this.primitiveN("uint8",g,I)}uint16(g,I={}){return this.primitiveN(this.useThisEndian("uint16"),g,I)}uint16le(g,I={}){return this.primitiveN("uint16le",g,I)}uint16be(g,I={}){return this.primitiveN("uint16be",g,I)}uint32(g,I={}){return this.primitiveN(this.useThisEndian("uint32"),g,I)}uint32le(g,I={}){return this.primitiveN("uint32le",g,I)}uint32be(g,I={}){return this.primitiveN("uint32be",g,I)}int8(g,I={}){return this.primitiveN("int8",g,I)}int16(g,I={}){return this.primitiveN(this.useThisEndian("int16"),g,I)}int16le(g,I={}){return this.primitiveN("int16le",g,I)}int16be(g,I={}){return this.primitiveN("int16be",g,I)}int32(g,I={}){return this.primitiveN(this.useThisEndian("int32"),g,I)}int32le(g,I={}){return this.primitiveN("int32le",g,I)}int32be(g,I={}){return this.primitiveN("int32be",g,I)}bigIntVersionCheck(){if(!DataView.prototype.getBigInt64)throw new Error("BigInt64 is unsupported on this runtime")}int64(g,I={}){return this.bigIntVersionCheck(),this.primitiveN(this.useThisEndian("int64"),g,I)}int64be(g,I={}){return this.bigIntVersionCheck(),this.primitiveN("int64be",g,I)}int64le(g,I={}){return this.bigIntVersionCheck(),this.primitiveN("int64le",g,I)}uint64(g,I={}){return this.bigIntVersionCheck(),this.primitiveN(this.useThisEndian("uint64"),g,I)}uint64be(g,I={}){return this.bigIntVersionCheck(),this.primitiveN("uint64be",g,I)}uint64le(g,I={}){return this.bigIntVersionCheck(),this.primitiveN("uint64le",g,I)}floatle(g,I={}){return this.primitiveN("floatle",g,I)}floatbe(g,I={}){return this.primitiveN("floatbe",g,I)}doublele(g,I={}){return this.primitiveN("doublele",g,I)}doublebe(g,I={}){return this.primitiveN("doublebe",g,I)}bitN(g,I,i){return i.length=g,this.setNextParser("bit",I,i)}bit1(g,I={}){return this.bitN(1,g,I)}bit2(g,I={}){return this.bitN(2,g,I)}bit3(g,I={}){return this.bitN(3,g,I)}bit4(g,I={}){return this.bitN(4,g,I)}bit5(g,I={}){return this.bitN(5,g,I)}bit6(g,I={}){return this.bitN(6,g,I)}bit7(g,I={}){return this.bitN(7,g,I)}bit8(g,I={}){return this.bitN(8,g,I)}bit9(g,I={}){return this.bitN(9,g,I)}bit10(g,I={}){return this.bitN(10,g,I)}bit11(g,I={}){return this.bitN(11,g,I)}bit12(g,I={}){return this.bitN(12,g,I)}bit13(g,I={}){return this.bitN(13,g,I)}bit14(g,I={}){return this.bitN(14,g,I)}bit15(g,I={}){return this.bitN(15,g,I)}bit16(g,I={}){return this.bitN(16,g,I)}bit17(g,I={}){return this.bitN(17,g,I)}bit18(g,I={}){return this.bitN(18,g,I)}bit19(g,I={}){return this.bitN(19,g,I)}bit20(g,I={}){return this.bitN(20,g,I)}bit21(g,I={}){return this.bitN(21,g,I)}bit22(g,I={}){return this.bitN(22,g,I)}bit23(g,I={}){return this.bitN(23,g,I)}bit24(g,I={}){return this.bitN(24,g,I)}bit25(g,I={}){return this.bitN(25,g,I)}bit26(g,I={}){return this.bitN(26,g,I)}bit27(g,I={}){return this.bitN(27,g,I)}bit28(g,I={}){return this.bitN(28,g,I)}bit29(g,I={}){return this.bitN(29,g,I)}bit30(g,I={}){return this.bitN(30,g,I)}bit31(g,I={}){return this.bitN(31,g,I)}bit32(g,I={}){return this.bitN(32,g,I)}namely(g){return To.set(g,this),this.alias=g,this}skip(g,I={}){return this.seek(g,I)}seek(g,I={}){if(I.assert)throw new Error("assert option on seek is not allowed.");return this.setNextParser("seek","",{length:g})}string(g,I){if(!I.zeroTerminated&&!I.length&&!I.greedy)throw new Error("One of length, zeroTerminated, or greedy must be defined for string.");if((I.zeroTerminated||I.length)&&I.greedy)throw new Error("greedy is mutually exclusive with length and zeroTerminated for string.");if(I.stripNull&&!(I.length||I.greedy))throw new Error("length or greedy must be defined if stripNull is enabled.");return I.encoding=I.encoding||"utf8",this.setNextParser("string",g,I)}buffer(g,I){if(!I.length&&!I.readUntil)throw new Error("length or readUntil must be defined for buffer.");return this.setNextParser("buffer",g,I)}wrapped(g,I){if(typeof I!="object"&&typeof g=="object"&&(I=g,g=""),!I||!I.wrapper||!I.type)throw new Error("Both wrapper and type must be defined for wrapped.");if(!I.length&&!I.readUntil)throw new Error("length or readUntil must be defined for wrapped.");return this.setNextParser("wrapper",g,I)}array(g,I){if(!I.readUntil&&!I.length&&!I.lengthInBytes)throw new Error("One of readUntil, length and lengthInBytes must be defined for array.");if(!I.type)throw new Error("type is required for array.");if(typeof I.type=="string"&&!To.has(I.type)&&!(I.type in No))throw new Error(`Array element type "${I.type}" is unkown.`);return this.setNextParser("array",g,I)}choice(g,I){if(typeof I!="object"&&typeof g=="object"&&(I=g,g=""),!I)throw new Error("tag and choices are are required for choice.");if(!I.tag)throw new Error("tag is requird for choice.");if(!I.choices)throw new Error("choices is required for choice.");for(const i in I.choices){const n=parseInt(i,10),C=I.choices[n];if(isNaN(n))throw new Error(`Choice key "${i}" is not a number.`);if(typeof C=="string"&&!To.has(C)&&!(C in No))throw new Error(`Choice type "${C}" is unkown.`)}return this.setNextParser("choice",g,I)}nest(g,I){if(typeof I!="object"&&typeof g=="object"&&(I=g,g=""),!I||!I.type)throw new Error("type is required for nest.");if(!(I.type instanceof kg)&&!To.has(I.type))throw new Error("type must be a known parser name or a Parser object.");if(!(I.type instanceof kg)&&!g)throw new Error("type must be a Parser object if the variable name is omitted.");return this.setNextParser("nest",g,I)}pointer(g,I){if(!I.offset)throw new Error("offset is required for pointer.");if(!I.type)throw new Error("type is required for pointer.");if(typeof I.type=="string"&&!(I.type in No)&&!To.has(I.type))throw new Error(`Pointer type "${I.type}" is unkown.`);return this.setNextParser("pointer",g,I)}saveOffset(g,I={}){return this.setNextParser("saveOffset",g,I)}endianness(g){switch(g.toLowerCase()){case"little":this.endian="le";break;case"big":this.endian="be";break;default:throw new Error('endianness must be one of "little" or "big"')}return this}endianess(g){return this.endianness(g)}useContextVars(g=!0){return this.useContextVariables=g,this}create(g){if(!(g instanceof Function))throw new Error("Constructor must be a Function object.");return this.constructorFn=g,this}getContext(g){const I=new Bgg(g,this.useContextVariables);return I.pushCode("var dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.length);"),this.alias?(this.addAliasedCode(I),I.pushCode(`return ${Fu+this.alias}(0).result;`)):this.addRawCode(I),I}getCode(){const g="imports";return this.getContext(g).code}addRawCode(g){g.pushCode("var offset = 0;"),g.pushCode(`var vars = ${this.constructorFn?"new constructorFn()":"{}"};`),g.pushCode("vars.$parent = null;"),g.pushCode("vars.$root = vars;"),this.generate(g),this.resolveReferences(g),g.pushCode("delete vars.$parent;"),g.pushCode("delete vars.$root;"),g.pushCode("return vars;")}addAliasedCode(g){return g.pushCode(`function ${Fu+this.alias}(offset, context) {`),g.pushCode(`var vars = ${this.constructorFn?"new constructorFn()":"{}"};`),g.pushCode("var ctx = Object.assign({$parent: null, $root: vars}, context || {});"),g.pushCode("vars = Object.assign(vars, ctx);"),this.generate(g),g.markResolved(this.alias),this.resolveReferences(g),g.pushCode("Object.keys(ctx).forEach(function (item) { delete vars[item]; });"),g.pushCode("return { offset: offset, result: vars };"),g.pushCode("}"),g}resolveReferences(g){const I=g.getUnresolvedReferences();g.markRequested(I),I.forEach(i=>{var n;(n=To.get(i))===null||n===void 0||n.addAliasedCode(g)})}compile(){const g="imports",I=this.getContext(g);this.compiled=new Function(g,"TextDecoder",`return function (buffer, constructorFn) { ${I.code} };`)(I.imports,TextDecoder)}sizeOf(){let g=NaN;if(Object.keys(No).indexOf(this.type)>=0)g=No[this.type];else if(this.type==="string"&&typeof this.options.length=="number")g=this.options.length;else if(this.type==="buffer"&&typeof this.options.length=="number")g=this.options.length;else if(this.type==="array"&&typeof this.options.length=="number"){let I=NaN;typeof this.options.type=="string"?I=No[this.options.type]:this.options.type instanceof kg&&(I=this.options.type.sizeOf()),g=this.options.length*I}else this.type==="seek"?g=this.options.length:this.type==="nest"?g=this.options.type.sizeOf():this.type||(g=0);return this.next&&(g+=this.next.sizeOf()),g}parse(g){return this.compiled||this.compile(),this.compiled(g,this.constructorFn)}setNextParser(g,I,i){const n=new kg;return n.type=g,n.varName=I,n.options=i,n.endian=this.endian,this.head?this.head.next=n:this.next=n,this.head=n,this}generate(g){if(this.type){switch(this.type){case"uint8":case"uint16le":case"uint16be":case"uint32le":case"uint32be":case"int8":case"int16le":case"int16be":case"int32le":case"int32be":case"int64be":case"int64le":case"uint64be":case"uint64le":case"floatle":case"floatbe":case"doublele":case"doublebe":this.primitiveGenerateN(this.type,g);break;case"bit":this.generateBit(g);break;case"string":this.generateString(g);break;case"buffer":this.generateBuffer(g);break;case"seek":this.generateSeek(g);break;case"nest":this.generateNest(g);break;case"array":this.generateArray(g);break;case"choice":this.generateChoice(g);break;case"pointer":this.generatePointer(g);break;case"saveOffset":this.generateSaveOffset(g);break;case"wrapper":this.generateWrapper(g);break}this.type!=="bit"&&this.generateAssert(g)}const I=g.generateVariable(this.varName);return this.options.formatter&&this.type!=="bit"&&this.generateFormatter(g,I,this.options.formatter),this.generateNext(g)}generateAssert(g){if(!this.options.assert)return;const I=g.generateVariable(this.varName);switch(typeof this.options.assert){case"function":{const i=g.addImport(this.options.assert);g.pushCode(`if (!${i}.call(vars, ${I})) {`)}break;case"number":g.pushCode(`if (${this.options.assert} !== ${I}) {`);break;case"string":g.pushCode(`if (${JSON.stringify(this.options.assert)} !== ${I}) {`);break;default:throw new Error("assert option must be a string, number or a function.")}g.generateError(`"Assertion error: ${I} is " + ${JSON.stringify(this.options.assert.toString())}`),g.pushCode("}")}generateNext(g){return this.next&&(g=this.next.generate(g)),g}generateBit(g){const I=JSON.parse(JSON.stringify(this));if(I.options=this.options,I.generateAssert=this.generateAssert.bind(this),I.generateFormatter=this.generateFormatter.bind(this),I.varName=g.generateVariable(I.varName),g.bitFields.push(I),!this.next||this.next&&["bit","nest"].indexOf(this.next.type)<0){const i=g.generateTmpVariable();g.pushCode(`var ${i} = 0;`);const n=(A=0)=>{let l=0;for(let c=A;c32)break;l+=u}return l},C=A=>(A<=8?(g.pushCode(`${i} = dataView.getUint8(offset);`),A=8):A<=16?(g.pushCode(`${i} = dataView.getUint16(offset);`),A=16):A<=24?(g.pushCode(`${i} = (dataView.getUint16(offset) << 8) | dataView.getUint8(offset + 2);`),A=24):(g.pushCode(`${i} = dataView.getUint32(offset);`),A=32),g.pushCode(`offset += ${A/8};`),A);let r=0;const o=this.endian==="be";let a=0,s=0;g.bitFields.forEach((A,l)=>{let c=A.options.length;if(c>s){if(s){const h=-1>>>32-s;g.pushCode(`${A.varName} = (${i} & 0x${h.toString(16)}) << ${c-s};`),c-=s}r=0,s=a=C(n(l)-s)}const u=o?a-r-c:r,d=-1>>>32-c;g.pushCode(`${A.varName} ${c> ${u} & 0x${d.toString(16)};`),A.options.length===32&&g.pushCode(`${A.varName} >>>= 0`),A.options.assert&&A.generateAssert(g),A.options.formatter&&A.generateFormatter(g,A.varName,A.options.formatter),r+=c,s-=c}),g.bitFields=[]}}generateSeek(g){const I=g.generateOption(this.options.length);g.pushCode(`offset += ${I};`)}generateString(g){const I=g.generateVariable(this.varName),i=g.generateTmpVariable(),n=this.options.encoding,C=n.toLowerCase()==="hex",r='b => b.toString(16).padStart(2, "0")';if(this.options.length&&this.options.zeroTerminated){const o=this.options.length;g.pushCode(`var ${i} = offset;`),g.pushCode(`while(dataView.getUint8(offset++) !== 0 && offset - ${i} < ${o});`);const a=`offset - ${i} < ${o} ? offset - 1 : offset`;g.pushCode(C?`${I} = Array.from(buffer.subarray(${i}, ${a}), ${r}).join('');`:`${I} = new TextDecoder('${n}').decode(buffer.subarray(${i}, ${a}));`)}else if(this.options.length){const o=g.generateOption(this.options.length);g.pushCode(C?`${I} = Array.from(buffer.subarray(offset, offset + ${o}), ${r}).join('');`:`${I} = new TextDecoder('${n}').decode(buffer.subarray(offset, offset + ${o}));`),g.pushCode(`offset += ${o};`)}else this.options.zeroTerminated?(g.pushCode(`var ${i} = offset;`),g.pushCode("while(dataView.getUint8(offset++) !== 0);"),g.pushCode(C?`${I} = Array.from(buffer.subarray(${i}, offset - 1), ${r}).join('');`:`${I} = new TextDecoder('${n}').decode(buffer.subarray(${i}, offset - 1));`)):this.options.greedy&&(g.pushCode(`var ${i} = offset;`),g.pushCode("while(buffer.length > offset++);"),g.pushCode(C?`${I} = Array.from(buffer.subarray(${i}, offset), ${r}).join('');`:`${I} = new TextDecoder('${n}').decode(buffer.subarray(${i}, offset));`));this.options.stripNull&&g.pushCode(`${I} = ${I}.replace(/\\x00+$/g, '')`)}generateBuffer(g){const I=g.generateVariable(this.varName);if(typeof this.options.readUntil=="function"){const i=this.options.readUntil,n=g.generateTmpVariable(),C=g.generateTmpVariable();g.pushCode(`var ${n} = offset;`),g.pushCode(`var ${C} = 0;`),g.pushCode("while (offset < buffer.length) {"),g.pushCode(`${C} = dataView.getUint8(offset);`);const r=g.addImport(i);g.pushCode(`if (${r}.call(${g.generateVariable()}, ${C}, buffer.subarray(offset))) break;`),g.pushCode("offset += 1;"),g.pushCode("}"),g.pushCode(`${I} = buffer.subarray(${n}, offset);`)}else if(this.options.readUntil==="eof")g.pushCode(`${I} = buffer.subarray(offset);`);else{const i=g.generateOption(this.options.length);g.pushCode(`${I} = buffer.subarray(offset, offset + ${i});`),g.pushCode(`offset += ${i};`)}this.options.clone&&g.pushCode(`${I} = buffer.constructor.from(${I});`)}generateArray(g){const I=g.generateOption(this.options.length),i=g.generateOption(this.options.lengthInBytes),n=this.options.type,C=g.generateTmpVariable(),r=g.generateVariable(this.varName),o=g.generateTmpVariable(),a=this.options.key,s=typeof a=="string";if(s?g.pushCode(`${r} = {};`):g.pushCode(`${r} = [];`),typeof this.options.readUntil=="function"?g.pushCode("do {"):this.options.readUntil==="eof"?g.pushCode(`for (var ${C} = 0; offset < buffer.length; ${C}++) {`):i!==void 0?g.pushCode(`for (var ${C} = offset + ${i}; offset < ${C}; ) {`):g.pushCode(`for (var ${C} = ${I}; ${C} > 0; ${C}--) {`),typeof n=="string")if(To.get(n)){const A=g.generateTmpVariable();if(g.pushCode(`var ${A} = ${Fu+n}(offset, {`),g.useContextVariables){const l=g.generateVariable();g.pushCode(`$parent: ${l},`),g.pushCode(`$root: ${l}.$root,`),!this.options.readUntil&&i===void 0&&g.pushCode(`$index: ${I} - ${C},`)}g.pushCode("});"),g.pushCode(`var ${o} = ${A}.result; offset = ${A}.offset;`),n!==this.alias&&g.addReference(n)}else{const A=$R[n],l=qR[n];g.pushCode(`var ${o} = dataView.get${A}(offset, ${l});`),g.pushCode(`offset += ${No[n]};`)}else if(n instanceof kg){g.pushCode(`var ${o} = {};`);const A=g.generateVariable();g.pushScope(o),g.useContextVariables&&(g.pushCode(`${o}.$parent = ${A};`),g.pushCode(`${o}.$root = ${A}.$root;`),!this.options.readUntil&&i===void 0&&g.pushCode(`${o}.$index = ${I} - ${C};`)),n.generate(g),g.useContextVariables&&(g.pushCode(`delete ${o}.$parent;`),g.pushCode(`delete ${o}.$root;`),g.pushCode(`delete ${o}.$index;`)),g.popScope()}if(s?g.pushCode(`${r}[${o}.${a}] = ${o};`):g.pushCode(`${r}.push(${o});`),g.pushCode("}"),typeof this.options.readUntil=="function"){const A=this.options.readUntil,l=g.addImport(A);g.pushCode(`while (!${l}.call(${g.generateVariable()}, ${o}, buffer.subarray(offset)));`)}}generateChoiceCase(g,I,i){if(typeof i=="string"){const n=g.generateVariable(this.varName);if(To.has(i)){const C=g.generateTmpVariable();g.pushCode(`var ${C} = ${Fu+i}(offset, {`),g.useContextVariables&&(g.pushCode(`$parent: ${n}.$parent,`),g.pushCode(`$root: ${n}.$root,`)),g.pushCode("});"),g.pushCode(`${n} = ${C}.result; offset = ${C}.offset;`),i!==this.alias&&g.addReference(i)}else{const C=$R[i],r=qR[i];g.pushCode(`${n} = dataView.get${C}(offset, ${r});`),g.pushCode(`offset += ${No[i]}`)}}else i instanceof kg&&(g.pushPath(I),i.generate(g),g.popPath(I))}generateChoice(g){const I=g.generateOption(this.options.tag),i=g.generateVariable(this.varName);if(this.varName&&(g.pushCode(`${i} = {};`),g.useContextVariables)){const n=g.generateVariable();g.pushCode(`${i}.$parent = ${n};`),g.pushCode(`${i}.$root = ${n}.$root;`)}g.pushCode(`switch(${I}) {`);for(const n in this.options.choices){const C=parseInt(n,10),r=this.options.choices[C];g.pushCode(`case ${C}:`),this.generateChoiceCase(g,this.varName,r),g.pushCode("break;")}g.pushCode("default:"),this.options.defaultChoice?this.generateChoiceCase(g,this.varName,this.options.defaultChoice):g.generateError(`"Met undefined tag value " + ${I} + " at choice"`),g.pushCode("}"),this.varName&&g.useContextVariables&&(g.pushCode(`delete ${i}.$parent;`),g.pushCode(`delete ${i}.$root;`))}generateNest(g){const I=g.generateVariable(this.varName);if(this.options.type instanceof kg){if(this.varName&&(g.pushCode(`${I} = {};`),g.useContextVariables)){const i=g.generateVariable();g.pushCode(`${I}.$parent = ${i};`),g.pushCode(`${I}.$root = ${i}.$root;`)}g.pushPath(this.varName),this.options.type.generate(g),g.popPath(this.varName),this.varName&&g.useContextVariables&&g.useContextVariables&&(g.pushCode(`delete ${I}.$parent;`),g.pushCode(`delete ${I}.$root;`))}else if(To.has(this.options.type)){const i=g.generateTmpVariable();if(g.pushCode(`var ${i} = ${Fu+this.options.type}(offset, {`),g.useContextVariables){const n=g.generateVariable();g.pushCode(`$parent: ${n},`),g.pushCode(`$root: ${n}.$root,`)}g.pushCode("});"),g.pushCode(`${I} = ${i}.result; offset = ${i}.offset;`),this.options.type!==this.alias&&g.addReference(this.options.type)}}generateWrapper(g){const I=g.generateVariable(this.varName),i=g.generateTmpVariable();if(typeof this.options.readUntil=="function"){const a=this.options.readUntil,s=g.generateTmpVariable(),A=g.generateTmpVariable();g.pushCode(`var ${s} = offset;`),g.pushCode(`var ${A} = 0;`),g.pushCode("while (offset < buffer.length) {"),g.pushCode(`${A} = dataView.getUint8(offset);`);const l=g.addImport(a);g.pushCode(`if (${l}.call(${g.generateVariable()}, ${A}, buffer.subarray(offset))) break;`),g.pushCode("offset += 1;"),g.pushCode("}"),g.pushCode(`${i} = buffer.subarray(${s}, offset);`)}else if(this.options.readUntil==="eof")g.pushCode(`${i} = buffer.subarray(offset);`);else{const a=g.generateOption(this.options.length);g.pushCode(`${i} = buffer.subarray(offset, offset + ${a});`),g.pushCode(`offset += ${a};`)}this.options.clone&&g.pushCode(`${i} = buffer.constructor.from(${i});`);const n=g.generateTmpVariable(),C=g.generateTmpVariable(),r=g.generateTmpVariable(),o=g.addImport(this.options.wrapper);if(g.pushCode(`${i} = ${o}.call(this, ${i}).subarray(0);`),g.pushCode(`var ${n} = buffer;`),g.pushCode(`var ${C} = offset;`),g.pushCode(`var ${r} = dataView;`),g.pushCode(`buffer = ${i};`),g.pushCode("offset = 0;"),g.pushCode("dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.length);"),this.options.type instanceof kg)this.varName&&g.pushCode(`${I} = {};`),g.pushPath(this.varName),this.options.type.generate(g),g.popPath(this.varName);else if(To.has(this.options.type)){const a=g.generateTmpVariable();g.pushCode(`var ${a} = ${Fu+this.options.type}(0);`),g.pushCode(`${I} = ${a}.result;`),this.options.type!==this.alias&&g.addReference(this.options.type)}g.pushCode(`buffer = ${n};`),g.pushCode(`dataView = ${r};`),g.pushCode(`offset = ${C};`)}generateFormatter(g,I,i){if(typeof i=="function"){const n=g.addImport(i);g.pushCode(`${I} = ${n}.call(${g.generateVariable()}, ${I});`)}}generatePointer(g){const I=this.options.type,i=g.generateOption(this.options.offset),n=g.generateTmpVariable(),C=g.generateVariable(this.varName);if(g.pushCode(`var ${n} = offset;`),g.pushCode(`offset = ${i};`),this.options.type instanceof kg){if(g.pushCode(`${C} = {};`),g.useContextVariables){const r=g.generateVariable();g.pushCode(`${C}.$parent = ${r};`),g.pushCode(`${C}.$root = ${r}.$root;`)}g.pushPath(this.varName),this.options.type.generate(g),g.popPath(this.varName),g.useContextVariables&&(g.pushCode(`delete ${C}.$parent;`),g.pushCode(`delete ${C}.$root;`))}else if(To.has(this.options.type)){const r=g.generateTmpVariable();if(g.pushCode(`var ${r} = ${Fu+this.options.type}(offset, {`),g.useContextVariables){const o=g.generateVariable();g.pushCode(`$parent: ${o},`),g.pushCode(`$root: ${o}.$root,`)}g.pushCode("});"),g.pushCode(`${C} = ${r}.result; offset = ${r}.offset;`),this.options.type!==this.alias&&g.addReference(this.options.type)}else if(Object.keys(No).indexOf(this.options.type)>=0){const r=$R[I],o=qR[I];g.pushCode(`${C} = dataView.get${r}(offset, ${o});`),g.pushCode(`offset += ${No[I]};`)}g.pushCode(`offset = ${n};`)}generateSaveOffset(g){const I=g.generateVariable(this.varName);g.pushCode(`${I} = offset`)}}var l2e={},E$={},xh={},Tw={};Object.defineProperty(Tw,"__esModule",{value:!0});function M$(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function cle(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function fG(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Vgg(e,g){if(g&&(typeof g=="object"||typeof g=="function"))return g;if(g!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return fG(e)}function Rgg(e){var g=wgg();return function(){var i=d0(e),n;if(g){var C=d0(this).constructor;n=Reflect.construct(i,arguments,C)}else n=i.apply(this,arguments);return Vgg(this,n)}}function Wgg(e,g){for(;!Object.prototype.hasOwnProperty.call(e,g)&&(e=d0(e),e!==null););return e}function YW(){return typeof Reflect<"u"&&Reflect.get?YW=Reflect.get.bind():YW=function(g,I,i){var n=Wgg(g,I);if(n){var C=Object.getOwnPropertyDescriptor(n,I);return C.get?C.get.call(arguments.length<3?g:i):C.value}},YW.apply(this,arguments)}var ule=function(){function e(){M$(this,e),Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}return z$(e,[{key:"addEventListener",value:function(I,i,n){I in this.listeners||(this.listeners[I]=[]),this.listeners[I].push({callback:i,options:n})}},{key:"removeEventListener",value:function(I,i){if(I in this.listeners){for(var n=this.listeners[I],C=0,r=n.length;C"u")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch{n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(i)}},{key:"toString",value:function(){return"[object AbortController]"}}]),e}();typeof Symbol<"u"&&Symbol.toStringTag&&(c2e.prototype[Symbol.toStringTag]="AbortController",P$.prototype[Symbol.toStringTag]="AbortSignal");function Xgg(e){return e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof e.Request=="function"&&!e.Request.prototype.hasOwnProperty("signal")||!e.AbortController}function Hgg(e){typeof e=="function"&&(e={fetch:e});var g=e,I=g.fetch,i=g.Request,n=i===void 0?I.Request:i,C=g.AbortController,r=g.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL,o=r===void 0?!1:r;if(!Xgg({fetch:I,Request:n,AbortController:C,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o}))return{fetch:I,Request:a};var a=n;(a&&!a.prototype.hasOwnProperty("signal")||o)&&(a=function(c,u){var d;u&&u.signal&&(d=u.signal,delete u.signal);var h=new n(c,u);return d&&Object.defineProperty(h,"signal",{writable:!1,enumerable:!1,configurable:!0,value:d}),h},a.prototype=n.prototype);var s=I,A=function(c,u){var d=a&&a.prototype.isPrototypeOf(c)?c.signal:u?u.signal:void 0;if(d){var h;try{h=new DOMException("Aborted","AbortError")}catch{h=new Error("Aborted"),h.name="AbortError"}if(d.aborted)return Promise.reject(h);var m=new Promise(function(f,b){d.addEventListener("abort",function(){return b(h)},{once:!0})});return u&&u.signal&&delete u.signal,Promise.race([m,s(c,u)])}return s(c,u)};return{fetch:A,Request:a}}Tw.AbortController=c2e;Tw.AbortSignal=P$;Tw.abortableFetch=Hgg;Object.defineProperty(xh,"__esModule",{value:!0});xh.AbortSignal=xh.AbortController=void 0;const u2e=Tw;var SH=function(){if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof Ih<"u")return Ih;throw new Error("unable to locate global object")};let Tgg=typeof SH().AbortController>"u"?u2e.AbortController:SH().AbortController;xh.AbortController=Tgg;let Ngg=typeof SH().AbortController>"u"?u2e.AbortSignal:SH().AbortSignal;xh.AbortSignal=Ngg;var J$={};Object.defineProperty(J$,"__esModule",{value:!0});const kgg=xh;class Ygg{}class Kgg{constructor(){this.signals=new Set,this.abortController=new kgg.AbortController}addSignal(g=new Ygg){if(this.signal.aborted)throw new Error("cannot add a signal, already aborted!");this.signals.add(g),g.aborted?this.handleAborted(g):typeof g.addEventListener=="function"&&g.addEventListener("abort",()=>{this.handleAborted(g)})}handleAborted(g){this.signals.delete(g),this.signals.size===0&&this.abortController.abort()}get signal(){return this.abortController.signal}abort(){this.abortController.abort()}}J$.default=Kgg;var O$={};Object.defineProperty(O$,"__esModule",{value:!0});class xgg{constructor(){this.callbacks=new Set}addCallback(g=()=>{}){this.callbacks.add(g),g(this.currentMessage)}callback(g){this.currentMessage=g,this.callbacks.forEach(I=>{I(g)})}}O$.default=xgg;var d2e=Ih&&Ih.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(E$,"__esModule",{value:!0});const Dgg=xh,Fgg=d2e(J$),Egg=d2e(O$);class wH{constructor({fill:g,cache:I}){if(typeof g!="function")throw new TypeError("must pass a fill function");if(typeof I!="object")throw new TypeError("must pass a cache object");if(typeof I.get!="function"||typeof I.set!="function"||typeof I.delete!="function")throw new TypeError("cache must implement get(key), set(key, val), and and delete(key)");this.cache=I,this.fillCallback=g}static isAbortException(g){return g.name==="AbortError"||g.code==="ERR_ABORTED"||g.message==="AbortError: aborted"||g.message==="Error: aborted"}evict(g,I){this.cache.get(g)===I&&this.cache.delete(g)}fill(g,I,i,n){const C=new Fgg.default,r=new Egg.default;r.addCallback(n);const o={aborter:C,promise:this.fillCallback(I,C.signal,a=>{r.callback(a)}),settled:!1,statusReporter:r,get aborted(){return this.aborter.signal.aborted}};o.aborter.addSignal(i),o.aborter.signal.addEventListener("abort",()=>{o.settled||this.evict(g,o)}),o.promise.then(()=>{o.settled=!0},()=>{o.settled=!0,this.evict(g,o)}).catch(a=>{throw console.error(a),a}),this.cache.set(g,o)}static checkSinglePromise(g,I){function i(){if(I&&I.aborted)throw Object.assign(new Error("aborted"),{code:"ERR_ABORTED"})}return g.then(n=>(i(),n),n=>{throw i(),n})}has(g){return this.cache.has(g)}get(g,I,i,n){if(!i&&I instanceof Dgg.AbortSignal)throw new TypeError("second get argument appears to be an AbortSignal, perhaps you meant to pass `null` for the fill data?");const C=this.cache.get(g);return C?C.aborted&&!C.settled?(this.evict(g,C),this.get(g,I,i,n)):C.settled?C.promise:(C.aborter.addSignal(i),C.statusReporter.addCallback(n),wH.checkSinglePromise(C.promise,i)):(this.fill(g,I,i,n),wH.checkSinglePromise(this.cache.get(g).promise,i))}delete(g){const I=this.cache.get(g);I&&(I.settled||I.aborter.abort(),this.cache.delete(g))}clear(){const g=this.cache.keys();let I=0;for(let i=g.next();!i.done;i=g.next())this.delete(i.value),I+=1;return I}}E$.default=wH;var Mgg=Ih&&Ih.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(l2e,"__esModule",{value:!0});const zgg=Mgg(E$);var Pgg=l2e.default=zgg.default;class nc{constructor(g,I){this.ranges=arguments.length===2?[{min:g,max:I}]:0 in g?Object.assign({},g):[g]}min(){return this.ranges[0].min}max(){return this.ranges[this.ranges.length-1].max}contains(g){for(let I=0;I=g)return!0}return!1}isContiguous(){return this.ranges.length>1}getRanges(){return this.ranges.map(g=>new nc(g.min,g.max))}toString(){return this.ranges.map(g=>`[${g.min}-${g.max}]`).join(",")}union(g){const I=this.getRanges().concat(g.getRanges()).sort(this.rangeOrder),i=[];let n=I[0];for(let C=1;Cn.max()+1?(i.push(n),n=r):r.max()>n.max()&&(n=new nc(n.min(),r.max()))}return i.push(n),i.length===1?i[0]:new nc(i)}intersection(g){let I=this,i=g;const n=this.ranges(),C=i.ranges(),r=n.length,o=C.length;let a=0,s=0;const A=[];for(;a=l&&A.push(new nc(l,c)),I.max()>i.max()?s+=1:a+=1}if(A.length===0)throw new Error("found range of length 0");return A.length===1?A[0]:new nc(A)}coverage(){let g=0;const I=this.ranges();for(let i=0;in.min()?1:i.max()i.max()?1:0}}function dy(e){let g=e.length;for(;--g>=0;)e[g]=0}const Jgg=3,Ogg=258,h2e=29,_gg=256,Lgg=_gg+1+h2e,m2e=30,Ugg=512,Qgg=new Array((Lgg+2)*2);dy(Qgg);const jgg=new Array(m2e*2);dy(jgg);const $gg=new Array(Ugg);dy($gg);const qgg=new Array(Ogg-Jgg+1);dy(qgg);const eIg=new Array(h2e);dy(eIg);const tIg=new Array(m2e);dy(tIg);const gIg=(e,g,I,i)=>{let n=e&65535|0,C=e>>>16&65535|0,r=0;for(;I!==0;){r=I>2e3?2e3:I,I-=r;do n=n+g[i++]|0,C=C+n|0;while(--r);n%=65521,C%=65521}return n|C<<16|0};var I_=gIg;const IIg=()=>{let e,g=[];for(var I=0;I<256;I++){e=I;for(var i=0;i<8;i++)e=e&1?3988292384^e>>>1:e>>>1;g[I]=e}return g},iIg=new Uint32Array(IIg()),nIg=(e,g,I,i)=>{const n=iIg,C=i+I;e^=-1;for(let r=i;r>>8^n[(e^g[r])&255];return e^-1};var Na=nIg,i_={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},_$={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const CIg=(e,g)=>Object.prototype.hasOwnProperty.call(e,g);var rIg=function(e){const g=Array.prototype.slice.call(arguments,1);for(;g.length;){const I=g.shift();if(I){if(typeof I!="object")throw new TypeError(I+"must be non-object");for(const i in I)CIg(I,i)&&(e[i]=I[i])}}return e},oIg=e=>{let g=0;for(let i=0,n=e.length;i=252?6:e>=248?5:e>=240?4:e>=224?3:e>=192?2:1;oS[254]=oS[254]=1;var aIg=e=>{if(typeof TextEncoder=="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(e);let g,I,i,n,C,r=e.length,o=0;for(n=0;n>>6,g[C++]=128|I&63):I<65536?(g[C++]=224|I>>>12,g[C++]=128|I>>>6&63,g[C++]=128|I&63):(g[C++]=240|I>>>18,g[C++]=128|I>>>12&63,g[C++]=128|I>>>6&63,g[C++]=128|I&63);return g};const AIg=(e,g)=>{if(g<65534&&e.subarray&&p2e)return String.fromCharCode.apply(null,e.length===g?e:e.subarray(0,g));let I="";for(let i=0;i{const I=g||e.length;if(typeof TextDecoder=="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(e.subarray(0,g));let i,n;const C=new Array(I*2);for(n=0,i=0;i4){C[n++]=65533,i+=o-1;continue}for(r&=o===2?31:o===3?15:7;o>1&&i1){C[n++]=65533;continue}r<65536?C[n++]=r:(r-=65536,C[n++]=55296|r>>10&1023,C[n++]=56320|r&1023)}return AIg(C,n)},lIg=(e,g)=>{g=g||e.length,g>e.length&&(g=e.length);let I=g-1;for(;I>=0&&(e[I]&192)===128;)I--;return I<0||I===0?g:I+oS[e[I]]>g?I:g},n_={string2buf:aIg,buf2string:sIg,utf8border:lIg};function cIg(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}var uIg=cIg;const e1=16209,dIg=16191;var hIg=function(g,I){let i,n,C,r,o,a,s,A,l,c,u,d,h,m,f,b,p,y,Z,B,G,v,w,V;const S=g.state;i=g.next_in,w=g.input,n=i+(g.avail_in-5),C=g.next_out,V=g.output,r=C-(I-g.avail_out),o=C+(g.avail_out-257),a=S.dmax,s=S.wsize,A=S.whave,l=S.wnext,c=S.window,u=S.hold,d=S.bits,h=S.lencode,m=S.distcode,f=(1<>>24,u>>>=y,d-=y,y=p>>>16&255,y===0)V[C++]=p&65535;else if(y&16){Z=p&65535,y&=15,y&&(d>>=y,d-=y),d<15&&(u+=w[i++]<>>24,u>>>=y,d-=y,y=p>>>16&255,y&16){if(B=p&65535,y&=15,da){g.msg="invalid distance too far back",S.mode=e1;break e}if(u>>>=y,d-=y,y=C-r,B>y){if(y=B-y,y>A&&S.sane){g.msg="invalid distance too far back",S.mode=e1;break e}if(G=0,v=c,l===0){if(G+=s-y,y2;)V[C++]=v[G++],V[C++]=v[G++],V[C++]=v[G++],Z-=3;Z&&(V[C++]=v[G++],Z>1&&(V[C++]=v[G++]))}else{G=C-B;do V[C++]=V[G++],V[C++]=V[G++],V[C++]=V[G++],Z-=3;while(Z>2);Z&&(V[C++]=V[G++],Z>1&&(V[C++]=V[G++]))}}else if(y&64){g.msg="invalid distance code",S.mode=e1;break e}else{p=m[(p&65535)+(u&(1<>3,i-=Z,d-=Z<<3,u&=(1<{const a=o.bits;let s=0,A=0,l=0,c=0,u=0,d=0,h=0,m=0,f=0,b=0,p,y,Z,B,G,v=null,w;const V=new Uint16Array(of+1),S=new Uint16Array(of+1);let X=null,W,R,H;for(s=0;s<=of;s++)V[s]=0;for(A=0;A=1&&V[c]===0;c--);if(u>c&&(u=c),c===0)return n[C++]=1<<24|64<<16|0,n[C++]=1<<24|64<<16|0,o.bits=1,0;for(l=1;l0&&(e===mle||c!==1))return-1;for(S[1]=0,s=1;sdle||e===fle&&f>hle)return 1;for(;;){W=s-h,r[A]+1=w?(R=X[r[A]-w],H=v[r[A]-w]):(R=32+64,H=0),p=1<>h)+y]=W<<24|R<<16|H|0;while(y!==0);for(p=1<>=1;if(p!==0?(b&=p-1,b+=p):b=0,A++,--V[s]===0){if(s===c)break;s=g[I+r[A]]}if(s>u&&(b&B)!==Z){for(h===0&&(h=u),G+=l,d=s-h,m=1<dle||e===fle&&f>hle)return 1;Z=b&B,n[Z]=u<<24|d<<16|G-C|0}}return b!==0&&(n[G+b]=s-h<<24|64<<16|0),o.bits=u,0};var Tv=yIg;const ZIg=0,b2e=1,y2e=2,{Z_FINISH:ple,Z_BLOCK:GIg,Z_TREES:t1,Z_OK:Dh,Z_STREAM_END:vIg,Z_NEED_DICT:BIg,Z_STREAM_ERROR:oo,Z_DATA_ERROR:Z2e,Z_MEM_ERROR:G2e,Z_BUF_ERROR:SIg,Z_DEFLATED:ble}=_$,jk=16180,yle=16181,Zle=16182,Gle=16183,vle=16184,Ble=16185,Sle=16186,wle=16187,Vle=16188,Rle=16189,VH=16190,_A=16191,BF=16192,Wle=16193,SF=16194,Xle=16195,Hle=16196,Tle=16197,Nle=16198,g1=16199,I1=16200,kle=16201,Yle=16202,Kle=16203,xle=16204,Dle=16205,wF=16206,Fle=16207,Ele=16208,vI=16209,v2e=16210,B2e=16211,wIg=852,VIg=592,RIg=15,WIg=RIg,Mle=e=>(e>>>24&255)+(e>>>8&65280)+((e&65280)<<8)+((e&255)<<24);function XIg(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const Gm=e=>{if(!e)return 1;const g=e.state;return!g||g.strm!==e||g.modeB2e?1:0},S2e=e=>{if(Gm(e))return oo;const g=e.state;return e.total_in=e.total_out=g.total=0,e.msg="",g.wrap&&(e.adler=g.wrap&1),g.mode=jk,g.last=0,g.havedict=0,g.flags=-1,g.dmax=32768,g.head=null,g.hold=0,g.bits=0,g.lencode=g.lendyn=new Int32Array(wIg),g.distcode=g.distdyn=new Int32Array(VIg),g.sane=1,g.back=-1,Dh},w2e=e=>{if(Gm(e))return oo;const g=e.state;return g.wsize=0,g.whave=0,g.wnext=0,S2e(e)},V2e=(e,g)=>{let I;if(Gm(e))return oo;const i=e.state;return g<0?(I=0,g=-g):(I=(g>>4)+5,g<48&&(g&=15)),g&&(g<8||g>15)?oo:(i.window!==null&&i.wbits!==g&&(i.window=null),i.wrap=I,i.wbits=g,w2e(e))},R2e=(e,g)=>{if(!e)return oo;const I=new XIg;e.state=I,I.strm=e,I.window=null,I.mode=jk;const i=V2e(e,g);return i!==Dh&&(e.state=null),i},HIg=e=>R2e(e,WIg);let zle=!0,VF,RF;const TIg=e=>{if(zle){VF=new Int32Array(512),RF=new Int32Array(32);let g=0;for(;g<144;)e.lens[g++]=8;for(;g<256;)e.lens[g++]=9;for(;g<280;)e.lens[g++]=7;for(;g<288;)e.lens[g++]=8;for(Tv(b2e,e.lens,0,288,VF,0,e.work,{bits:9}),g=0;g<32;)e.lens[g++]=5;Tv(y2e,e.lens,0,32,RF,0,e.work,{bits:5}),zle=!1}e.lencode=VF,e.lenbits=9,e.distcode=RF,e.distbits=5},W2e=(e,g,I,i)=>{let n;const C=e.state;return C.window===null&&(C.wsize=1<=C.wsize?(C.window.set(g.subarray(I-C.wsize,I),0),C.wnext=0,C.whave=C.wsize):(n=C.wsize-C.wnext,n>i&&(n=i),C.window.set(g.subarray(I-i,I-i+n),C.wnext),i-=n,i?(C.window.set(g.subarray(I-i,I),0),C.wnext=i,C.whave=C.wsize):(C.wnext+=n,C.wnext===C.wsize&&(C.wnext=0),C.whave{let I,i,n,C,r,o,a,s,A,l,c,u,d,h,m=0,f,b,p,y,Z,B,G,v;const w=new Uint8Array(4);let V,S;const X=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(Gm(e)||!e.output||!e.input&&e.avail_in!==0)return oo;I=e.state,I.mode===_A&&(I.mode=BF),r=e.next_out,n=e.output,a=e.avail_out,C=e.next_in,i=e.input,o=e.avail_in,s=I.hold,A=I.bits,l=o,c=a,v=Dh;e:for(;;)switch(I.mode){case jk:if(I.wrap===0){I.mode=BF;break}for(;A<16;){if(o===0)break e;o--,s+=i[C++]<>>8&255,I.check=Na(I.check,w,2,0),s=0,A=0,I.mode=yle;break}if(I.head&&(I.head.done=!1),!(I.wrap&1)||(((s&255)<<8)+(s>>8))%31){e.msg="incorrect header check",I.mode=vI;break}if((s&15)!==ble){e.msg="unknown compression method",I.mode=vI;break}if(s>>>=4,A-=4,G=(s&15)+8,I.wbits===0&&(I.wbits=G),G>15||G>I.wbits){e.msg="invalid window size",I.mode=vI;break}I.dmax=1<>8&1),I.flags&512&&I.wrap&4&&(w[0]=s&255,w[1]=s>>>8&255,I.check=Na(I.check,w,2,0)),s=0,A=0,I.mode=Zle;case Zle:for(;A<32;){if(o===0)break e;o--,s+=i[C++]<>>8&255,w[2]=s>>>16&255,w[3]=s>>>24&255,I.check=Na(I.check,w,4,0)),s=0,A=0,I.mode=Gle;case Gle:for(;A<16;){if(o===0)break e;o--,s+=i[C++]<>8),I.flags&512&&I.wrap&4&&(w[0]=s&255,w[1]=s>>>8&255,I.check=Na(I.check,w,2,0)),s=0,A=0,I.mode=vle;case vle:if(I.flags&1024){for(;A<16;){if(o===0)break e;o--,s+=i[C++]<>>8&255,I.check=Na(I.check,w,2,0)),s=0,A=0}else I.head&&(I.head.extra=null);I.mode=Ble;case Ble:if(I.flags&1024&&(u=I.length,u>o&&(u=o),u&&(I.head&&(G=I.head.extra_len-I.length,I.head.extra||(I.head.extra=new Uint8Array(I.head.extra_len)),I.head.extra.set(i.subarray(C,C+u),G)),I.flags&512&&I.wrap&4&&(I.check=Na(I.check,i,u,C)),o-=u,C+=u,I.length-=u),I.length))break e;I.length=0,I.mode=Sle;case Sle:if(I.flags&2048){if(o===0)break e;u=0;do G=i[C+u++],I.head&&G&&I.length<65536&&(I.head.name+=String.fromCharCode(G));while(G&&u>9&1,I.head.done=!0),e.adler=I.check=0,I.mode=_A;break;case Rle:for(;A<32;){if(o===0)break e;o--,s+=i[C++]<>>=A&7,A-=A&7,I.mode=wF;break}for(;A<3;){if(o===0)break e;o--,s+=i[C++]<>>=1,A-=1,s&3){case 0:I.mode=Wle;break;case 1:if(TIg(I),I.mode=g1,g===t1){s>>>=2,A-=2;break e}break;case 2:I.mode=Hle;break;case 3:e.msg="invalid block type",I.mode=vI}s>>>=2,A-=2;break;case Wle:for(s>>>=A&7,A-=A&7;A<32;){if(o===0)break e;o--,s+=i[C++]<>>16^65535)){e.msg="invalid stored block lengths",I.mode=vI;break}if(I.length=s&65535,s=0,A=0,I.mode=SF,g===t1)break e;case SF:I.mode=Xle;case Xle:if(u=I.length,u){if(u>o&&(u=o),u>a&&(u=a),u===0)break e;n.set(i.subarray(C,C+u),r),o-=u,C+=u,a-=u,r+=u,I.length-=u;break}I.mode=_A;break;case Hle:for(;A<14;){if(o===0)break e;o--,s+=i[C++]<>>=5,A-=5,I.ndist=(s&31)+1,s>>>=5,A-=5,I.ncode=(s&15)+4,s>>>=4,A-=4,I.nlen>286||I.ndist>30){e.msg="too many length or distance symbols",I.mode=vI;break}I.have=0,I.mode=Tle;case Tle:for(;I.have>>=3,A-=3}for(;I.have<19;)I.lens[X[I.have++]]=0;if(I.lencode=I.lendyn,I.lenbits=7,V={bits:I.lenbits},v=Tv(ZIg,I.lens,0,19,I.lencode,0,I.work,V),I.lenbits=V.bits,v){e.msg="invalid code lengths set",I.mode=vI;break}I.have=0,I.mode=Nle;case Nle:for(;I.have>>24,b=m>>>16&255,p=m&65535,!(f<=A);){if(o===0)break e;o--,s+=i[C++]<>>=f,A-=f,I.lens[I.have++]=p;else{if(p===16){for(S=f+2;A>>=f,A-=f,I.have===0){e.msg="invalid bit length repeat",I.mode=vI;break}G=I.lens[I.have-1],u=3+(s&3),s>>>=2,A-=2}else if(p===17){for(S=f+3;A>>=f,A-=f,G=0,u=3+(s&7),s>>>=3,A-=3}else{for(S=f+7;A>>=f,A-=f,G=0,u=11+(s&127),s>>>=7,A-=7}if(I.have+u>I.nlen+I.ndist){e.msg="invalid bit length repeat",I.mode=vI;break}for(;u--;)I.lens[I.have++]=G}}if(I.mode===vI)break;if(I.lens[256]===0){e.msg="invalid code -- missing end-of-block",I.mode=vI;break}if(I.lenbits=9,V={bits:I.lenbits},v=Tv(b2e,I.lens,0,I.nlen,I.lencode,0,I.work,V),I.lenbits=V.bits,v){e.msg="invalid literal/lengths set",I.mode=vI;break}if(I.distbits=6,I.distcode=I.distdyn,V={bits:I.distbits},v=Tv(y2e,I.lens,I.nlen,I.ndist,I.distcode,0,I.work,V),I.distbits=V.bits,v){e.msg="invalid distances set",I.mode=vI;break}if(I.mode=g1,g===t1)break e;case g1:I.mode=I1;case I1:if(o>=6&&a>=258){e.next_out=r,e.avail_out=a,e.next_in=C,e.avail_in=o,I.hold=s,I.bits=A,hIg(e,c),r=e.next_out,n=e.output,a=e.avail_out,C=e.next_in,i=e.input,o=e.avail_in,s=I.hold,A=I.bits,I.mode===_A&&(I.back=-1);break}for(I.back=0;m=I.lencode[s&(1<>>24,b=m>>>16&255,p=m&65535,!(f<=A);){if(o===0)break e;o--,s+=i[C++]<>y)],f=m>>>24,b=m>>>16&255,p=m&65535,!(y+f<=A);){if(o===0)break e;o--,s+=i[C++]<>>=y,A-=y,I.back+=y}if(s>>>=f,A-=f,I.back+=f,I.length=p,b===0){I.mode=Dle;break}if(b&32){I.back=-1,I.mode=_A;break}if(b&64){e.msg="invalid literal/length code",I.mode=vI;break}I.extra=b&15,I.mode=kle;case kle:if(I.extra){for(S=I.extra;A>>=I.extra,A-=I.extra,I.back+=I.extra}I.was=I.length,I.mode=Yle;case Yle:for(;m=I.distcode[s&(1<>>24,b=m>>>16&255,p=m&65535,!(f<=A);){if(o===0)break e;o--,s+=i[C++]<>y)],f=m>>>24,b=m>>>16&255,p=m&65535,!(y+f<=A);){if(o===0)break e;o--,s+=i[C++]<>>=y,A-=y,I.back+=y}if(s>>>=f,A-=f,I.back+=f,b&64){e.msg="invalid distance code",I.mode=vI;break}I.offset=p,I.extra=b&15,I.mode=Kle;case Kle:if(I.extra){for(S=I.extra;A>>=I.extra,A-=I.extra,I.back+=I.extra}if(I.offset>I.dmax){e.msg="invalid distance too far back",I.mode=vI;break}I.mode=xle;case xle:if(a===0)break e;if(u=c-a,I.offset>u){if(u=I.offset-u,u>I.whave&&I.sane){e.msg="invalid distance too far back",I.mode=vI;break}u>I.wnext?(u-=I.wnext,d=I.wsize-u):d=I.wnext-u,u>I.length&&(u=I.length),h=I.window}else h=n,d=r-I.offset,u=I.length;u>a&&(u=a),a-=u,I.length-=u;do n[r++]=h[d++];while(--u);I.length===0&&(I.mode=I1);break;case Dle:if(a===0)break e;n[r++]=I.length,a--,I.mode=I1;break;case wF:if(I.wrap){for(;A<32;){if(o===0)break e;o--,s|=i[C++]<{if(Gm(e))return oo;let g=e.state;return g.window&&(g.window=null),e.state=null,Dh},YIg=(e,g)=>{if(Gm(e))return oo;const I=e.state;return I.wrap&2?(I.head=g,g.done=!1,Dh):oo},KIg=(e,g)=>{const I=g.length;let i,n,C;return Gm(e)||(i=e.state,i.wrap!==0&&i.mode!==VH)?oo:i.mode===VH&&(n=1,n=I_(n,g,I,0),n!==i.check)?Z2e:(C=W2e(e,g,I,I),C?(i.mode=v2e,G2e):(i.havedict=1,Dh))};var xIg=w2e,DIg=V2e,FIg=S2e,EIg=HIg,MIg=R2e,zIg=NIg,PIg=kIg,JIg=YIg,OIg=KIg,_Ig="pako inflate (from Nodeca project)",os={inflateReset:xIg,inflateReset2:DIg,inflateResetKeep:FIg,inflateInit:EIg,inflateInit2:MIg,inflate:zIg,inflateEnd:PIg,inflateGetHeader:JIg,inflateSetDictionary:OIg,inflateInfo:_Ig};function LIg(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}var UIg=LIg;const X2e=Object.prototype.toString,{Z_NO_FLUSH:QIg,Z_FINISH:jIg,Z_OK:aS,Z_STREAM_END:WF,Z_NEED_DICT:XF,Z_STREAM_ERROR:$Ig,Z_DATA_ERROR:Ple,Z_MEM_ERROR:qIg}=_$;function Nw(e){this.options=f2e.assign({chunkSize:1024*64,windowBits:15,to:""},e||{});const g=this.options;g.raw&&g.windowBits>=0&&g.windowBits<16&&(g.windowBits=-g.windowBits,g.windowBits===0&&(g.windowBits=-15)),g.windowBits>=0&&g.windowBits<16&&!(e&&e.windowBits)&&(g.windowBits+=32),g.windowBits>15&&g.windowBits<48&&(g.windowBits&15||(g.windowBits|=15)),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new uIg,this.strm.avail_out=0;let I=os.inflateInit2(this.strm,g.windowBits);if(I!==aS)throw new Error(i_[I]);if(this.header=new UIg,os.inflateGetHeader(this.strm,this.header),g.dictionary&&(typeof g.dictionary=="string"?g.dictionary=n_.string2buf(g.dictionary):X2e.call(g.dictionary)==="[object ArrayBuffer]"&&(g.dictionary=new Uint8Array(g.dictionary)),g.raw&&(I=os.inflateSetDictionary(this.strm,g.dictionary),I!==aS)))throw new Error(i_[I])}Nw.prototype.push=function(e,g){const I=this.strm,i=this.options.chunkSize,n=this.options.dictionary;let C,r,o;if(this.ended)return!1;for(g===~~g?r=g:r=g===!0?jIg:QIg,X2e.call(e)==="[object ArrayBuffer]"?I.input=new Uint8Array(e):I.input=e,I.next_in=0,I.avail_in=I.input.length;;){for(I.avail_out===0&&(I.output=new Uint8Array(i),I.next_out=0,I.avail_out=i),C=os.inflate(I,r),C===XF&&n&&(C=os.inflateSetDictionary(I,n),C===aS?C=os.inflate(I,r):C===Ple&&(C=XF));I.avail_in>0&&C===WF&&I.state.wrap>0&&e[I.next_in]!==0;)os.inflateReset(I),C=os.inflate(I,r);switch(C){case $Ig:case Ple:case XF:case qIg:return this.onEnd(C),this.ended=!0,!1}if(o=I.avail_out,I.next_out&&(I.avail_out===0||C===WF))if(this.options.to==="string"){let a=n_.utf8border(I.output,I.next_out),s=I.next_out-a,A=n_.buf2string(I.output,a);I.next_out=s,I.avail_out=i-s,s&&I.output.set(I.output.subarray(a,a+s),0),this.onData(A)}else this.onData(I.output.length===I.next_out?I.output:I.output.subarray(0,I.next_out));if(!(C===aS&&o===0)){if(C===WF)return C=os.inflateEnd(this.strm),this.onEnd(C),this.ended=!0,!0;if(I.avail_in===0)break}}return!0};Nw.prototype.onData=function(e){this.chunks.push(e)};Nw.prototype.onEnd=function(e){e===aS&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=f2e.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};function L$(e,g){const I=new Nw(g);if(I.push(e),I.err)throw I.msg||i_[I.err];return I.result}function eig(e,g){return g=g||{},g.raw=!0,L$(e,g)}var tig=Nw,gig=L$,Iig=eig,iig=L$,nig=_$,Cig={Inflate:tig,inflate:gig,inflateRaw:Iig,ungzip:iig,constants:nig};const{Inflate:gpg,inflate:Ipg,inflateRaw:rig,ungzip:ipg}=Cig;var oig=rig;function aig(e){return oig(e.subarray(2))}class Aig extends Error{constructor(g){super(g),this.code="ERR_ABORTED"}}function sig(e){e.sort((n,C)=>Number(n.offset)-Number(C.offset));const g=[];let I,i;for(let n=0;n=I}function dig(e){const g=e?"big":"little",I=new kg().endianess(g).uint32("chromId").uint32("start").uint32("end").uint32("validCnt").floatle("minScore").floatle("maxScore").floatle("sumData").floatle("sumSqData").saveOffset("offset"),i=new kg().endianess(g).uint8("isLeaf").skip(1).uint16("cnt").choice({tag:"isLeaf",choices:{1:new kg().endianess(g).array("blocksToFetch",{length:"cnt",type:new kg().endianess(g).uint32("startChrom").uint32("startBase").uint32("endChrom").uint32("endBase").uint64("blockOffset").uint64("blockSize").saveOffset("offset")}),0:new kg().array("recurOffsets",{length:"cnt",type:new kg().endianess(g).uint32("startChrom").uint32("startBase").uint32("endChrom").uint32("endBase").uint64("blockOffset").saveOffset("offset")})}}),n=new kg().endianess(g).uint32("chromId").int32("start").int32("end").string("rest",{zeroTerminated:!0}).saveOffset("offset");return{bigWigParser:new kg().endianess(g).skip(4).int32("blockStart").skip(4).uint32("itemStep").uint32("itemSpan").uint8("blockType").skip(1).uint16("itemCount").choice({tag:"blockType",choices:{[uig]:new kg().array("items",{length:"itemCount",type:new kg().floatle("score")}),[cig]:new kg().array("items",{length:"itemCount",type:new kg().endianess(g).int32("start").floatle("score")}),[lig]:new kg().array("items",{length:"itemCount",type:new kg().endianess(g).int32("start").int32("end").floatle("score")})}}),bigBedParser:n,summaryParser:I,leafParser:i}}class H2e{constructor(g,I,i,n,C,r){if(this.bbi=g,this.refsByName=I,this.cirTreeOffset=i,this.isBigEndian=n,this.isCompressed=C,this.blockType=r,this.featureCache=new Pgg({cache:new Ret({maxSize:1e3}),fill:async(a,s)=>{const A=Number(a.length),l=Number(a.offset),{buffer:c}=await this.bbi.read(gh.Buffer.alloc(A),0,A,l,{signal:s});return c}}),!(i>=0))throw new Error("invalid cirTreeOffset!");const o=dig(n);this.leafParser=o.leafParser,this.bigBedParser=o.bigBedParser}async readWigData(g,I,i,n,C){try{const{refsByName:r,bbi:o,cirTreeOffset:a,isBigEndian:s}=this,A=r[g];A===void 0&&n.complete();const l={chrId:A,start:I,end:i};this.cirTreePromise||(this.cirTreePromise=o.read(gh.Buffer.alloc(48),0,48,Number(a),C));const{buffer:c}=await this.cirTreePromise,u=s?c.readUInt32BE(4):c.readUInt32LE(4);let d=[],h=0;const m=(y,Z,B)=>{try{const G=y.subarray(Z),v=this.leafParser.parse(G);if(v.blocksToFetch&&(d=d.concat(v.blocksToFetch.filter(f).map(w=>({offset:w.blockOffset,length:w.blockSize})))),v.recurOffsets){const w=v.recurOffsets.filter(f).map(V=>Number(V.blockOffset));w.length>0&&p(w,B+1)}}catch(G){n.error(G)}},f=y=>{const{startChrom:Z,startBase:B,endChrom:G,endBase:v}=y;return(ZA||G===A&&v>=I)},b=async(y,Z,B)=>{try{const G=Z.max()-Z.min(),v=Z.min(),w=await this.featureCache.get(`${G}_${v}`,{length:G,offset:v},C.signal);for(let V=0;V{try{h+=y.length;const B=4+Number(u)*32;let G=new nc(y[0],y[0]+B);for(let v=1;vb(y,v,Z))}catch(B){n.error(B)}};return p([Number(a)+48],1)}catch(r){n.error(r)}}parseSummaryBlock(g,I,i){const n=[];let C=I;const r=new DataView(g.buffer,g.byteOffset,g.length);for(;CHF(o.start,o.end,n.start,n.end)):C}parseBigWigBlock(g,I,i){const n=g.subarray(I),C=new DataView(n.buffer,n.byteOffset,n.length);let r=0;r+=4;const o=C.getInt32(r,!0);r+=8;const a=C.getUint32(r,!0);r+=4;const s=C.getUint32(r,!0);r+=4;const A=C.getUint8(r);r+=2;const l=C.getUint16(r,!0);r+=2;const c=new Array(l);switch(A){case 1:for(let u=0;uHF(u.start,u.end,i.start,i.end)):c}async readFeatures(g,I,i={}){try{const{blockType:n,isCompressed:C}=this,{signal:r,request:o}=i,a=sig(I);i1(r),await Promise.all(a.map(async s=>{i1(r);const{length:A,offset:l}=s,c=await this.featureCache.get(`${A}_${l}`,s,r);s.blocks.forEach(u=>{i1(r);let d=Number(u.offset)-Number(s.offset),h=c;switch(C&&(h=aig(c.subarray(d)),d=0),i1(r),n){case"summary":g.next(this.parseSummaryBlock(h,d,o));break;case"bigwig":g.next(this.parseBigWigBlock(h,d,o));break;case"bigbed":g.next(this.parseBigBedBlock(h,d,Number(u.offset)*256,o));break;default:console.warn(`Don't know what to do with ${n}`)}})})),g.complete()}catch(n){g.error(n)}}}var C_=function(e,g){return C_=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(I,i){I.__proto__=i}||function(I,i){for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(I[n]=i[n])},C_(e,g)};function U$(e,g){if(typeof g!="function"&&g!==null)throw new TypeError("Class extends value "+String(g)+" is not a constructor or null");C_(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}function Jle(e){var g=typeof Symbol=="function"&&Symbol.iterator,I=g&&e[g],i=0;if(I)return I.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&i>=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}};throw new TypeError(g?"Object is not iterable.":"Symbol.iterator is not defined.")}function r_(e,g){var I=typeof Symbol=="function"&&e[Symbol.iterator];if(!I)return e;var i=I.call(e),n,C=[],r;try{for(;(g===void 0||g-- >0)&&!(n=i.next()).done;)C.push(n.value)}catch(o){r={error:o}}finally{try{n&&!n.done&&(I=i.return)&&I.call(i)}finally{if(r)throw r.error}}return C}function o_(e,g,I){if(I||arguments.length===2)for(var i=0,n=g.length,C;i{const i=this.references.get(I);i&&(i.requested=!0)})}getUnresolvedReferences(){return Array.from(this.references).filter(([g,I])=>!I.resolved&&!I.requested).map(([g,I])=>g)}}const To=new Map,Fu="___parser_",No={uint8:1,uint16le:2,uint16be:2,uint32le:4,uint32be:4,int8:1,int16le:2,int16be:2,int32le:4,int32be:4,int64be:8,int64le:8,uint64be:8,uint64le:8,floatle:4,floatbe:4,doublele:8,doublebe:8},$R={uint8:"Uint8",uint16le:"Uint16",uint16be:"Uint16",uint32le:"Uint32",uint32be:"Uint32",int8:"Int8",int16le:"Int16",int16be:"Int16",int32le:"Int32",int32be:"Int32",int64be:"BigInt64",int64le:"BigInt64",uint64be:"BigUint64",uint64le:"BigUint64",floatle:"Float32",floatbe:"Float32",doublele:"Float64",doublebe:"Float64"},qR={uint8:!1,uint16le:!0,uint16be:!1,uint32le:!0,uint32be:!1,int8:!1,int16le:!0,int16be:!1,int32le:!0,int32be:!1,int64be:!1,int64le:!0,uint64be:!1,uint64le:!0,floatle:!0,floatbe:!1,doublele:!0,doublebe:!1};class kg{constructor(){this.varName="",this.type="",this.options={},this.endian="be",this.useContextVariables=!1}static start(){return new kg}primitiveGenerateN(g,I){const i=$R[g],n=qR[g];I.pushCode(`${I.generateVariable(this.varName)} = dataView.get${i}(offset, ${n});`),I.pushCode(`offset += ${No[g]};`)}primitiveN(g,I,i){return this.setNextParser(g,I,i)}useThisEndian(g){return g+this.endian.toLowerCase()}uint8(g,I={}){return this.primitiveN("uint8",g,I)}uint16(g,I={}){return this.primitiveN(this.useThisEndian("uint16"),g,I)}uint16le(g,I={}){return this.primitiveN("uint16le",g,I)}uint16be(g,I={}){return this.primitiveN("uint16be",g,I)}uint32(g,I={}){return this.primitiveN(this.useThisEndian("uint32"),g,I)}uint32le(g,I={}){return this.primitiveN("uint32le",g,I)}uint32be(g,I={}){return this.primitiveN("uint32be",g,I)}int8(g,I={}){return this.primitiveN("int8",g,I)}int16(g,I={}){return this.primitiveN(this.useThisEndian("int16"),g,I)}int16le(g,I={}){return this.primitiveN("int16le",g,I)}int16be(g,I={}){return this.primitiveN("int16be",g,I)}int32(g,I={}){return this.primitiveN(this.useThisEndian("int32"),g,I)}int32le(g,I={}){return this.primitiveN("int32le",g,I)}int32be(g,I={}){return this.primitiveN("int32be",g,I)}bigIntVersionCheck(){if(!DataView.prototype.getBigInt64)throw new Error("BigInt64 is unsupported on this runtime")}int64(g,I={}){return this.bigIntVersionCheck(),this.primitiveN(this.useThisEndian("int64"),g,I)}int64be(g,I={}){return this.bigIntVersionCheck(),this.primitiveN("int64be",g,I)}int64le(g,I={}){return this.bigIntVersionCheck(),this.primitiveN("int64le",g,I)}uint64(g,I={}){return this.bigIntVersionCheck(),this.primitiveN(this.useThisEndian("uint64"),g,I)}uint64be(g,I={}){return this.bigIntVersionCheck(),this.primitiveN("uint64be",g,I)}uint64le(g,I={}){return this.bigIntVersionCheck(),this.primitiveN("uint64le",g,I)}floatle(g,I={}){return this.primitiveN("floatle",g,I)}floatbe(g,I={}){return this.primitiveN("floatbe",g,I)}doublele(g,I={}){return this.primitiveN("doublele",g,I)}doublebe(g,I={}){return this.primitiveN("doublebe",g,I)}bitN(g,I,i){return i.length=g,this.setNextParser("bit",I,i)}bit1(g,I={}){return this.bitN(1,g,I)}bit2(g,I={}){return this.bitN(2,g,I)}bit3(g,I={}){return this.bitN(3,g,I)}bit4(g,I={}){return this.bitN(4,g,I)}bit5(g,I={}){return this.bitN(5,g,I)}bit6(g,I={}){return this.bitN(6,g,I)}bit7(g,I={}){return this.bitN(7,g,I)}bit8(g,I={}){return this.bitN(8,g,I)}bit9(g,I={}){return this.bitN(9,g,I)}bit10(g,I={}){return this.bitN(10,g,I)}bit11(g,I={}){return this.bitN(11,g,I)}bit12(g,I={}){return this.bitN(12,g,I)}bit13(g,I={}){return this.bitN(13,g,I)}bit14(g,I={}){return this.bitN(14,g,I)}bit15(g,I={}){return this.bitN(15,g,I)}bit16(g,I={}){return this.bitN(16,g,I)}bit17(g,I={}){return this.bitN(17,g,I)}bit18(g,I={}){return this.bitN(18,g,I)}bit19(g,I={}){return this.bitN(19,g,I)}bit20(g,I={}){return this.bitN(20,g,I)}bit21(g,I={}){return this.bitN(21,g,I)}bit22(g,I={}){return this.bitN(22,g,I)}bit23(g,I={}){return this.bitN(23,g,I)}bit24(g,I={}){return this.bitN(24,g,I)}bit25(g,I={}){return this.bitN(25,g,I)}bit26(g,I={}){return this.bitN(26,g,I)}bit27(g,I={}){return this.bitN(27,g,I)}bit28(g,I={}){return this.bitN(28,g,I)}bit29(g,I={}){return this.bitN(29,g,I)}bit30(g,I={}){return this.bitN(30,g,I)}bit31(g,I={}){return this.bitN(31,g,I)}bit32(g,I={}){return this.bitN(32,g,I)}namely(g){return To.set(g,this),this.alias=g,this}skip(g,I={}){return this.seek(g,I)}seek(g,I={}){if(I.assert)throw new Error("assert option on seek is not allowed.");return this.setNextParser("seek","",{length:g})}string(g,I){if(!I.zeroTerminated&&!I.length&&!I.greedy)throw new Error("One of length, zeroTerminated, or greedy must be defined for string.");if((I.zeroTerminated||I.length)&&I.greedy)throw new Error("greedy is mutually exclusive with length and zeroTerminated for string.");if(I.stripNull&&!(I.length||I.greedy))throw new Error("length or greedy must be defined if stripNull is enabled.");return I.encoding=I.encoding||"utf8",this.setNextParser("string",g,I)}buffer(g,I){if(!I.length&&!I.readUntil)throw new Error("length or readUntil must be defined for buffer.");return this.setNextParser("buffer",g,I)}wrapped(g,I){if(typeof I!="object"&&typeof g=="object"&&(I=g,g=""),!I||!I.wrapper||!I.type)throw new Error("Both wrapper and type must be defined for wrapped.");if(!I.length&&!I.readUntil)throw new Error("length or readUntil must be defined for wrapped.");return this.setNextParser("wrapper",g,I)}array(g,I){if(!I.readUntil&&!I.length&&!I.lengthInBytes)throw new Error("One of readUntil, length and lengthInBytes must be defined for array.");if(!I.type)throw new Error("type is required for array.");if(typeof I.type=="string"&&!To.has(I.type)&&!(I.type in No))throw new Error(`Array element type "${I.type}" is unkown.`);return this.setNextParser("array",g,I)}choice(g,I){if(typeof I!="object"&&typeof g=="object"&&(I=g,g=""),!I)throw new Error("tag and choices are are required for choice.");if(!I.tag)throw new Error("tag is requird for choice.");if(!I.choices)throw new Error("choices is required for choice.");for(const i in I.choices){const n=parseInt(i,10),C=I.choices[n];if(isNaN(n))throw new Error(`Choice key "${i}" is not a number.`);if(typeof C=="string"&&!To.has(C)&&!(C in No))throw new Error(`Choice type "${C}" is unkown.`)}return this.setNextParser("choice",g,I)}nest(g,I){if(typeof I!="object"&&typeof g=="object"&&(I=g,g=""),!I||!I.type)throw new Error("type is required for nest.");if(!(I.type instanceof kg)&&!To.has(I.type))throw new Error("type must be a known parser name or a Parser object.");if(!(I.type instanceof kg)&&!g)throw new Error("type must be a Parser object if the variable name is omitted.");return this.setNextParser("nest",g,I)}pointer(g,I){if(!I.offset)throw new Error("offset is required for pointer.");if(!I.type)throw new Error("type is required for pointer.");if(typeof I.type=="string"&&!(I.type in No)&&!To.has(I.type))throw new Error(`Pointer type "${I.type}" is unkown.`);return this.setNextParser("pointer",g,I)}saveOffset(g,I={}){return this.setNextParser("saveOffset",g,I)}endianness(g){switch(g.toLowerCase()){case"little":this.endian="le";break;case"big":this.endian="be";break;default:throw new Error('endianness must be one of "little" or "big"')}return this}endianess(g){return this.endianness(g)}useContextVars(g=!0){return this.useContextVariables=g,this}create(g){if(!(g instanceof Function))throw new Error("Constructor must be a Function object.");return this.constructorFn=g,this}getContext(g){const I=new Bgg(g,this.useContextVariables);return I.pushCode("var dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.length);"),this.alias?(this.addAliasedCode(I),I.pushCode(`return ${Fu+this.alias}(0).result;`)):this.addRawCode(I),I}getCode(){const g="imports";return this.getContext(g).code}addRawCode(g){g.pushCode("var offset = 0;"),g.pushCode(`var vars = ${this.constructorFn?"new constructorFn()":"{}"};`),g.pushCode("vars.$parent = null;"),g.pushCode("vars.$root = vars;"),this.generate(g),this.resolveReferences(g),g.pushCode("delete vars.$parent;"),g.pushCode("delete vars.$root;"),g.pushCode("return vars;")}addAliasedCode(g){return g.pushCode(`function ${Fu+this.alias}(offset, context) {`),g.pushCode(`var vars = ${this.constructorFn?"new constructorFn()":"{}"};`),g.pushCode("var ctx = Object.assign({$parent: null, $root: vars}, context || {});"),g.pushCode("vars = Object.assign(vars, ctx);"),this.generate(g),g.markResolved(this.alias),this.resolveReferences(g),g.pushCode("Object.keys(ctx).forEach(function (item) { delete vars[item]; });"),g.pushCode("return { offset: offset, result: vars };"),g.pushCode("}"),g}resolveReferences(g){const I=g.getUnresolvedReferences();g.markRequested(I),I.forEach(i=>{var n;(n=To.get(i))===null||n===void 0||n.addAliasedCode(g)})}compile(){const g="imports",I=this.getContext(g);this.compiled=new Function(g,"TextDecoder",`return function (buffer, constructorFn) { ${I.code} };`)(I.imports,TextDecoder)}sizeOf(){let g=NaN;if(Object.keys(No).indexOf(this.type)>=0)g=No[this.type];else if(this.type==="string"&&typeof this.options.length=="number")g=this.options.length;else if(this.type==="buffer"&&typeof this.options.length=="number")g=this.options.length;else if(this.type==="array"&&typeof this.options.length=="number"){let I=NaN;typeof this.options.type=="string"?I=No[this.options.type]:this.options.type instanceof kg&&(I=this.options.type.sizeOf()),g=this.options.length*I}else this.type==="seek"?g=this.options.length:this.type==="nest"?g=this.options.type.sizeOf():this.type||(g=0);return this.next&&(g+=this.next.sizeOf()),g}parse(g){return this.compiled||this.compile(),this.compiled(g,this.constructorFn)}setNextParser(g,I,i){const n=new kg;return n.type=g,n.varName=I,n.options=i,n.endian=this.endian,this.head?this.head.next=n:this.next=n,this.head=n,this}generate(g){if(this.type){switch(this.type){case"uint8":case"uint16le":case"uint16be":case"uint32le":case"uint32be":case"int8":case"int16le":case"int16be":case"int32le":case"int32be":case"int64be":case"int64le":case"uint64be":case"uint64le":case"floatle":case"floatbe":case"doublele":case"doublebe":this.primitiveGenerateN(this.type,g);break;case"bit":this.generateBit(g);break;case"string":this.generateString(g);break;case"buffer":this.generateBuffer(g);break;case"seek":this.generateSeek(g);break;case"nest":this.generateNest(g);break;case"array":this.generateArray(g);break;case"choice":this.generateChoice(g);break;case"pointer":this.generatePointer(g);break;case"saveOffset":this.generateSaveOffset(g);break;case"wrapper":this.generateWrapper(g);break}this.type!=="bit"&&this.generateAssert(g)}const I=g.generateVariable(this.varName);return this.options.formatter&&this.type!=="bit"&&this.generateFormatter(g,I,this.options.formatter),this.generateNext(g)}generateAssert(g){if(!this.options.assert)return;const I=g.generateVariable(this.varName);switch(typeof this.options.assert){case"function":{const i=g.addImport(this.options.assert);g.pushCode(`if (!${i}.call(vars, ${I})) {`)}break;case"number":g.pushCode(`if (${this.options.assert} !== ${I}) {`);break;case"string":g.pushCode(`if (${JSON.stringify(this.options.assert)} !== ${I}) {`);break;default:throw new Error("assert option must be a string, number or a function.")}g.generateError(`"Assertion error: ${I} is " + ${JSON.stringify(this.options.assert.toString())}`),g.pushCode("}")}generateNext(g){return this.next&&(g=this.next.generate(g)),g}generateBit(g){const I=JSON.parse(JSON.stringify(this));if(I.options=this.options,I.generateAssert=this.generateAssert.bind(this),I.generateFormatter=this.generateFormatter.bind(this),I.varName=g.generateVariable(I.varName),g.bitFields.push(I),!this.next||this.next&&["bit","nest"].indexOf(this.next.type)<0){const i=g.generateTmpVariable();g.pushCode(`var ${i} = 0;`);const n=(A=0)=>{let l=0;for(let c=A;c32)break;l+=u}return l},C=A=>(A<=8?(g.pushCode(`${i} = dataView.getUint8(offset);`),A=8):A<=16?(g.pushCode(`${i} = dataView.getUint16(offset);`),A=16):A<=24?(g.pushCode(`${i} = (dataView.getUint16(offset) << 8) | dataView.getUint8(offset + 2);`),A=24):(g.pushCode(`${i} = dataView.getUint32(offset);`),A=32),g.pushCode(`offset += ${A/8};`),A);let r=0;const o=this.endian==="be";let a=0,s=0;g.bitFields.forEach((A,l)=>{let c=A.options.length;if(c>s){if(s){const h=-1>>>32-s;g.pushCode(`${A.varName} = (${i} & 0x${h.toString(16)}) << ${c-s};`),c-=s}r=0,s=a=C(n(l)-s)}const u=o?a-r-c:r,d=-1>>>32-c;g.pushCode(`${A.varName} ${c> ${u} & 0x${d.toString(16)};`),A.options.length===32&&g.pushCode(`${A.varName} >>>= 0`),A.options.assert&&A.generateAssert(g),A.options.formatter&&A.generateFormatter(g,A.varName,A.options.formatter),r+=c,s-=c}),g.bitFields=[]}}generateSeek(g){const I=g.generateOption(this.options.length);g.pushCode(`offset += ${I};`)}generateString(g){const I=g.generateVariable(this.varName),i=g.generateTmpVariable(),n=this.options.encoding,C=n.toLowerCase()==="hex",r='b => b.toString(16).padStart(2, "0")';if(this.options.length&&this.options.zeroTerminated){const o=this.options.length;g.pushCode(`var ${i} = offset;`),g.pushCode(`while(dataView.getUint8(offset++) !== 0 && offset - ${i} < ${o});`);const a=`offset - ${i} < ${o} ? offset - 1 : offset`;g.pushCode(C?`${I} = Array.from(buffer.subarray(${i}, ${a}), ${r}).join('');`:`${I} = new TextDecoder('${n}').decode(buffer.subarray(${i}, ${a}));`)}else if(this.options.length){const o=g.generateOption(this.options.length);g.pushCode(C?`${I} = Array.from(buffer.subarray(offset, offset + ${o}), ${r}).join('');`:`${I} = new TextDecoder('${n}').decode(buffer.subarray(offset, offset + ${o}));`),g.pushCode(`offset += ${o};`)}else this.options.zeroTerminated?(g.pushCode(`var ${i} = offset;`),g.pushCode("while(dataView.getUint8(offset++) !== 0);"),g.pushCode(C?`${I} = Array.from(buffer.subarray(${i}, offset - 1), ${r}).join('');`:`${I} = new TextDecoder('${n}').decode(buffer.subarray(${i}, offset - 1));`)):this.options.greedy&&(g.pushCode(`var ${i} = offset;`),g.pushCode("while(buffer.length > offset++);"),g.pushCode(C?`${I} = Array.from(buffer.subarray(${i}, offset), ${r}).join('');`:`${I} = new TextDecoder('${n}').decode(buffer.subarray(${i}, offset));`));this.options.stripNull&&g.pushCode(`${I} = ${I}.replace(/\\x00+$/g, '')`)}generateBuffer(g){const I=g.generateVariable(this.varName);if(typeof this.options.readUntil=="function"){const i=this.options.readUntil,n=g.generateTmpVariable(),C=g.generateTmpVariable();g.pushCode(`var ${n} = offset;`),g.pushCode(`var ${C} = 0;`),g.pushCode("while (offset < buffer.length) {"),g.pushCode(`${C} = dataView.getUint8(offset);`);const r=g.addImport(i);g.pushCode(`if (${r}.call(${g.generateVariable()}, ${C}, buffer.subarray(offset))) break;`),g.pushCode("offset += 1;"),g.pushCode("}"),g.pushCode(`${I} = buffer.subarray(${n}, offset);`)}else if(this.options.readUntil==="eof")g.pushCode(`${I} = buffer.subarray(offset);`);else{const i=g.generateOption(this.options.length);g.pushCode(`${I} = buffer.subarray(offset, offset + ${i});`),g.pushCode(`offset += ${i};`)}this.options.clone&&g.pushCode(`${I} = buffer.constructor.from(${I});`)}generateArray(g){const I=g.generateOption(this.options.length),i=g.generateOption(this.options.lengthInBytes),n=this.options.type,C=g.generateTmpVariable(),r=g.generateVariable(this.varName),o=g.generateTmpVariable(),a=this.options.key,s=typeof a=="string";if(s?g.pushCode(`${r} = {};`):g.pushCode(`${r} = [];`),typeof this.options.readUntil=="function"?g.pushCode("do {"):this.options.readUntil==="eof"?g.pushCode(`for (var ${C} = 0; offset < buffer.length; ${C}++) {`):i!==void 0?g.pushCode(`for (var ${C} = offset + ${i}; offset < ${C}; ) {`):g.pushCode(`for (var ${C} = ${I}; ${C} > 0; ${C}--) {`),typeof n=="string")if(To.get(n)){const A=g.generateTmpVariable();if(g.pushCode(`var ${A} = ${Fu+n}(offset, {`),g.useContextVariables){const l=g.generateVariable();g.pushCode(`$parent: ${l},`),g.pushCode(`$root: ${l}.$root,`),!this.options.readUntil&&i===void 0&&g.pushCode(`$index: ${I} - ${C},`)}g.pushCode("});"),g.pushCode(`var ${o} = ${A}.result; offset = ${A}.offset;`),n!==this.alias&&g.addReference(n)}else{const A=$R[n],l=qR[n];g.pushCode(`var ${o} = dataView.get${A}(offset, ${l});`),g.pushCode(`offset += ${No[n]};`)}else if(n instanceof kg){g.pushCode(`var ${o} = {};`);const A=g.generateVariable();g.pushScope(o),g.useContextVariables&&(g.pushCode(`${o}.$parent = ${A};`),g.pushCode(`${o}.$root = ${A}.$root;`),!this.options.readUntil&&i===void 0&&g.pushCode(`${o}.$index = ${I} - ${C};`)),n.generate(g),g.useContextVariables&&(g.pushCode(`delete ${o}.$parent;`),g.pushCode(`delete ${o}.$root;`),g.pushCode(`delete ${o}.$index;`)),g.popScope()}if(s?g.pushCode(`${r}[${o}.${a}] = ${o};`):g.pushCode(`${r}.push(${o});`),g.pushCode("}"),typeof this.options.readUntil=="function"){const A=this.options.readUntil,l=g.addImport(A);g.pushCode(`while (!${l}.call(${g.generateVariable()}, ${o}, buffer.subarray(offset)));`)}}generateChoiceCase(g,I,i){if(typeof i=="string"){const n=g.generateVariable(this.varName);if(To.has(i)){const C=g.generateTmpVariable();g.pushCode(`var ${C} = ${Fu+i}(offset, {`),g.useContextVariables&&(g.pushCode(`$parent: ${n}.$parent,`),g.pushCode(`$root: ${n}.$root,`)),g.pushCode("});"),g.pushCode(`${n} = ${C}.result; offset = ${C}.offset;`),i!==this.alias&&g.addReference(i)}else{const C=$R[i],r=qR[i];g.pushCode(`${n} = dataView.get${C}(offset, ${r});`),g.pushCode(`offset += ${No[i]}`)}}else i instanceof kg&&(g.pushPath(I),i.generate(g),g.popPath(I))}generateChoice(g){const I=g.generateOption(this.options.tag),i=g.generateVariable(this.varName);if(this.varName&&(g.pushCode(`${i} = {};`),g.useContextVariables)){const n=g.generateVariable();g.pushCode(`${i}.$parent = ${n};`),g.pushCode(`${i}.$root = ${n}.$root;`)}g.pushCode(`switch(${I}) {`);for(const n in this.options.choices){const C=parseInt(n,10),r=this.options.choices[C];g.pushCode(`case ${C}:`),this.generateChoiceCase(g,this.varName,r),g.pushCode("break;")}g.pushCode("default:"),this.options.defaultChoice?this.generateChoiceCase(g,this.varName,this.options.defaultChoice):g.generateError(`"Met undefined tag value " + ${I} + " at choice"`),g.pushCode("}"),this.varName&&g.useContextVariables&&(g.pushCode(`delete ${i}.$parent;`),g.pushCode(`delete ${i}.$root;`))}generateNest(g){const I=g.generateVariable(this.varName);if(this.options.type instanceof kg){if(this.varName&&(g.pushCode(`${I} = {};`),g.useContextVariables)){const i=g.generateVariable();g.pushCode(`${I}.$parent = ${i};`),g.pushCode(`${I}.$root = ${i}.$root;`)}g.pushPath(this.varName),this.options.type.generate(g),g.popPath(this.varName),this.varName&&g.useContextVariables&&g.useContextVariables&&(g.pushCode(`delete ${I}.$parent;`),g.pushCode(`delete ${I}.$root;`))}else if(To.has(this.options.type)){const i=g.generateTmpVariable();if(g.pushCode(`var ${i} = ${Fu+this.options.type}(offset, {`),g.useContextVariables){const n=g.generateVariable();g.pushCode(`$parent: ${n},`),g.pushCode(`$root: ${n}.$root,`)}g.pushCode("});"),g.pushCode(`${I} = ${i}.result; offset = ${i}.offset;`),this.options.type!==this.alias&&g.addReference(this.options.type)}}generateWrapper(g){const I=g.generateVariable(this.varName),i=g.generateTmpVariable();if(typeof this.options.readUntil=="function"){const a=this.options.readUntil,s=g.generateTmpVariable(),A=g.generateTmpVariable();g.pushCode(`var ${s} = offset;`),g.pushCode(`var ${A} = 0;`),g.pushCode("while (offset < buffer.length) {"),g.pushCode(`${A} = dataView.getUint8(offset);`);const l=g.addImport(a);g.pushCode(`if (${l}.call(${g.generateVariable()}, ${A}, buffer.subarray(offset))) break;`),g.pushCode("offset += 1;"),g.pushCode("}"),g.pushCode(`${i} = buffer.subarray(${s}, offset);`)}else if(this.options.readUntil==="eof")g.pushCode(`${i} = buffer.subarray(offset);`);else{const a=g.generateOption(this.options.length);g.pushCode(`${i} = buffer.subarray(offset, offset + ${a});`),g.pushCode(`offset += ${a};`)}this.options.clone&&g.pushCode(`${i} = buffer.constructor.from(${i});`);const n=g.generateTmpVariable(),C=g.generateTmpVariable(),r=g.generateTmpVariable(),o=g.addImport(this.options.wrapper);if(g.pushCode(`${i} = ${o}.call(this, ${i}).subarray(0);`),g.pushCode(`var ${n} = buffer;`),g.pushCode(`var ${C} = offset;`),g.pushCode(`var ${r} = dataView;`),g.pushCode(`buffer = ${i};`),g.pushCode("offset = 0;"),g.pushCode("dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.length);"),this.options.type instanceof kg)this.varName&&g.pushCode(`${I} = {};`),g.pushPath(this.varName),this.options.type.generate(g),g.popPath(this.varName);else if(To.has(this.options.type)){const a=g.generateTmpVariable();g.pushCode(`var ${a} = ${Fu+this.options.type}(0);`),g.pushCode(`${I} = ${a}.result;`),this.options.type!==this.alias&&g.addReference(this.options.type)}g.pushCode(`buffer = ${n};`),g.pushCode(`dataView = ${r};`),g.pushCode(`offset = ${C};`)}generateFormatter(g,I,i){if(typeof i=="function"){const n=g.addImport(i);g.pushCode(`${I} = ${n}.call(${g.generateVariable()}, ${I});`)}}generatePointer(g){const I=this.options.type,i=g.generateOption(this.options.offset),n=g.generateTmpVariable(),C=g.generateVariable(this.varName);if(g.pushCode(`var ${n} = offset;`),g.pushCode(`offset = ${i};`),this.options.type instanceof kg){if(g.pushCode(`${C} = {};`),g.useContextVariables){const r=g.generateVariable();g.pushCode(`${C}.$parent = ${r};`),g.pushCode(`${C}.$root = ${r}.$root;`)}g.pushPath(this.varName),this.options.type.generate(g),g.popPath(this.varName),g.useContextVariables&&(g.pushCode(`delete ${C}.$parent;`),g.pushCode(`delete ${C}.$root;`))}else if(To.has(this.options.type)){const r=g.generateTmpVariable();if(g.pushCode(`var ${r} = ${Fu+this.options.type}(offset, {`),g.useContextVariables){const o=g.generateVariable();g.pushCode(`$parent: ${o},`),g.pushCode(`$root: ${o}.$root,`)}g.pushCode("});"),g.pushCode(`${C} = ${r}.result; offset = ${r}.offset;`),this.options.type!==this.alias&&g.addReference(this.options.type)}else if(Object.keys(No).indexOf(this.options.type)>=0){const r=$R[I],o=qR[I];g.pushCode(`${C} = dataView.get${r}(offset, ${o});`),g.pushCode(`offset += ${No[I]};`)}g.pushCode(`offset = ${n};`)}generateSaveOffset(g){const I=g.generateVariable(this.varName);g.pushCode(`${I} = offset`)}}var l2e={},E$={},xh={},Tw={};Object.defineProperty(Tw,"__esModule",{value:!0});function M$(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function cle(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function fG(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Vgg(e,g){if(g&&(typeof g=="object"||typeof g=="function"))return g;if(g!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return fG(e)}function Rgg(e){var g=wgg();return function(){var i=d0(e),n;if(g){var C=d0(this).constructor;n=Reflect.construct(i,arguments,C)}else n=i.apply(this,arguments);return Vgg(this,n)}}function Wgg(e,g){for(;!Object.prototype.hasOwnProperty.call(e,g)&&(e=d0(e),e!==null););return e}function YW(){return typeof Reflect<"u"&&Reflect.get?YW=Reflect.get.bind():YW=function(g,I,i){var n=Wgg(g,I);if(n){var C=Object.getOwnPropertyDescriptor(n,I);return C.get?C.get.call(arguments.length<3?g:i):C.value}},YW.apply(this,arguments)}var ule=function(){function e(){M$(this,e),Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}return z$(e,[{key:"addEventListener",value:function(I,i,n){I in this.listeners||(this.listeners[I]=[]),this.listeners[I].push({callback:i,options:n})}},{key:"removeEventListener",value:function(I,i){if(I in this.listeners){for(var n=this.listeners[I],C=0,r=n.length;C"u")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch{n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(i)}},{key:"toString",value:function(){return"[object AbortController]"}}]),e}();typeof Symbol<"u"&&Symbol.toStringTag&&(c2e.prototype[Symbol.toStringTag]="AbortController",P$.prototype[Symbol.toStringTag]="AbortSignal");function Xgg(e){return e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof e.Request=="function"&&!e.Request.prototype.hasOwnProperty("signal")||!e.AbortController}function Hgg(e){typeof e=="function"&&(e={fetch:e});var g=e,I=g.fetch,i=g.Request,n=i===void 0?I.Request:i,C=g.AbortController,r=g.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL,o=r===void 0?!1:r;if(!Xgg({fetch:I,Request:n,AbortController:C,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o}))return{fetch:I,Request:a};var a=n;(a&&!a.prototype.hasOwnProperty("signal")||o)&&(a=function(c,u){var d;u&&u.signal&&(d=u.signal,delete u.signal);var h=new n(c,u);return d&&Object.defineProperty(h,"signal",{writable:!1,enumerable:!1,configurable:!0,value:d}),h},a.prototype=n.prototype);var s=I,A=function(c,u){var d=a&&a.prototype.isPrototypeOf(c)?c.signal:u?u.signal:void 0;if(d){var h;try{h=new DOMException("Aborted","AbortError")}catch{h=new Error("Aborted"),h.name="AbortError"}if(d.aborted)return Promise.reject(h);var m=new Promise(function(f,b){d.addEventListener("abort",function(){return b(h)},{once:!0})});return u&&u.signal&&delete u.signal,Promise.race([m,s(c,u)])}return s(c,u)};return{fetch:A,Request:a}}Tw.AbortController=c2e;Tw.AbortSignal=P$;Tw.abortableFetch=Hgg;Object.defineProperty(xh,"__esModule",{value:!0});xh.AbortSignal=xh.AbortController=void 0;const u2e=Tw;var SH=function(){if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof Ih<"u")return Ih;throw new Error("unable to locate global object")};let Tgg=typeof SH().AbortController>"u"?u2e.AbortController:SH().AbortController;xh.AbortController=Tgg;let Ngg=typeof SH().AbortController>"u"?u2e.AbortSignal:SH().AbortSignal;xh.AbortSignal=Ngg;var J$={};Object.defineProperty(J$,"__esModule",{value:!0});const kgg=xh;class Ygg{}class Kgg{constructor(){this.signals=new Set,this.abortController=new kgg.AbortController}addSignal(g=new Ygg){if(this.signal.aborted)throw new Error("cannot add a signal, already aborted!");this.signals.add(g),g.aborted?this.handleAborted(g):typeof g.addEventListener=="function"&&g.addEventListener("abort",()=>{this.handleAborted(g)})}handleAborted(g){this.signals.delete(g),this.signals.size===0&&this.abortController.abort()}get signal(){return this.abortController.signal}abort(){this.abortController.abort()}}J$.default=Kgg;var O$={};Object.defineProperty(O$,"__esModule",{value:!0});class xgg{constructor(){this.callbacks=new Set}addCallback(g=()=>{}){this.callbacks.add(g),g(this.currentMessage)}callback(g){this.currentMessage=g,this.callbacks.forEach(I=>{I(g)})}}O$.default=xgg;var d2e=Ih&&Ih.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(E$,"__esModule",{value:!0});const Dgg=xh,Fgg=d2e(J$),Egg=d2e(O$);class wH{constructor({fill:g,cache:I}){if(typeof g!="function")throw new TypeError("must pass a fill function");if(typeof I!="object")throw new TypeError("must pass a cache object");if(typeof I.get!="function"||typeof I.set!="function"||typeof I.delete!="function")throw new TypeError("cache must implement get(key), set(key, val), and and delete(key)");this.cache=I,this.fillCallback=g}static isAbortException(g){return g.name==="AbortError"||g.code==="ERR_ABORTED"||g.message==="AbortError: aborted"||g.message==="Error: aborted"}evict(g,I){this.cache.get(g)===I&&this.cache.delete(g)}fill(g,I,i,n){const C=new Fgg.default,r=new Egg.default;r.addCallback(n);const o={aborter:C,promise:this.fillCallback(I,C.signal,a=>{r.callback(a)}),settled:!1,statusReporter:r,get aborted(){return this.aborter.signal.aborted}};o.aborter.addSignal(i),o.aborter.signal.addEventListener("abort",()=>{o.settled||this.evict(g,o)}),o.promise.then(()=>{o.settled=!0},()=>{o.settled=!0,this.evict(g,o)}).catch(a=>{throw console.error(a),a}),this.cache.set(g,o)}static checkSinglePromise(g,I){function i(){if(I&&I.aborted)throw Object.assign(new Error("aborted"),{code:"ERR_ABORTED"})}return g.then(n=>(i(),n),n=>{throw i(),n})}has(g){return this.cache.has(g)}get(g,I,i,n){if(!i&&I instanceof Dgg.AbortSignal)throw new TypeError("second get argument appears to be an AbortSignal, perhaps you meant to pass `null` for the fill data?");const C=this.cache.get(g);return C?C.aborted&&!C.settled?(this.evict(g,C),this.get(g,I,i,n)):C.settled?C.promise:(C.aborter.addSignal(i),C.statusReporter.addCallback(n),wH.checkSinglePromise(C.promise,i)):(this.fill(g,I,i,n),wH.checkSinglePromise(this.cache.get(g).promise,i))}delete(g){const I=this.cache.get(g);I&&(I.settled||I.aborter.abort(),this.cache.delete(g))}clear(){const g=this.cache.keys();let I=0;for(let i=g.next();!i.done;i=g.next())this.delete(i.value),I+=1;return I}}E$.default=wH;var Mgg=Ih&&Ih.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(l2e,"__esModule",{value:!0});const zgg=Mgg(E$);var Pgg=l2e.default=zgg.default;class nc{constructor(g,I){this.ranges=arguments.length===2?[{min:g,max:I}]:0 in g?Object.assign({},g):[g]}min(){return this.ranges[0].min}max(){return this.ranges[this.ranges.length-1].max}contains(g){for(let I=0;I=g)return!0}return!1}isContiguous(){return this.ranges.length>1}getRanges(){return this.ranges.map(g=>new nc(g.min,g.max))}toString(){return this.ranges.map(g=>`[${g.min}-${g.max}]`).join(",")}union(g){const I=this.getRanges().concat(g.getRanges()).sort(this.rangeOrder),i=[];let n=I[0];for(let C=1;Cn.max()+1?(i.push(n),n=r):r.max()>n.max()&&(n=new nc(n.min(),r.max()))}return i.push(n),i.length===1?i[0]:new nc(i)}intersection(g){let I=this,i=g;const n=this.ranges(),C=i.ranges(),r=n.length,o=C.length;let a=0,s=0;const A=[];for(;a=l&&A.push(new nc(l,c)),I.max()>i.max()?s+=1:a+=1}if(A.length===0)throw new Error("found range of length 0");return A.length===1?A[0]:new nc(A)}coverage(){let g=0;const I=this.ranges();for(let i=0;in.min()?1:i.max()i.max()?1:0}}function dy(e){let g=e.length;for(;--g>=0;)e[g]=0}const Jgg=3,Ogg=258,h2e=29,_gg=256,Lgg=_gg+1+h2e,m2e=30,Ugg=512,Qgg=new Array((Lgg+2)*2);dy(Qgg);const jgg=new Array(m2e*2);dy(jgg);const $gg=new Array(Ugg);dy($gg);const qgg=new Array(Ogg-Jgg+1);dy(qgg);const eIg=new Array(h2e);dy(eIg);const tIg=new Array(m2e);dy(tIg);const gIg=(e,g,I,i)=>{let n=e&65535|0,C=e>>>16&65535|0,r=0;for(;I!==0;){r=I>2e3?2e3:I,I-=r;do n=n+g[i++]|0,C=C+n|0;while(--r);n%=65521,C%=65521}return n|C<<16|0};var I_=gIg;const IIg=()=>{let e,g=[];for(var I=0;I<256;I++){e=I;for(var i=0;i<8;i++)e=e&1?3988292384^e>>>1:e>>>1;g[I]=e}return g},iIg=new Uint32Array(IIg()),nIg=(e,g,I,i)=>{const n=iIg,C=i+I;e^=-1;for(let r=i;r>>8^n[(e^g[r])&255];return e^-1};var Na=nIg,i_={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},_$={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const CIg=(e,g)=>Object.prototype.hasOwnProperty.call(e,g);var rIg=function(e){const g=Array.prototype.slice.call(arguments,1);for(;g.length;){const I=g.shift();if(I){if(typeof I!="object")throw new TypeError(I+"must be non-object");for(const i in I)CIg(I,i)&&(e[i]=I[i])}}return e},oIg=e=>{let g=0;for(let i=0,n=e.length;i=252?6:e>=248?5:e>=240?4:e>=224?3:e>=192?2:1;oS[254]=oS[254]=1;var aIg=e=>{if(typeof TextEncoder=="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(e);let g,I,i,n,C,r=e.length,o=0;for(n=0;n>>6,g[C++]=128|I&63):I<65536?(g[C++]=224|I>>>12,g[C++]=128|I>>>6&63,g[C++]=128|I&63):(g[C++]=240|I>>>18,g[C++]=128|I>>>12&63,g[C++]=128|I>>>6&63,g[C++]=128|I&63);return g};const AIg=(e,g)=>{if(g<65534&&e.subarray&&p2e)return String.fromCharCode.apply(null,e.length===g?e:e.subarray(0,g));let I="";for(let i=0;i{const I=g||e.length;if(typeof TextDecoder=="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(e.subarray(0,g));let i,n;const C=new Array(I*2);for(n=0,i=0;i4){C[n++]=65533,i+=o-1;continue}for(r&=o===2?31:o===3?15:7;o>1&&i1){C[n++]=65533;continue}r<65536?C[n++]=r:(r-=65536,C[n++]=55296|r>>10&1023,C[n++]=56320|r&1023)}return AIg(C,n)},lIg=(e,g)=>{g=g||e.length,g>e.length&&(g=e.length);let I=g-1;for(;I>=0&&(e[I]&192)===128;)I--;return I<0||I===0?g:I+oS[e[I]]>g?I:g},n_={string2buf:aIg,buf2string:sIg,utf8border:lIg};function cIg(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}var uIg=cIg;const e1=16209,dIg=16191;var hIg=function(g,I){let i,n,C,r,o,a,s,A,l,c,u,d,h,m,f,b,p,y,Z,B,G,v,w,V;const S=g.state;i=g.next_in,w=g.input,n=i+(g.avail_in-5),C=g.next_out,V=g.output,r=C-(I-g.avail_out),o=C+(g.avail_out-257),a=S.dmax,s=S.wsize,A=S.whave,l=S.wnext,c=S.window,u=S.hold,d=S.bits,h=S.lencode,m=S.distcode,f=(1<>>24,u>>>=y,d-=y,y=p>>>16&255,y===0)V[C++]=p&65535;else if(y&16){Z=p&65535,y&=15,y&&(d>>=y,d-=y),d<15&&(u+=w[i++]<>>24,u>>>=y,d-=y,y=p>>>16&255,y&16){if(B=p&65535,y&=15,da){g.msg="invalid distance too far back",S.mode=e1;break e}if(u>>>=y,d-=y,y=C-r,B>y){if(y=B-y,y>A&&S.sane){g.msg="invalid distance too far back",S.mode=e1;break e}if(G=0,v=c,l===0){if(G+=s-y,y2;)V[C++]=v[G++],V[C++]=v[G++],V[C++]=v[G++],Z-=3;Z&&(V[C++]=v[G++],Z>1&&(V[C++]=v[G++]))}else{G=C-B;do V[C++]=V[G++],V[C++]=V[G++],V[C++]=V[G++],Z-=3;while(Z>2);Z&&(V[C++]=V[G++],Z>1&&(V[C++]=V[G++]))}}else if(y&64){g.msg="invalid distance code",S.mode=e1;break e}else{p=m[(p&65535)+(u&(1<>3,i-=Z,d-=Z<<3,u&=(1<{const a=o.bits;let s=0,A=0,l=0,c=0,u=0,d=0,h=0,m=0,f=0,b=0,p,y,Z,B,G,v=null,w;const V=new Uint16Array(of+1),S=new Uint16Array(of+1);let X=null,W,R,H;for(s=0;s<=of;s++)V[s]=0;for(A=0;A=1&&V[c]===0;c--);if(u>c&&(u=c),c===0)return n[C++]=1<<24|64<<16|0,n[C++]=1<<24|64<<16|0,o.bits=1,0;for(l=1;l0&&(e===mle||c!==1))return-1;for(S[1]=0,s=1;sdle||e===fle&&f>hle)return 1;for(;;){W=s-h,r[A]+1=w?(R=X[r[A]-w],H=v[r[A]-w]):(R=32+64,H=0),p=1<>h)+y]=W<<24|R<<16|H|0;while(y!==0);for(p=1<>=1;if(p!==0?(b&=p-1,b+=p):b=0,A++,--V[s]===0){if(s===c)break;s=g[I+r[A]]}if(s>u&&(b&B)!==Z){for(h===0&&(h=u),G+=l,d=s-h,m=1<dle||e===fle&&f>hle)return 1;Z=b&B,n[Z]=u<<24|d<<16|G-C|0}}return b!==0&&(n[G+b]=s-h<<24|64<<16|0),o.bits=u,0};var Tv=yIg;const ZIg=0,b2e=1,y2e=2,{Z_FINISH:ple,Z_BLOCK:GIg,Z_TREES:t1,Z_OK:Dh,Z_STREAM_END:vIg,Z_NEED_DICT:BIg,Z_STREAM_ERROR:oo,Z_DATA_ERROR:Z2e,Z_MEM_ERROR:G2e,Z_BUF_ERROR:SIg,Z_DEFLATED:ble}=_$,jk=16180,yle=16181,Zle=16182,Gle=16183,vle=16184,Ble=16185,Sle=16186,wle=16187,Vle=16188,Rle=16189,VH=16190,_A=16191,BF=16192,Wle=16193,SF=16194,Xle=16195,Hle=16196,Tle=16197,Nle=16198,g1=16199,I1=16200,kle=16201,Yle=16202,Kle=16203,xle=16204,Dle=16205,wF=16206,Fle=16207,Ele=16208,vI=16209,v2e=16210,B2e=16211,wIg=852,VIg=592,RIg=15,WIg=RIg,Mle=e=>(e>>>24&255)+(e>>>8&65280)+((e&65280)<<8)+((e&255)<<24);function XIg(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const Gm=e=>{if(!e)return 1;const g=e.state;return!g||g.strm!==e||g.modeB2e?1:0},S2e=e=>{if(Gm(e))return oo;const g=e.state;return e.total_in=e.total_out=g.total=0,e.msg="",g.wrap&&(e.adler=g.wrap&1),g.mode=jk,g.last=0,g.havedict=0,g.flags=-1,g.dmax=32768,g.head=null,g.hold=0,g.bits=0,g.lencode=g.lendyn=new Int32Array(wIg),g.distcode=g.distdyn=new Int32Array(VIg),g.sane=1,g.back=-1,Dh},w2e=e=>{if(Gm(e))return oo;const g=e.state;return g.wsize=0,g.whave=0,g.wnext=0,S2e(e)},V2e=(e,g)=>{let I;if(Gm(e))return oo;const i=e.state;return g<0?(I=0,g=-g):(I=(g>>4)+5,g<48&&(g&=15)),g&&(g<8||g>15)?oo:(i.window!==null&&i.wbits!==g&&(i.window=null),i.wrap=I,i.wbits=g,w2e(e))},R2e=(e,g)=>{if(!e)return oo;const I=new XIg;e.state=I,I.strm=e,I.window=null,I.mode=jk;const i=V2e(e,g);return i!==Dh&&(e.state=null),i},HIg=e=>R2e(e,WIg);let zle=!0,VF,RF;const TIg=e=>{if(zle){VF=new Int32Array(512),RF=new Int32Array(32);let g=0;for(;g<144;)e.lens[g++]=8;for(;g<256;)e.lens[g++]=9;for(;g<280;)e.lens[g++]=7;for(;g<288;)e.lens[g++]=8;for(Tv(b2e,e.lens,0,288,VF,0,e.work,{bits:9}),g=0;g<32;)e.lens[g++]=5;Tv(y2e,e.lens,0,32,RF,0,e.work,{bits:5}),zle=!1}e.lencode=VF,e.lenbits=9,e.distcode=RF,e.distbits=5},W2e=(e,g,I,i)=>{let n;const C=e.state;return C.window===null&&(C.wsize=1<=C.wsize?(C.window.set(g.subarray(I-C.wsize,I),0),C.wnext=0,C.whave=C.wsize):(n=C.wsize-C.wnext,n>i&&(n=i),C.window.set(g.subarray(I-i,I-i+n),C.wnext),i-=n,i?(C.window.set(g.subarray(I-i,I),0),C.wnext=i,C.whave=C.wsize):(C.wnext+=n,C.wnext===C.wsize&&(C.wnext=0),C.whave{let I,i,n,C,r,o,a,s,A,l,c,u,d,h,m=0,f,b,p,y,Z,B,G,v;const w=new Uint8Array(4);let V,S;const X=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(Gm(e)||!e.output||!e.input&&e.avail_in!==0)return oo;I=e.state,I.mode===_A&&(I.mode=BF),r=e.next_out,n=e.output,a=e.avail_out,C=e.next_in,i=e.input,o=e.avail_in,s=I.hold,A=I.bits,l=o,c=a,v=Dh;e:for(;;)switch(I.mode){case jk:if(I.wrap===0){I.mode=BF;break}for(;A<16;){if(o===0)break e;o--,s+=i[C++]<>>8&255,I.check=Na(I.check,w,2,0),s=0,A=0,I.mode=yle;break}if(I.head&&(I.head.done=!1),!(I.wrap&1)||(((s&255)<<8)+(s>>8))%31){e.msg="incorrect header check",I.mode=vI;break}if((s&15)!==ble){e.msg="unknown compression method",I.mode=vI;break}if(s>>>=4,A-=4,G=(s&15)+8,I.wbits===0&&(I.wbits=G),G>15||G>I.wbits){e.msg="invalid window size",I.mode=vI;break}I.dmax=1<>8&1),I.flags&512&&I.wrap&4&&(w[0]=s&255,w[1]=s>>>8&255,I.check=Na(I.check,w,2,0)),s=0,A=0,I.mode=Zle;case Zle:for(;A<32;){if(o===0)break e;o--,s+=i[C++]<>>8&255,w[2]=s>>>16&255,w[3]=s>>>24&255,I.check=Na(I.check,w,4,0)),s=0,A=0,I.mode=Gle;case Gle:for(;A<16;){if(o===0)break e;o--,s+=i[C++]<>8),I.flags&512&&I.wrap&4&&(w[0]=s&255,w[1]=s>>>8&255,I.check=Na(I.check,w,2,0)),s=0,A=0,I.mode=vle;case vle:if(I.flags&1024){for(;A<16;){if(o===0)break e;o--,s+=i[C++]<>>8&255,I.check=Na(I.check,w,2,0)),s=0,A=0}else I.head&&(I.head.extra=null);I.mode=Ble;case Ble:if(I.flags&1024&&(u=I.length,u>o&&(u=o),u&&(I.head&&(G=I.head.extra_len-I.length,I.head.extra||(I.head.extra=new Uint8Array(I.head.extra_len)),I.head.extra.set(i.subarray(C,C+u),G)),I.flags&512&&I.wrap&4&&(I.check=Na(I.check,i,u,C)),o-=u,C+=u,I.length-=u),I.length))break e;I.length=0,I.mode=Sle;case Sle:if(I.flags&2048){if(o===0)break e;u=0;do G=i[C+u++],I.head&&G&&I.length<65536&&(I.head.name+=String.fromCharCode(G));while(G&&u>9&1,I.head.done=!0),e.adler=I.check=0,I.mode=_A;break;case Rle:for(;A<32;){if(o===0)break e;o--,s+=i[C++]<>>=A&7,A-=A&7,I.mode=wF;break}for(;A<3;){if(o===0)break e;o--,s+=i[C++]<>>=1,A-=1,s&3){case 0:I.mode=Wle;break;case 1:if(TIg(I),I.mode=g1,g===t1){s>>>=2,A-=2;break e}break;case 2:I.mode=Hle;break;case 3:e.msg="invalid block type",I.mode=vI}s>>>=2,A-=2;break;case Wle:for(s>>>=A&7,A-=A&7;A<32;){if(o===0)break e;o--,s+=i[C++]<>>16^65535)){e.msg="invalid stored block lengths",I.mode=vI;break}if(I.length=s&65535,s=0,A=0,I.mode=SF,g===t1)break e;case SF:I.mode=Xle;case Xle:if(u=I.length,u){if(u>o&&(u=o),u>a&&(u=a),u===0)break e;n.set(i.subarray(C,C+u),r),o-=u,C+=u,a-=u,r+=u,I.length-=u;break}I.mode=_A;break;case Hle:for(;A<14;){if(o===0)break e;o--,s+=i[C++]<>>=5,A-=5,I.ndist=(s&31)+1,s>>>=5,A-=5,I.ncode=(s&15)+4,s>>>=4,A-=4,I.nlen>286||I.ndist>30){e.msg="too many length or distance symbols",I.mode=vI;break}I.have=0,I.mode=Tle;case Tle:for(;I.have>>=3,A-=3}for(;I.have<19;)I.lens[X[I.have++]]=0;if(I.lencode=I.lendyn,I.lenbits=7,V={bits:I.lenbits},v=Tv(ZIg,I.lens,0,19,I.lencode,0,I.work,V),I.lenbits=V.bits,v){e.msg="invalid code lengths set",I.mode=vI;break}I.have=0,I.mode=Nle;case Nle:for(;I.have>>24,b=m>>>16&255,p=m&65535,!(f<=A);){if(o===0)break e;o--,s+=i[C++]<>>=f,A-=f,I.lens[I.have++]=p;else{if(p===16){for(S=f+2;A>>=f,A-=f,I.have===0){e.msg="invalid bit length repeat",I.mode=vI;break}G=I.lens[I.have-1],u=3+(s&3),s>>>=2,A-=2}else if(p===17){for(S=f+3;A>>=f,A-=f,G=0,u=3+(s&7),s>>>=3,A-=3}else{for(S=f+7;A>>=f,A-=f,G=0,u=11+(s&127),s>>>=7,A-=7}if(I.have+u>I.nlen+I.ndist){e.msg="invalid bit length repeat",I.mode=vI;break}for(;u--;)I.lens[I.have++]=G}}if(I.mode===vI)break;if(I.lens[256]===0){e.msg="invalid code -- missing end-of-block",I.mode=vI;break}if(I.lenbits=9,V={bits:I.lenbits},v=Tv(b2e,I.lens,0,I.nlen,I.lencode,0,I.work,V),I.lenbits=V.bits,v){e.msg="invalid literal/lengths set",I.mode=vI;break}if(I.distbits=6,I.distcode=I.distdyn,V={bits:I.distbits},v=Tv(y2e,I.lens,I.nlen,I.ndist,I.distcode,0,I.work,V),I.distbits=V.bits,v){e.msg="invalid distances set",I.mode=vI;break}if(I.mode=g1,g===t1)break e;case g1:I.mode=I1;case I1:if(o>=6&&a>=258){e.next_out=r,e.avail_out=a,e.next_in=C,e.avail_in=o,I.hold=s,I.bits=A,hIg(e,c),r=e.next_out,n=e.output,a=e.avail_out,C=e.next_in,i=e.input,o=e.avail_in,s=I.hold,A=I.bits,I.mode===_A&&(I.back=-1);break}for(I.back=0;m=I.lencode[s&(1<>>24,b=m>>>16&255,p=m&65535,!(f<=A);){if(o===0)break e;o--,s+=i[C++]<>y)],f=m>>>24,b=m>>>16&255,p=m&65535,!(y+f<=A);){if(o===0)break e;o--,s+=i[C++]<>>=y,A-=y,I.back+=y}if(s>>>=f,A-=f,I.back+=f,I.length=p,b===0){I.mode=Dle;break}if(b&32){I.back=-1,I.mode=_A;break}if(b&64){e.msg="invalid literal/length code",I.mode=vI;break}I.extra=b&15,I.mode=kle;case kle:if(I.extra){for(S=I.extra;A>>=I.extra,A-=I.extra,I.back+=I.extra}I.was=I.length,I.mode=Yle;case Yle:for(;m=I.distcode[s&(1<>>24,b=m>>>16&255,p=m&65535,!(f<=A);){if(o===0)break e;o--,s+=i[C++]<>y)],f=m>>>24,b=m>>>16&255,p=m&65535,!(y+f<=A);){if(o===0)break e;o--,s+=i[C++]<>>=y,A-=y,I.back+=y}if(s>>>=f,A-=f,I.back+=f,b&64){e.msg="invalid distance code",I.mode=vI;break}I.offset=p,I.extra=b&15,I.mode=Kle;case Kle:if(I.extra){for(S=I.extra;A>>=I.extra,A-=I.extra,I.back+=I.extra}if(I.offset>I.dmax){e.msg="invalid distance too far back",I.mode=vI;break}I.mode=xle;case xle:if(a===0)break e;if(u=c-a,I.offset>u){if(u=I.offset-u,u>I.whave&&I.sane){e.msg="invalid distance too far back",I.mode=vI;break}u>I.wnext?(u-=I.wnext,d=I.wsize-u):d=I.wnext-u,u>I.length&&(u=I.length),h=I.window}else h=n,d=r-I.offset,u=I.length;u>a&&(u=a),a-=u,I.length-=u;do n[r++]=h[d++];while(--u);I.length===0&&(I.mode=I1);break;case Dle:if(a===0)break e;n[r++]=I.length,a--,I.mode=I1;break;case wF:if(I.wrap){for(;A<32;){if(o===0)break e;o--,s|=i[C++]<{if(Gm(e))return oo;let g=e.state;return g.window&&(g.window=null),e.state=null,Dh},YIg=(e,g)=>{if(Gm(e))return oo;const I=e.state;return I.wrap&2?(I.head=g,g.done=!1,Dh):oo},KIg=(e,g)=>{const I=g.length;let i,n,C;return Gm(e)||(i=e.state,i.wrap!==0&&i.mode!==VH)?oo:i.mode===VH&&(n=1,n=I_(n,g,I,0),n!==i.check)?Z2e:(C=W2e(e,g,I,I),C?(i.mode=v2e,G2e):(i.havedict=1,Dh))};var xIg=w2e,DIg=V2e,FIg=S2e,EIg=HIg,MIg=R2e,zIg=NIg,PIg=kIg,JIg=YIg,OIg=KIg,_Ig="pako inflate (from Nodeca project)",os={inflateReset:xIg,inflateReset2:DIg,inflateResetKeep:FIg,inflateInit:EIg,inflateInit2:MIg,inflate:zIg,inflateEnd:PIg,inflateGetHeader:JIg,inflateSetDictionary:OIg,inflateInfo:_Ig};function LIg(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}var UIg=LIg;const X2e=Object.prototype.toString,{Z_NO_FLUSH:QIg,Z_FINISH:jIg,Z_OK:aS,Z_STREAM_END:WF,Z_NEED_DICT:XF,Z_STREAM_ERROR:$Ig,Z_DATA_ERROR:Ple,Z_MEM_ERROR:qIg}=_$;function Nw(e){this.options=f2e.assign({chunkSize:1024*64,windowBits:15,to:""},e||{});const g=this.options;g.raw&&g.windowBits>=0&&g.windowBits<16&&(g.windowBits=-g.windowBits,g.windowBits===0&&(g.windowBits=-15)),g.windowBits>=0&&g.windowBits<16&&!(e&&e.windowBits)&&(g.windowBits+=32),g.windowBits>15&&g.windowBits<48&&(g.windowBits&15||(g.windowBits|=15)),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new uIg,this.strm.avail_out=0;let I=os.inflateInit2(this.strm,g.windowBits);if(I!==aS)throw new Error(i_[I]);if(this.header=new UIg,os.inflateGetHeader(this.strm,this.header),g.dictionary&&(typeof g.dictionary=="string"?g.dictionary=n_.string2buf(g.dictionary):X2e.call(g.dictionary)==="[object ArrayBuffer]"&&(g.dictionary=new Uint8Array(g.dictionary)),g.raw&&(I=os.inflateSetDictionary(this.strm,g.dictionary),I!==aS)))throw new Error(i_[I])}Nw.prototype.push=function(e,g){const I=this.strm,i=this.options.chunkSize,n=this.options.dictionary;let C,r,o;if(this.ended)return!1;for(g===~~g?r=g:r=g===!0?jIg:QIg,X2e.call(e)==="[object ArrayBuffer]"?I.input=new Uint8Array(e):I.input=e,I.next_in=0,I.avail_in=I.input.length;;){for(I.avail_out===0&&(I.output=new Uint8Array(i),I.next_out=0,I.avail_out=i),C=os.inflate(I,r),C===XF&&n&&(C=os.inflateSetDictionary(I,n),C===aS?C=os.inflate(I,r):C===Ple&&(C=XF));I.avail_in>0&&C===WF&&I.state.wrap>0&&e[I.next_in]!==0;)os.inflateReset(I),C=os.inflate(I,r);switch(C){case $Ig:case Ple:case XF:case qIg:return this.onEnd(C),this.ended=!0,!1}if(o=I.avail_out,I.next_out&&(I.avail_out===0||C===WF))if(this.options.to==="string"){let a=n_.utf8border(I.output,I.next_out),s=I.next_out-a,A=n_.buf2string(I.output,a);I.next_out=s,I.avail_out=i-s,s&&I.output.set(I.output.subarray(a,a+s),0),this.onData(A)}else this.onData(I.output.length===I.next_out?I.output:I.output.subarray(0,I.next_out));if(!(C===aS&&o===0)){if(C===WF)return C=os.inflateEnd(this.strm),this.onEnd(C),this.ended=!0,!0;if(I.avail_in===0)break}}return!0};Nw.prototype.onData=function(e){this.chunks.push(e)};Nw.prototype.onEnd=function(e){e===aS&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=f2e.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};function L$(e,g){const I=new Nw(g);if(I.push(e),I.err)throw I.msg||i_[I.err];return I.result}function eig(e,g){return g=g||{},g.raw=!0,L$(e,g)}var tig=Nw,gig=L$,Iig=eig,iig=L$,nig=_$,Cig={Inflate:tig,inflate:gig,inflateRaw:Iig,ungzip:iig,constants:nig};const{Inflate:Cpg,inflate:rpg,inflateRaw:rig,ungzip:opg}=Cig;var oig=rig;function aig(e){return oig(e.subarray(2))}class Aig extends Error{constructor(g){super(g),this.code="ERR_ABORTED"}}function sig(e){e.sort((n,C)=>Number(n.offset)-Number(C.offset));const g=[];let I,i;for(let n=0;n=I}function dig(e){const g=e?"big":"little",I=new kg().endianess(g).uint32("chromId").uint32("start").uint32("end").uint32("validCnt").floatle("minScore").floatle("maxScore").floatle("sumData").floatle("sumSqData").saveOffset("offset"),i=new kg().endianess(g).uint8("isLeaf").skip(1).uint16("cnt").choice({tag:"isLeaf",choices:{1:new kg().endianess(g).array("blocksToFetch",{length:"cnt",type:new kg().endianess(g).uint32("startChrom").uint32("startBase").uint32("endChrom").uint32("endBase").uint64("blockOffset").uint64("blockSize").saveOffset("offset")}),0:new kg().array("recurOffsets",{length:"cnt",type:new kg().endianess(g).uint32("startChrom").uint32("startBase").uint32("endChrom").uint32("endBase").uint64("blockOffset").saveOffset("offset")})}}),n=new kg().endianess(g).uint32("chromId").int32("start").int32("end").string("rest",{zeroTerminated:!0}).saveOffset("offset");return{bigWigParser:new kg().endianess(g).skip(4).int32("blockStart").skip(4).uint32("itemStep").uint32("itemSpan").uint8("blockType").skip(1).uint16("itemCount").choice({tag:"blockType",choices:{[uig]:new kg().array("items",{length:"itemCount",type:new kg().floatle("score")}),[cig]:new kg().array("items",{length:"itemCount",type:new kg().endianess(g).int32("start").floatle("score")}),[lig]:new kg().array("items",{length:"itemCount",type:new kg().endianess(g).int32("start").int32("end").floatle("score")})}}),bigBedParser:n,summaryParser:I,leafParser:i}}class H2e{constructor(g,I,i,n,C,r){if(this.bbi=g,this.refsByName=I,this.cirTreeOffset=i,this.isBigEndian=n,this.isCompressed=C,this.blockType=r,this.featureCache=new Pgg({cache:new Ret({maxSize:1e3}),fill:async(a,s)=>{const A=Number(a.length),l=Number(a.offset),{buffer:c}=await this.bbi.read(gh.Buffer.alloc(A),0,A,l,{signal:s});return c}}),!(i>=0))throw new Error("invalid cirTreeOffset!");const o=dig(n);this.leafParser=o.leafParser,this.bigBedParser=o.bigBedParser}async readWigData(g,I,i,n,C){try{const{refsByName:r,bbi:o,cirTreeOffset:a,isBigEndian:s}=this,A=r[g];A===void 0&&n.complete();const l={chrId:A,start:I,end:i};this.cirTreePromise||(this.cirTreePromise=o.read(gh.Buffer.alloc(48),0,48,Number(a),C));const{buffer:c}=await this.cirTreePromise,u=s?c.readUInt32BE(4):c.readUInt32LE(4);let d=[],h=0;const m=(y,Z,B)=>{try{const G=y.subarray(Z),v=this.leafParser.parse(G);if(v.blocksToFetch&&(d=d.concat(v.blocksToFetch.filter(f).map(w=>({offset:w.blockOffset,length:w.blockSize})))),v.recurOffsets){const w=v.recurOffsets.filter(f).map(V=>Number(V.blockOffset));w.length>0&&p(w,B+1)}}catch(G){n.error(G)}},f=y=>{const{startChrom:Z,startBase:B,endChrom:G,endBase:v}=y;return(ZA||G===A&&v>=I)},b=async(y,Z,B)=>{try{const G=Z.max()-Z.min(),v=Z.min(),w=await this.featureCache.get(`${G}_${v}`,{length:G,offset:v},C.signal);for(let V=0;V{try{h+=y.length;const B=4+Number(u)*32;let G=new nc(y[0],y[0]+B);for(let v=1;vb(y,v,Z))}catch(B){n.error(B)}};return p([Number(a)+48],1)}catch(r){n.error(r)}}parseSummaryBlock(g,I,i){const n=[];let C=I;const r=new DataView(g.buffer,g.byteOffset,g.length);for(;CHF(o.start,o.end,n.start,n.end)):C}parseBigWigBlock(g,I,i){const n=g.subarray(I),C=new DataView(n.buffer,n.byteOffset,n.length);let r=0;r+=4;const o=C.getInt32(r,!0);r+=8;const a=C.getUint32(r,!0);r+=4;const s=C.getUint32(r,!0);r+=4;const A=C.getUint8(r);r+=2;const l=C.getUint16(r,!0);r+=2;const c=new Array(l);switch(A){case 1:for(let u=0;uHF(u.start,u.end,i.start,i.end)):c}async readFeatures(g,I,i={}){try{const{blockType:n,isCompressed:C}=this,{signal:r,request:o}=i,a=sig(I);i1(r),await Promise.all(a.map(async s=>{i1(r);const{length:A,offset:l}=s,c=await this.featureCache.get(`${A}_${l}`,s,r);s.blocks.forEach(u=>{i1(r);let d=Number(u.offset)-Number(s.offset),h=c;switch(C&&(h=aig(c.subarray(d)),d=0),i1(r),n){case"summary":g.next(this.parseSummaryBlock(h,d,o));break;case"bigwig":g.next(this.parseBigWigBlock(h,d,o));break;case"bigbed":g.next(this.parseBigBedBlock(h,d,Number(u.offset)*256,o));break;default:console.warn(`Don't know what to do with ${n}`)}})})),g.complete()}catch(n){g.error(n)}}}var C_=function(e,g){return C_=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(I,i){I.__proto__=i}||function(I,i){for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(I[n]=i[n])},C_(e,g)};function U$(e,g){if(typeof g!="function"&&g!==null)throw new TypeError("Class extends value "+String(g)+" is not a constructor or null");C_(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}function Jle(e){var g=typeof Symbol=="function"&&Symbol.iterator,I=g&&e[g],i=0;if(I)return I.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&i>=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}};throw new TypeError(g?"Object is not iterable.":"Symbol.iterator is not defined.")}function r_(e,g){var I=typeof Symbol=="function"&&e[Symbol.iterator];if(!I)return e;var i=I.call(e),n,C=[],r;try{for(;(g===void 0||g-- >0)&&!(n=i.next()).done;)C.push(n.value)}catch(o){r={error:o}}finally{try{n&&!n.done&&(I=i.return)&&I.call(i)}finally{if(r)throw r.error}}return C}function o_(e,g,I){if(I||arguments.length===2)for(var i=0,n=g.length,C;i=2,!1,!0))}var Yig=function(e,g){return e.push(g),e};function Kig(){return Y2e(function(e,g){kig(Yig,[])(e).subscribe(g)})}const Qle=-2003829722,kF=-2021002517;function xig(e){return new TextDecoder().decode(e)}function jle(e){const g=e?"big":"little",I=new kg().endianess(g).int32("magic").uint16("version").uint16("numZoomLevels").uint64("chromTreeOffset").uint64("unzoomedDataOffset").uint64("unzoomedIndexOffset").uint16("fieldCount").uint16("definedFieldCount").uint64("asOffset").uint64("totalSummaryOffset").uint32("uncompressBufSize").uint64("extHeaderOffset").array("zoomLevels",{length:"numZoomLevels",type:new kg().endianess(g).uint32("reductionLevel").uint32("reserved").uint64("dataOffset").uint64("indexOffset")}),i=new kg().endianess(g).uint64("basesCovered").doublele("scoreMin").doublele("scoreMax").doublele("scoreSum").doublele("scoreSumSquares"),n=new kg().endianess(g).uint32("magic").uint32("blockSize").uint32("keySize").uint32("valSize").uint64("itemCount"),C=new kg().endianess(g).uint8("isLeafNode").skip(1).uint16("cnt").saveOffset("offset");return{chromTreeParser:n,totalSummaryParser:i,headerParser:I,isLeafNode:C}}class Dig{getHeader(g={}){const I="aborted"in g?{signal:g}:g;return this.headerP||(this.headerP=this._getHeader(I).catch(i=>{throw this.headerP=void 0,i})),this.headerP}constructor(g={}){const{filehandle:I,renameRefSeqs:i=r=>r,path:n,url:C}=g;if(this.renameRefSeqs=i,I)this.bbi=I;else if(C)this.bbi=new cbe(C);else if(n)this.bbi=new mme(n);else throw new Error("no file given")}async _getHeader(g){const I=await this._getMainHeader(g),i=await this._readChromTree(I,g);return{...I,...i}}async _getMainHeader(g,I=2e3){const{buffer:i}=await this.bbi.read(gh.Buffer.alloc(I),0,I,0,g),n=this._isBigEndian(i),C=jle(n),r=C.headerParser.parse(i),{magic:o,asOffset:a,totalSummaryOffset:s}=r;if(r.fileType=o===kF?"bigbed":"bigwig",a>I||s>I)return this._getMainHeader(g,I*2);if(a){const A=Number(r.asOffset);r.autoSql=xig(i.subarray(A,i.indexOf(0,A)))}if(r.totalSummaryOffset>I)return this._getMainHeader(g,I*2);if(r.totalSummaryOffset){const A=i.subarray(Number(r.totalSummaryOffset)),l=C.totalSummaryParser.parse(A);r.totalSummary={...l,basesCovered:Number(l.basesCovered)}}return{...r,isBigEndian:n}}_isBigEndian(g){let I=g.readInt32LE(0);if(I===Qle||I===kF)return!1;if(I=g.readInt32BE(0),I===Qle||I===kF)return!0;throw new Error("not a BigWig/BigBed file")}async _readChromTree(g,I){const i=g.isBigEndian,n=i?"big":"little",C=[],r={};let o=Number(g.unzoomedDataOffset);const a=Number(g.chromTreeOffset);for(;o%4!==0;)o+=1;const s=o-a,{buffer:A}=await this.bbi.read(gh.Buffer.alloc(s),0,s,Number(a),I),l=jle(i),{keySize:c}=l.chromTreeParser.parse(A),u=new kg().endianess(n).string("key",{stripNull:!0,length:c}).uint32("refId").uint32("refSize").saveOffset("offset"),d=new kg().endianess(n).skip(c).uint64("childOffset").saveOffset("offset"),h=32,m=async f=>{let b=f;if(b>=A.length)throw new Error("reading beyond end of buffer");const p=l.isLeafNode.parse(A.subarray(b)),{isLeafNode:y,cnt:Z}=p;if(b+=p.offset,y)for(let B=0;B0,r)}async getFeatureStream(g,I,i,n={scale:1}){await this.getHeader(n);const C=this.renameRefSeqs(g);let r;if(n.basesPerSpan?r=await this.getView(1/n.basesPerSpan,n):n.scale?r=await this.getView(n.scale,n):r=await this.getView(1,n),!r)throw new Error("unable to get block view for data");return new Sig(o=>{r.readWigData(C,I,i,o,n)})}async getFeatures(g,I,i,n={scale:1}){const C=await this.getFeatureStream(g,I,i,n);return(await Tig(C.pipe(Kig()))).flat()}}class Fig extends Dig{async getView(g,I){const{zoomLevels:i,refsByName:n,fileSize:C,isBigEndian:r,uncompressBufSize:o}=await this.getHeader(I),a=1/g;let s=i.length;C||(s-=1);for(let A=s;A>=0;A-=1){const l=i[A];if(l&&l.reductionLevel<=2*a){const c=Number(l.indexOffset);return new H2e(this.bbi,n,c,r,o>0,"summary")}}return this.getUnzoomedView(I)}}function K2e(e,g){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');const I=class{constructor(){rt(this,"dataConfig"),rt(this,"bwFileHeader"),rt(this,"bwFile"),rt(this,"TILE_SIZE"),rt(this,"errorTxt"),rt(this,"dataPromises"),rt(this,"chromSizes"),rt(this,"assembly"),rt(this,"tilesetInfoLoading"),this.dataConfig=g,this.assembly=this.dataConfig.assembly,this.bwFileHeader=null,this.bwFile=null,this.TILE_SIZE=1024,this.errorTxt="",this.dataPromises=[];const n=bI(this.assembly).size,C=[],r={};let o=0;Object.keys(bI(this.assembly).size).forEach((a,s)=>{const A={id:s,chr:a,pos:o};C.push(A),r[a]=A,o+=bI(this.assembly).size[a]}),this.chromSizes={chrToAbs:(a,s)=>this.chromSizes.chrPositions[a].pos+s,cumPositions:C,chrPositions:r,totalLength:o,chromLengths:n},this.dataPromises.push(this.loadBBI(g))}async loadBBI(n){return n.url?(this.bwFile=new Fig({filehandle:new $be(n.url,{overrides:n.urlFetchOptions})}),this.bwFile.getHeader().then(C=>{this.bwFileHeader=C})):(console.error('Please enter a "url" field to the data config'),null)}tilesetInfo(n){return this.tilesetInfoLoading=!0,Promise.all(this.dataPromises).then(()=>{this.tilesetInfoLoading=!1;const C=this.chromSizes.totalLength,r={tile_size:this.TILE_SIZE,max_zoom:Math.ceil(Math.log(C/this.TILE_SIZE)/Math.log(2)),max_width:2**Math.ceil(Math.log(C)/Math.log(2)),min_pos:[0],max_pos:[C]};return n&&n(r),r}).catch(C=>(this.tilesetInfoLoading=!1,console.error(C),n&&n({error:`Error parsing bigwig: ${C}`}),null))}fetchTilesDebounced(n,C){const r={},o=[],a=[];for(const s of C){const A=s.split("."),l=parseInt(A[0],10),c=parseInt(A[1],10);if(Number.isNaN(c)||Number.isNaN(l)){console.warn("Invalid tile zoom or position:",l,c);continue}o.push(s),a.push(this.tile(l,c))}return Promise.all(a).then(s=>{for(let A=0;A{const p=b.chr,y=b.pos,Z=b.pos+m[p];let B,G;if(y<=l&&lZ)B=l-y,G=Z-y,a.push(this.bwFile.getFeatures(p,B,G,{scale:1/u}).then(v=>(v.forEach(w=>{w.startAbs=e.utils.chrToAbs(p,w.start,this.chromSizes),w.endAbs=e.utils.chrToAbs(p,w.end,this.chromSizes)}),v))),l=Z;else{if(B=Math.floor(l-y),G=Math.ceil(c-y),!this.bwFile)return;a.push(this.bwFile.getFeatures(p,B,G,{scale:1/u}).then(v=>(v.forEach(w=>{w.startAbs=e.utils.chrToAbs(p,w.start,this.chromSizes),w.endAbs=e.utils.chrToAbs(p,w.end,this.chromSizes)}),v)));return}}),Promise.all(a).then(b=>{const p=b.flat(),y=[];for(let B=0;B{if(Bc)return;const v=p.filter(w=>B>=w.startAbs&&Bw.score);y[G]=v.length>0?v[0]:null});const Z=new e.utils.DenseDataExtrema1D(y);return s.min_value=Math.min(...y),s.max_value=Math.max(...y),s.dense=y,s.denseDataExtrema=Z,s.minNonZero=Z.minNonZeroInTile,s.maxNonZero=Z.maxNonZeroInTile,s})}determineScale(n,C){const r=[1],o=C-n;if(!this.bwFileHeader)throw Error("no bigwig header");this.bwFileHeader.zoomLevels.forEach(s=>{r.push(s.reductionLevel)});let a;return r.forEach(s=>{if(a)return;o/s<=this.TILE_SIZE*20&&(a=s)}),a||r.slice(-1)[0]}};return new I}K2e.config={type:"bigwig"};function x2e(e,g){const{field:I,not:i}=e;let n=Array.from(g);if(G4e(e)){const{oneOf:C}=e;n=n.filter(r=>i?C.indexOf(r[I])===-1:C.indexOf(r[I])!==-1)}else if(v4e(e)){const{inRange:C}=e;n=n.filter(r=>{const o=+r[I];return i?!(C[0]<=o&&o<=C[1]):C[0]<=o&&o<=C[1]})}else if(B4e(e)){const{include:C}=e;n=n.filter(r=>i?`${r[I]}`.includes(C):!`${r[I]}`.includes(C))}return n}function Eig(e,g){const{fields:I,separator:i,newField:n}=e;let C=Array.from(g);return C=C.map(r=>{const o=I.map(a=>r[a]);return r[n]=o.join(i),r}),C}function Mig(e,g){const{field:I,replace:i,newField:n}=e;let C=Array.from(g);return C=C.map(r=>(r[n]=r[I],i.forEach(o=>{const{from:a,to:s}=o;r[n]=r[n].toString().replaceAll(a,s)}),r)),C}function zig(e,g){const{field:I,base:i,newField:n}=e;let C=Array.from(g);return C=C.map(r=>(+r[I]&&(i==="e"?r[n??I]=Math.log(+r[I]):r[n??I]=Math.log(+r[I])/Math.log(i??10)),r)),C}function Pig(e,g){const{startField:I,endField:i,newField:n}=e,C=Array.from(g);return C.forEach(r=>{const o=r[I],a=r[i];!o||!a||(r[n]=Math.abs(+a-+o))}),C}function Jig(e,g){const{firstBp:I,secondBp:i,newField:n}=e,C=Array.from(g),[r,o,a,s,A]=["DUP","TRA","DEL","t2tINV","h2hINV"];return C.forEach(l=>{const c=l[I.chrField],u=l[i.chrField];if(c!==u){l[n]=o;return}let d=l[I.posField],h=l[i.posField],m=l[I.strandField],f=l[i.strandField];if(d>h){const b=d,p=m;d=h,m=f,h=b,f=p}switch(`${m}${f}`){case"+-":l[n]=a;break;case"--":l[n]=s;break;case"++":l[n]=A;break;case"-+":l[n]=r;break;default:l[n]="unknown"}}),C}function Oig(e,g,I){const{startField:i,endField:n,newField:C,groupField:r}=e,o={},a=1;return g.forEach(A=>{const l=I(A[i]),c=I(A[n]),u=r?A[r]:"__NO_GROUP__",d=Math.floor(l);for(let h=d;h{const[l,c]=A;return Object.entries(c).map(u=>{const[d,h]=u;return{[i]:I.invert(+d),[n]:I.invert(+d+a),[C??"coverage"]:h,[r??"group"]:l}})})}function _ig(e,g,I){const{boundingBox:i,method:n,newField:C}=e,{startField:r,endField:o,groupField:a}=i;let s=0;i.padding&&I&&!i.isPaddingBP?s=Math.abs(I.invert(i.padding)-I.invert(0)):i.padding&&i.isPaddingBP&&(s=i.padding);const A=Array.from(g);if(A&&A.length>0&&(!Object.keys(A[0]).find(l=>l===r)||!Object.keys(A[0]).find(l=>l===o)))return A;if(n==="pile"){const{maxRows:l}=e,c={};A.sort((d,h)=>d[r]-h[r]).forEach(d=>{const h=+d[r]-s,m=+d[o]+s,f=a?d[a]:"__NO_GROUP__";c[f]||(c[f]=[]);let b=c[f].findIndex(p=>mc[r]-u[r]).forEach(c=>{let u=c[r]-s,d=c[o]+s,h=l.filter(m=>m.start===u&&d===m.end||m.start0){let m=0;do h=l.filter(f=>f.start===u&&d===f.end||f.start0&&(m%2===0?(u+=s*m,d+=s*m):(u-=s*m,d-=s*m)),m++;while(h.length>0&&m<1e3)}c[`${C}Start`]=`${u+s}`,c[`${C}Etart`]=`${d-s}`,l.push({start:u,end:d})})}return A}function Lig(e,g,I="hg38"){const{separator:i,fields:n,flag:C}=e;let r=Array.from(g);return r=r.map(o=>{const a=[];return n.forEach(s=>{const{field:A,type:l,newField:c,chrField:u}=s;o[A].toString().split(i).forEach((h,m)=>{let f=h;l==="genomic"&&(f=bI(I).interval[o[u]][0]+ +h),a[m]?a[m][c]=f:a[m]=Object.assign(JSON.parse(JSON.stringify(o)),{[c]:f,[C.field]:C.value})})}),[o,...a]}).reduce((o,a)=>o.concat(a),[]),r}function Uig(e,g){const{field:I,genomicField:i,baseGenomicField:n,genomicLengthField:C}=e;let r=Array.from(g);return r=r.map(o=>{let a=JSON.parse(o[I]);return a=a.map(s=>{var A,l;return s[i]&&o[n]&&(s[`${i}_start`]=+s[i]+ +o[n],s[`${i}_end`]=+s[i]+ +o[n]+ +s[C]),Object.assign(JSON.parse(JSON.stringify(o)),{...s,[`${i}_start`]:s[`${i}_start`],[`${i}_end`]:s[`${i}_end`],type:(l=(A=s.type)!=null?A:s.variant)!=null?l:null,isParsedRow:"yes"})}),[o,...a]}).reduce((o,a)=>o.concat(a),[]),r}function Qig(e,g){if(V4e(e).length===0)return g;const I=s5(e,"nominal");if(I.length!==1)return console.warn("Currently, we only support aggregating datasets with single nominal field."),g;const i=e[I[0]];if(!ut(i))return g;const n=i.field;if(!n)return g;const C=[...s5(e,"quantitative"),...s5(e,"genomic")],r=[],o=Array.from(new Set(g.map(s=>s[n])));let a=!1;return o.forEach(s=>{const A={};A[n]=s,C.forEach(l=>{const c=e[l];if(!ut(c)){a=!0;return}const{field:u}=c;if(!u||!("aggregate"in c)){a=!0;return}A[u]=c.aggregate==="max"?Math.max(...g.filter(d=>d[n]===s).map(d=>+d[u])):Math.min(...g.filter(d=>d[n]===s).map(d=>+d[u]))}),r.push(A)}),a?g:r}class jig{constructor(g){fg(this,_O),fg(this,x$),fg(this,vH),fg(this,UO),fg(this,QO),fg(this,jO),rt(this,"dataConfig"),rt(this,"tilesetInfoLoading"),fg(this,hG,void 0),fg(this,CS,void 0),fg(this,rS,void 0),fg(this,Md,void 0),fg(this,ZH,void 0),fg(this,GH,void 0),this.dataConfig=g,this.tilesetInfoLoading=!1,WC(this,Md,this.dataConfig.assembly),WC(this,ZH,this.dataConfig.filter),g.url||console.error("Please provide the `url` of the data");const{urlFetchOptions:I,url:i}=g;WC(this,GH,new $be(i,{overrides:I})),WC(this,CS,SI(this,jO,i2e).call(this)),WC(this,hG,SI(this,_O,e2e).call(this))}tilesetInfo(g){if(Dt(this,hG))return this.tilesetInfoLoading=!0,Dt(this,hG).then(()=>SI(this,UO,g2e).call(this,g)).catch(I=>{this.tilesetInfoLoading=!1,console.error("[Gosling Data Fetcher] Error parsing data:",I)})}fetchTilesDebounced(g,I){const i={},n=[],C=[];for(const r of I){const o=r.split("."),a=parseInt(o[0],10),s=parseInt(o[1],10),A=parseInt(o[2],10);if(Number.isNaN(s)||Number.isNaN(a)){console.warn("[Gosling Data Fetcher] Invalid tile zoom or position:",a,s,A);continue}n.push(r),C.push(SI(this,QO,I2e).call(this,a,s,A))}Promise.all(C).then(r=>{r.forEach((o,a)=>{if(o){const s=n[a];i[s]=o,i[s].tilePositionId=s}}),g(i)})}}hG=new WeakMap;CS=new WeakMap;rS=new WeakMap;Md=new WeakMap;ZH=new WeakMap;GH=new WeakMap;_O=new WeakSet;e2e=async function(){var e,g;const{chromosomeField:I,genomicFields:i,headerNames:n,longToWideId:C,genomicFieldsToConvert:r}=this.dataConfig,o=(e=this.dataConfig.separator)!=null?e:",";try{const s=(await Dt(this,GH).readFile()).toString(),A=n?`${n.join(o)} -${s}`:s,l=Tet(o).parse(A,c=>SI(this,x$,t2e).call(this,c,r,I,i));if(C&&((g=l[0])!=null&&g[C])){const c=Object.keys(l[0]),u={};l.forEach(d=>{u[d[C]]?c.forEach(h=>{u[d[C]][`${h}_2`]=d[h]}):u[d[C]]=JSON.parse(JSON.stringify(d))}),WC(this,rS,Object.keys(u).map(d=>u[d]))}else WC(this,rS,l)}catch(a){console.error("[Gosling Data Fetcher] Error fetching data",a)}};x$=new WeakSet;t2e=function(e,g,I,i){try{return g?g.forEach(n=>{const C=n.genomicFields,r=e[n.chromosomeField];C.forEach(o=>{const a=e[o];e[o]=String(SI(this,vH,LO).call(this,r,a))})}):I&&i&&i.forEach(n=>{const C=e[n],r=e[I];e[n]=String(SI(this,vH,LO).call(this,r,C))}),e}catch{return}};vH=new WeakSet;LO=function(e,g){if(Dt(this,Md)!=="unknown"){const I=m3(e,Dt(this,Md),this.dataConfig.chromosomePrefix);return bI(Dt(this,Md)).interval[I][0]+ +g}else return g};UO=new WeakSet;g2e=function(e){this.tilesetInfoLoading=!1;const g=1024,I=Dt(this,CS).totalLength,i={tile_size:g,max_zoom:Math.ceil(Math.log(I/g)/Math.log(2)),max_width:I,min_pos:[0,0],max_pos:[I,I]};return e&&e(i),i};QO=new WeakSet;I2e=async function(e,g,I){var i,n;const C=await this.tilesetInfo();if(!C)return;const r=+C.max_width/2**+e,o=C.min_pos[0]+g*r,a=C.min_pos[0]+(g+1)*r;let s=jbe(Dt(this,rS),[o,a],this.dataConfig);(i=Dt(this,ZH))==null||i.forEach(l=>{s=x2e(l,s)});const A=(n=this.dataConfig.sampleLength)!=null?n:1e3;return{tabularData:s.length>A?e7(s,A):s,server:null,tilePos:[g,I],zoomLevel:e}};jO=new WeakSet;i2e=function(){const e=bI(Dt(this,Md)).size,g=[],I={};let i=0;return Object.keys(e).forEach((n,C)=>{const r={id:C,chr:n,pos:i};g.push(r),I[n]=r,i+=e[n]}),{chrToAbs:(n,C)=>Dt(this,CS).chrPositions[n].pos+C,cumPositions:g,chrPositions:I,totalLength:i,chromLengths:e}};function D2e(e,g,I){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');return new jig(g)}D2e.config={type:"csv"};function F2e(e,...g){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');class I{constructor(n){rt(this,"dataConfig"),rt(this,"tilesetInfoLoading"),rt(this,"chromSizes"),rt(this,"values"),rt(this,"assembly");const[C]=n;if(this.dataConfig=C,this.tilesetInfoLoading=!1,this.assembly=this.dataConfig.assembly,!C.values){console.error("Please provide `values` of the JSON data");return}const r=bI(this.assembly).size,o=[],a={};let s=0;Object.keys(bI(this.assembly).size).forEach((u,d)=>{const h={id:d,chr:u,pos:s};o.push(h),a[u]=h,s+=bI(this.assembly).size[u]}),this.chromSizes={chrToAbs:(u,d)=>this.chromSizes.chrPositions[u].pos+d,cumPositions:o,chrPositions:a,totalLength:s,chromLengths:r};const{chromosomeField:A,genomicFields:l,genomicFieldsToConvert:c}=this.dataConfig;this.values=C.values.map(u=>{try{return c?c.forEach(d=>{const h=d.genomicFields,m=m3(u[d.chromosomeField],this.assembly);h.forEach(f=>{const b=u[f];u[f]=String(this.chromSizes.chrToAbs(m,b))})}):A&&l&&l.forEach(d=>{const h=u[d],m=m3(u[A],this.assembly);u[d]=String(this.chromSizes.chrToAbs(m,h))}),u}catch{return}})}tilesetInfo(n){this.tilesetInfoLoading=!1;const C=1024,r=this.chromSizes.totalLength,o={tile_size:C,max_zoom:Math.ceil(Math.log(r/C)/Math.log(2)),max_width:r,min_pos:[0,0],max_pos:[r,r]};return n&&n(o),o}fetchTilesDebounced(n,C){const r={},o=[],a=[];for(const s of C){const A=s.split("."),l=parseInt(A[0],10),c=parseInt(A[1],10),u=parseInt(A[2],10);if(Number.isNaN(c)||Number.isNaN(l)){console.warn("[Gosling Data Fetcher] Invalid tile zoom or position:",l,c,u);continue}o.push(s),a.push(this.tile(l,c,u))}return Promise.all(a).then(s=>{s.forEach((A,l)=>{const c=o[l];r[c]=A,r[c].tilePositionId=c}),n(r)}),r}tile(n,C,r){var o;const a=this.tilesetInfo(),s=+a.max_width/2**+n,A=a.min_pos[0]+C*s,l=a.min_pos[0]+(C+1)*s;let c=jbe(this.values,[A,l],this.dataConfig);const u=(o=this.dataConfig.sampleLength)!=null?o:1e3;return u{const a=Object.entries(bI(C).size);return await o.init(this.uid,{url:i,indexUrl:n},a,r),o})}async tilesetInfo(g){(await this.worker).tilesetInfo(this.uid).then(g)}fetchTilesDebounced(g,I){this.track.drawLoadingCue(),I.forEach(i=>this.toFetch.add(i)),this.fetchTimeout&&clearTimeout(this.fetchTimeout),this.fetchTimeout=setTimeout(()=>{this.sendFetch(g,[...this.toFetch]),this.toFetch.clear()},qig)}async sendFetch(g,I){(await this.worker).fetchTilesDebounced(this.uid,I).then(g)}async getTabularData(g){const I=await(await this.worker).getTabularData(this.uid,g);return JSON.parse(new TextDecoder().decode(I))}}rt(M2e,"config",{type:"gff"});const z2e="KCgpID0+IHsKICB2YXIgX19jcmVhdGUgPSBPYmplY3QuY3JlYXRlOwogIHZhciBfX2RlZlByb3AgPSBPYmplY3QuZGVmaW5lUHJvcGVydHk7CiAgdmFyIF9fZ2V0T3duUHJvcERlc2MgPSBPYmplY3QuZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9yOwogIHZhciBfX2dldE93blByb3BOYW1lcyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eU5hbWVzOwogIHZhciBfX2dldFByb3RvT2YgPSBPYmplY3QuZ2V0UHJvdG90eXBlT2Y7CiAgdmFyIF9faGFzT3duUHJvcCA9IE9iamVjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHk7CiAgdmFyIF9fbWFya0FzTW9kdWxlID0gKHRhcmdldCkgPT4gX19kZWZQcm9wKHRhcmdldCwgIl9fZXNNb2R1bGUiLCB7IHZhbHVlOiB0cnVlIH0pOwogIHZhciBfX2VzbSA9IChmbiwgcmVzKSA9PiBmdW5jdGlvbiBfX2luaXQoKSB7CiAgICByZXR1cm4gZm4gJiYgKHJlcyA9ICgwLCBmbltPYmplY3Qua2V5cyhmbilbMF1dKShmbiA9IDApKSwgcmVzOwogIH07CiAgdmFy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TUpOwogICAgICAgICAgb3V0cHV0LnB1c2godHJpcGxldFRvQmFzZTY0KHRtcCkpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gb3V0cHV0LmpvaW4oIiIpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZyb21CeXRlQXJyYXkodWludDgpIHsKICAgICAgICB2YXIgdG1wOwogICAgICAgIHZhciBsZW4yID0gdWludDgubGVuZ3RoOwogICAgICAgIHZhciBleHRyYUJ5dGVzID0gbGVuMiAlIDM7CiAgICAgICAgdmFyIHBhcnRzID0gW107CiAgICAgICAgdmFyIG1heENodW5rTGVuZ3RoID0gMTYzODM7CiAgICAgICAgZm9yICh2YXIgaTIgPSAwLCBsZW4yMiA9IGxlbjIgLSBleHRyYUJ5dGVzOyBpMiA8IGxlbjIyOyBpMiArPSBtYXhDaHVua0xlbmd0aCkgewogICAgICAgICAgcGFydHMucHVzaChlbmNvZGVDaHVuayh1aW50OCwgaTIsIGkyICsgbWF4Q2h1bmtMZW5ndGggPiBsZW4yMiA/IGxlbjIyIDogaTIgKyBtYXhDaHVua0xlbmd0aCkpOwogICAgICAgIH0KICAgICAgICBpZiAoZXh0cmFCeXRlcyA9PT0gMSkgewogICAgICAgICAgdG1wID0gdWludDhbbGVuMiAtIDFdOwogICAgICAgICAgcGFydHMucHVzaChsb29rdXBbdG1wID4+IDJdICsgbG9va3VwW3RtcCA8PCA0ICYgNjNdICsgIj09Iik7CiAgICAgICAgfSBlbHNlIGlmIChleHRyYUJ5dGVzID09PSAyKSB7CiAgICAgICAgICB0bXAgPSAodWludDhbbGVuMiAtIDJdIDw8IDgpICsgdWludDhbbGVuMiAtIDFdOwogICAgICAgICAgcGFydHMucHVzaChsb29rdXBbdG1wID4+IDEwXSArIGxvb2t1cFt0bXAgPj4gNCAmIDYzXSArIGxvb2t1cFt0bXAgPDwgMiAmIDYzXSArICI9Iik7CiAgICAgICAgfQogICAgICAgIHJldHVybiBwYXJ0cy5qb2luKCIiKTsKICAgICAgfQogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vaWVlZTc1NEAxLjIuMS9ub2RlX21vZHVsZXMvaWVlZTc1NC9pbmRleC5qcwogIHZhciByZXF1aXJlX2llZWU3NTQgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vaWVlZTc1NEAxLjIuMS9ub2RlX21vZHVsZXMvaWVlZTc1NC9pbmRleC5qcyIoZXhwb3J0czIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICBleHBvcnRzMi5yZWFkID0gZnVuY3Rpb24oYnVmZmVyLCBvZmZzZXQsIGlzTEUsIG1MZW4sIG5CeXRlcykgewogICAgICAgIHZhciBlLCBtOwogICAgICAgIHZhciBlTGVuID0gbkJ5dGVzICogOCAtIG1MZW4gLSAxOwogICAgICAgIHZhciBlTWF4ID0gKDEgPDwgZUxlbikgLSAxOwogICAgICAgIHZhciBlQmlhcyA9IGVNYXggPj4gMTsKICAgICAgICB2YXIgbkJpdHMgPSAtNzsKICAgICAgICB2YXIgaSA9IGlzTEUgPyBuQnl0ZXMgLSAxIDogMDsKICAgICAgICB2YXIgZCA9IGlzTEUgPyAtMSA6IDE7CiAgICAgICAgdmFyIHMgPSBidWZmZXJbb2Zmc2V0ICsgaV07CiAgICAgICAgaSArPSBkOwogICAgICAgIGUgPSBzICYgKDEgPDwgLW5CaXRzKSAtIDE7CiAgICAgICAgcyA+Pj0gLW5CaXRzOwogICAgICAgIG5CaXRzICs9IGVMZW47CiAgICAgICAgZm9yICg7IG5CaXRzID4gMDsgZSA9IGUgKiAyNTYgKyBidWZmZXJbb2Zmc2V0ICsgaV0sIGkgKz0gZCwgbkJpdHMgLT0gOCkgewogICAgICAgIH0KICAgICAgICBtID0gZSAmICgxIDw8IC1uQml0cykgLSAxOwogICAgICAgIGUgPj49IC1uQml0czsKICAgICAgICBuQml0cyArPSBtTGVuOwogICAgICAgIGZvciAoOyBuQml0cyA+IDA7IG0gPSBt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ml0eSkgewogICAgICAgICAgbSA9IGlzTmFOKHZhbHVlKSA/IDEgOiAwOwogICAgICAgICAgZSA9IGVNYXg7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGUgPSBNYXRoLmZsb29yKE1hdGgubG9nKHZhbHVlKSAvIE1hdGguTE4yKTsKICAgICAgICAgIGlmICh2YWx1ZSAqIChjID0gTWF0aC5wb3coMiwgLWUpKSA8IDEpIHsKICAgICAgICAgICAgZS0tOwogICAgICAgICAgICBjICo9IDI7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoZSArIGVCaWFzID49IDEpIHsKICAgICAgICAgICAgdmFsdWUgKz0gcnQgLyBjOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdmFsdWUgKz0gcnQgKiBNYXRoLnBvdygyLCAxIC0gZUJpYXMpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHZhbHVlICogYyA+PSAyKSB7CiAgICAgICAgICAgIGUrKzsKICAgICAgICAgICAgYyAvPSAyOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGUgKyBlQmlhcyA+PSBlTWF4KSB7CiAgICAgICAgICAgIG0gPSAwOwogICAgICAgICAgICBlID0gZU1heDsKICAgICAgICAgIH0gZWxzZSBpZiAoZSArIGVCaWFzID49IDEpIHsKICAgICAgICAgICAgbSA9ICh2YWx1ZSAqIGMgLSAxKSAqIE1hdGgucG93KDIsIG1MZW4pOwogICAgICAgICAgICBlID0gZSArIGVCaWFzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbSA9IHZhbHVlICogTWF0aC5wb3coMiwgZUJpYXMgLSAxKSAqIE1hdGgucG93KDIsIG1MZW4pOwogICAgICAgICAgICBlID0gMDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZm9yICg7IG1MZW4gPj0gODsgYnVmZmVyW29mZnNldCArIGldID0gbSAmIDI1NSwgaSArPSBkLCBtIC89IDI1NiwgbUxlbiAtPSA4KSB7CiAgICAgICAgfQogIC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YWJsZTogdHJ1ZSwKICAgICAgICBnZXQ6IGZ1bmN0aW9uKCkgewogICAgICAgICAgaWYgKCFCdWZmZXIxMC5pc0J1ZmZlcih0aGlzKSkKICAgICAgICAgICAgcmV0dXJuIHZvaWQgMDsKICAgICAgICAgIHJldHVybiB0aGlzLmJ1ZmZlcjsKICAgICAgICB9CiAgICAgIH0pOwogICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoQnVmZmVyMTAucHJvdG90eXBlLCAib2Zmc2V0IiwgewogICAgICAgIGVudW1lcmFibGU6IHRydWUsCiAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHsKICAgICAgICAgIGlmICghQnVmZmVyMTAuaXNCdWZmZXIodGhpcykpCiAgICAgICAgICAgIHJldHVybiB2b2lkIDA7CiAgICAgICAgICByZXR1cm4gdGhpcy5ieXRlT2Zmc2V0OwogICAgICAgIH0KICAgICAgfSk7CiAgICAgIGZ1bmN0aW9uIGNyZWF0ZUJ1ZmZlcihsZW5ndGgpIHsKICAgICAgICBpZiAobGVuZ3RoID4gS19NQVhfTEVOR1RIKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcignVGhlIHZhbHVlICInICsgbGVuZ3RoICsgJyIgaXMgaW52YWxpZCBmb3Igb3B0aW9uICJzaXplIicpOwogICAgICAgIH0KICAgICAgICBjb25zdCBidWYgPSBuZXcgVWludDhBcnJheShsZW5ndGgpOwogICAgICAgIE9iamVjdC5zZXRQcm90b3R5cGVPZihidWYsIEJ1ZmZlcjEwLnByb3RvdHlwZSk7CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfQogICAgICBmdW5jdGlvbiBCdWZmZXIxMChhcmcsIGVuY29kaW5nT3JPZmZzZXQsIGxlbmd0aCkgewogICAgICAgIGlmICh0eXBlb2YgYXJnID09PSAibnVtYmVyIikgewogICAgICAgICAgaWYgKHR5cGVvZiBlbmNvZGluZ09yT2Zmc2V0ID09PSAic3RyaW5nIikgewogICAgICAgICAgIC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sKICAgICAgICAgIGVuY29kaW5nID0gInV0ZjgiOwogICAgICAgIH0KICAgICAgICBpZiAoIUJ1ZmZlcjEwLmlzRW5jb2RpbmcoZW5jb2RpbmcpKSB7CiAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgIH0KICAgICAgICBjb25zdCBsZW5ndGggPSBieXRlTGVuZ3RoKHN0cmluZywgZW5jb2RpbmcpIHwgMDsKICAgICAgICBsZXQgYnVmID0gY3JlYXRlQnVmZmVyKGxlbmd0aCk7CiAgICAgICAgY29uc3QgYWN0dWFsID0gYnVmLndyaXRlKHN0cmluZywgZW5jb2RpbmcpOwogICAgICAgIGlmIChhY3R1YWwgIT09IGxlbmd0aCkgewogICAgICAgICAgYnVmID0gYnVmLnNsaWNlKDAsIGFjdHVhbCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZnJvbUFycmF5TGlrZShhcnJheSkgewogICAgICAgIGNvbnN0IGxlbmd0aCA9IGFycmF5Lmxlbmd0aCA8IDAgPyAwIDogY2hlY2tlZChhcnJheS5sZW5ndGgpIHwgMDsKICAgICAgICBjb25zdCBidWYgPSBjcmVhdGVCdWZmZXIobGVuZ3RoKTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbmd0aDsgaSArPSAxKSB7CiAgICAgICAgICBidWZbaV0gPSBhcnJheVtpXSAmIDI1NTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfQogICAgICBmdW5jdGlvbiBmcm9tQXJyYXlWaWV3KGFycmF5VmlldykgewogICAgICAgIGlmIChpc0luc3RhbmNlKGFycmF5VmlldywgVWludDhBcnJheSkpIHsKICAgICAgICAgIGNvbnN0IGNvcHkgPSBuZXcgVWludDhBcnJheShhcnJheVZpZXcpOwogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUJ1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CiAgICAgIGZ1bmN0aW9uIGZyb21PYmplY3Qob2JqKSB7CiAgICAgICAgaWYgKEJ1ZmZlcjEwLmlzQnVmZmVyKG9iaikpIHsKICAgICAgICAgIGNvbnN0IGxlbiA9IGNoZWNrZWQob2JqLmxlbmd0aCkgfCAwOwogICAgICAgICAgY29uc3QgYnVmID0gY3JlYXRlQnVmZmVyKGxlbik7CiAgICAgICAgICBpZiAoYnVmLmxlbmd0aCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gYnVmOwogICAgICAgICAgfQogICAgICAgICAgb2JqLmNvcHkoYnVmLCAwLCAwLCBsZW4pOwogICAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai5sZW5ndGggIT09IHZvaWQgMCkgewogICAgICAgICAgaWYgKHR5cGVvZiBvYmoubGVuZ3RoICE9PSAibnVtYmVyIiB8fCBudW1iZXJJc05hTihvYmoubGVuZ3RoKSkgewogICAgICAgICAgICByZXR1cm4gY3JlYXRlQnVmZmVyKDApOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqKTsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai50eXBlID09PSAiQnVmZmVyIiAmJiBBcnJheS5pc0FycmF5KG9iai5kYXRhKSkgewogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqLmRhdGEpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBjaGVja2VkKGxlbmd0aCkgewogICAgICAgIGlmIChsZW5ndGggPj0gS19NQVhfTEVOR1RIKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiQXR0ZW1wdCB0byBhbGxvY2F0ZSBCdWZmZXIgbGFyZ2VyIHRoYW4gbWF4aW11bSBzaXplOiAweCIgKyBLX01BWF9MRU5HVEgudG9TdHJpbmcoMTYpICsgIiBieXRlcyIpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gbGVu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SAwLCBsZW4gPSBNYXRoLm1pbih4LCB5KTsgaSA8IGxlbjsgKytpKSB7CiAgICAgICAgICBpZiAoYVtpXSAhPT0gYltpXSkgewogICAgICAgICAgICB4ID0gYVtpXTsKICAgICAgICAgICAgeSA9IGJbaV07CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoeCA8IHkpCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHkgPCB4KQogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgcmV0dXJuIDA7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjEwLmlzRW5jb2RpbmcgPSBmdW5jdGlvbiBpc0VuY29kaW5nKGVuY29kaW5nKSB7CiAgICAgICAgc3dpdGNoIChTdHJpbmcoZW5jb2RpbmcpLnRvTG93ZXJDYXNlKCkpIHsKICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICBjYXNlICJ1dGY4IjoKICAgICAgICAgIGNhc2UgInV0Zi04IjoKICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgIGNhc2UgImxhdGluMSI6CiAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgY2FzZSAidXRmMTZsZSI6CiAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgfTsKICAgICAgQnVmZmVyMTAuY29uY2F0ID0gZnVuY3Rpb24gY29uY2F0KGxpc3QsIGxlbmd0aCkgewogICAgICAgIGlmICghQXJyYXkuaXNBcnJheShsaXN0KSkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignImxpc3QiIGFyZ3VtZW50IG11c3QgYmUgYW4gQXJyYXkgb2YgQnVmZmVycycpOwogICAgICAgIH0KICAgICAgICBpZiAobGlzdC5sZW5ndGggPT09IDApIHsKICAgICAgICAgIHJldHVybiBCdWZmZXIxMC5hbGxvYygwKTsKICAgICAgICB9CiAgICAgICAgbGV0IGk7CiAgICAgICAgaWYgKGxlbmd0aCA9PT0gdm9pZCAwKSB7CiAgICAgICAgICBsZW5ndGggPSAwOwogICAgICAgICAgZm9yIChpID0gMDsgaSA8IGxpc3QubGVuZ3RoOyArK2kpIHsKICAgICAgICAgICAgbGVuZ3RoICs9IGxpc3RbaV0ubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIgPSBCdWZmZXIxMC5hbGxvY1Vuc2FmZShsZW5ndGgpOwogICAgICAgIGxldCBwb3MgPSAwOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsaXN0Lmxlbmd0aDsgKytpKSB7CiAgICAgICAgICBsZXQgYnVmID0gbGlzdFtpXTsKICAgICAgICAgIGlmIChpc0luc3RhbmNlKGJ1ZiwgVWludDhBcnJheSkpIHsKICAgICAgICAgICAgaWYgKHBvcyArIGJ1Zi5sZW5ndGggPiBidWZmZXIubGVuZ3RoKSB7CiAgICAgICAgICAgICAgaWYgKCFCdWZmZXIxMC5pc0J1ZmZlcihidWYpKQogICAgICAgICAgICAgICAgYnVmID0gQnVmZmVyMTAuZnJvbShidWYpOwogICAgICAgICAgICAgIGJ1Zi5jb3B5KGJ1ZmZlciwgcG9zKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBVaW50OEFycmF5LnByb3RvdHlwZS5zZXQuY2FsbChidWZmZXIsIGJ1ZiwgcG9zKTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIGlmICghQnVmZmVyMTAuaXNCdWZmZXIoYnVmKSkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCcibGlzdCIgYXJndW1lbnQgbXVzdCBiZSBhbiBBcnJheSBvZiBCdWZmZXJzJyk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBidWYuY29weShidWZmZXIsIHBvcyk7CiAgICAgICAgICB9CiAgICAgICAgICBwb3MgKz0gYnVmLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZmZlcjsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gYnl0ZUxlbmd0aChzdHJpbmcsIGVuY29kaW5nKSB7CiAgICAgICAgaWYgKEJ1ZmZlcjEwLmlzQnVmZmVyKHN0cmluZykpIHsKICAgICAgICAgIHJldHVybiBzdHJpbmcubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoQXJyYXlCdWZmZXIuaXNWaWV3KHN0cmluZykgfHwgaXNJbnN0YW5jZShzdHJpbmcsIEFycmF5QnVmZmVyKSkgewogICAgICAgICAgcmV0dXJuIHN0cmluZy5ieXRlTGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAodHlwZW9mIHN0cmluZyAhPT0gInN0cmluZyIpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJ1RoZSAic3RyaW5nIiBhcmd1bWVudCBtdXN0IGJlIG9uZSBvZiB0eXBlIHN0cmluZywgQnVmZmVyLCBvciBBcnJheUJ1ZmZlci4gUmVjZWl2ZWQgdHlwZSAnICsgdHlwZW9mIHN0cmluZyk7CiAgICAgICAgfQogICAgICAgIGNvbnN0IGxlbiA9IHN0cmluZy5sZW5ndGg7CiAgICAgICAgY29uc3QgbXVzdE1hdGNoID0gYXJndW1lbnRzLmxlbmd0aCA+IDIgJiYgYXJndW1lbnRzWzJdID09PSB0cnVlOwogICAgICAgIGlmICghbXVzdE1hdGNoICYmIGxlbiA9PT0gMCkKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIGxldCBsb3dlcmVkQ2FzZSA9IGZhbHNlOwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgc3dpdGNoIChlbmNvZGluZykgewogICAgICAgICAgICBjYXNlICJhc2NpaSI6CiAgICAgICAgICAgIGNhc2UgImxhdGluMSI6CiAgICAgICAgICAgIGNhc2UgImJpbmFyeSI6CiAgICAgICAgICAgICAgcmV0dXJuIGxlbjsKICAgICAgICAgICAgY2FzZSAidXRmOCI6CiAgICAgICAgICAgIGNhc2UgInV0Zi04IjoKICAgICAgICAgICAgICByZXR1cm4gdXRmOFRvQnl0ZXMoc3RyaW5nKS5sZW5ndGg7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIGxlbiAqIDI7CiAgICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICAgICAgcmV0dXJuIGxlbiA+Pj4gMTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0VG9CeXRlcyhzdHJpbmcpLmxlbmd0aDsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpIHsKICAgICAgICAgICAgICAgIHJldHVybiBtdXN0TWF0Y2ggPyAtMSA6IHV0ZjhUb0J5dGVzKHN0cmluZykubGVuZ3RoOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBlbmNvZGluZyA9ICgiIiArIGVuY29kaW5nKS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgICAgIGxvd2VyZWRDYXNlID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgQnVmZmVyMTAuYnl0ZUxlbmd0aCA9IGJ5dGVMZW5ndGg7CiAgICAgIGZ1bmN0aW9uIHNsb3dUb1N0cmluZyhlbmNvZGluZywgc3RhcnQsIGVuZCkgewogICAgICAgIGxldCBsb3dlcmVkQ2FzZSA9IGZhbHNlOwogICAgICAgIGlmIChzdGFydCA9PT0gdm9pZCAwIHx8IHN0YXJ0IDwgMCkgewogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPiB0aGlzLmxlbmd0aCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kID09PSB2b2lkIDAgfHwgZW5kID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kIDw9IDApIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgZW5kID4+Pj0gMDsKICAgICAgICBzdGFydCA+Pj49IDA7CiAgICAgICAgaWYgKGVuZCA8PSBzdGFydCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoIWVuY29kaW5nKQogICAgICAgICAgZW5jb2RpbmcgPSAidXRmOCI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgICAgICByZXR1cm4gaGV4U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICAgIHJldHVybiBhc2NpaVNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsYXRpbjFTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjE2bGVTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gKGVuY29kaW5nICsgIiIpLnRvTG93ZXJDYXNlKCk7CiAgICAgICAgICAgICAgbG93ZXJlZENhc2UgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBCdWZmZXIxMC5wcm90b3R5cGUuX2lzQnVmZmVyID0gdHJ1ZTsKICAgICAgZnVuY3Rpb24gc3dhcChiLCBuLCBtKSB7CiAgICAgICAgY29uc3QgaSA9IGJbbl07CiAgICAgICAgYltuXSA9IGJbbV07CiAgICAgICAgYlttXSA9IGk7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnN3YXAxNiA9IGZ1bmN0aW9uIHN3YXAxNigpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgMiAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiAxNi1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDIpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDEpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnN3YXAzMiA9IGZ1bmN0aW9uIHN3YXAzMigpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgNCAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiAzMi1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDQpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDMpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMSwgaSArIDIpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnN3YXA2NCA9IGZ1bmN0aW9uIHN3YXA2NCgpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgOCAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiA2NC1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDgpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDcpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMSwgaSArIDYpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMiwgaSArIDUpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMywgaSArIDQpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVy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vaWQgMCkgewogICAgICAgICAgdGhpc0VuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPCAwIHx8IGVuZCA+IHRhcmdldC5sZW5ndGggfHwgdGhpc1N0YXJ0IDwgMCB8fCB0aGlzRW5kID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCJvdXQgb2YgcmFuZ2UgaW5kZXgiKTsKICAgICAgICB9CiAgICAgICAgaWYgKHRoaXNTdGFydCA+PSB0aGlzRW5kICYmIHN0YXJ0ID49IGVuZCkgewogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzU3RhcnQgPj0gdGhpc0VuZCkgewogICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPj0gZW5kKSB7CiAgICAgICAgICByZXR1cm4gMTsKICAgICAgICB9CiAgICAgICAgc3RhcnQgPj4+PSAwOwogICAgICAgIGVuZCA+Pj49IDA7CiAgICAgICAgdGhpc1N0YXJ0ID4+Pj0gMDsKICAgICAgICB0aGlzRW5kID4+Pj0gMDsKICAgICAgICBpZiAodGhpcyA9PT0gdGFyZ2V0KQogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgbGV0IHggPSB0aGlzRW5kIC0gdGhpc1N0YXJ0OwogICAgICAgIGxldCB5ID0gZW5kIC0gc3RhcnQ7CiAgICAgICAgY29uc3QgbGVuID0gTWF0aC5taW4oeCwgeSk7CiAgICAgICAgY29uc3QgdGhpc0NvcHkgPSB0aGlzLnNsaWNlKHRoaXNTdGFydCwgdGhpc0VuZCk7CiAgICAgICAgY29uc3QgdGFyZ2V0Q29weSA9IHRhcmdldC5zbGljZShzdGFydCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbjsgKytpKSB7CiAgICAgICAgICBpZiAodGhpc0NvcHlbaV0gIT09IHRhcmdldENvcH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zZXQ7CiAgICAgICAgaWYgKGJ5dGVPZmZzZXQgPj0gYnVmZmVyLmxlbmd0aCkgewogICAgICAgICAgaWYgKGRpcikKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgZWxzZQogICAgICAgICAgICBieXRlT2Zmc2V0ID0gYnVmZmVyLmxlbmd0aCAtIDE7CiAgICAgICAgfSBlbHNlIGlmIChieXRlT2Zmc2V0IDwgMCkgewogICAgICAgICAgaWYgKGRpcikKICAgICAgICAgICAgYnl0ZU9mZnNldCA9IDA7CiAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgaWYgKHR5cGVvZiB2YWwgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICB2YWwgPSBCdWZmZXIxMC5mcm9tKHZhbCwgZW5jb2RpbmcpOwogICAgICAgIH0KICAgICAgICBpZiAoQnVmZmVyMTAuaXNCdWZmZXIodmFsKSkgewogICAgICAgICAgaWYgKHZhbC5sZW5ndGggPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGFycmF5SW5kZXhPZihidWZmZXIsIHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGRpcik7CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgdmFsID0gdmFsICYgMjU1OwogICAgICAgICAgaWYgKHR5cGVvZiBVaW50OEFycmF5LnByb3RvdHlwZS5pbmRleE9mID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgIGlmIChkaXIpIHsKICAgICAgICAgICAgICByZXR1cm4gVWludDhBcnJheS5wcm90b3R5cGUuaW5kZXhPZi5jYWxsKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0KTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICByZXR1cm4gVWludDhBcnJheS5wcm90b3R5cGUubGFzdEluZGV4T2YuY2FsbChidWZmZXIsIHZhbCwgYnl0ZU9mZnNldCk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBhcnJheUluZGV4T2YoYnVmZmVyLCBbdmFsXSwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGRpcik7CiAgICAgICAgfQogICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoInZhbCBtdXN0IGJlIHN0cmluZywgbnVtYmVyIG9yIEJ1ZmZlciIpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGFycmF5SW5kZXhPZihhcnIsIHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGRpcikgewogICAgICAgIGxldCBpbmRleFNpemUgPSAxOwogICAgICAgIGxldCBhcnJMZW5ndGggPSBhcnIubGVuZ3RoOwogICAgICAgIGxldCB2YWxMZW5ndGggPSB2YWwubGVuZ3RoOwogICAgICAgIGlmIChlbmNvZGluZyAhPT0gdm9pZCAwKSB7CiAgICAgICAgICBlbmNvZGluZyA9IFN0cmluZyhlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgIGlmIChlbmNvZGluZyA9PT0gInVjczIiIHx8IGVuY29kaW5nID09PSAidWNzLTIiIHx8IGVuY29kaW5nID09PSAidXRmMTZsZSIgfHwgZW5jb2RpbmcgPT09ICJ1dGYtMTZsZSIpIHsKICAgICAgICAgICAgaWYgKGFyci5sZW5ndGggPCAyIHx8IHZhbC5sZW5ndGggPCAyKSB7CiAgICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGluZGV4U2l6ZSA9IDI7CiAgICAgICAgICAgIGFyckxlbmd0aCAvPSAyOwogICAgICAgICAgICB2YWxMZW5ndGggLz0gMjsKICAgICAgICAgICAgYnl0ZU9mZnNldCAvPSAyOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiByZWFkKGJ1ZiwgaTIpIHsKICAgICAgICAgIGlmIChpbmRleFNpemUgPT09IDEpIHsKICAgICAgICAgICAgcmV0dXJuIGJ1ZltpMl07CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByZXR1cm4gYnVmLnJlYWRVSW50MTZCRShpMiAqIGluZGV4U2l6ZSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGxldCBpOwogICAgICAgIGlmIChkaXIpIHsKICAgICAgICAgIGxldCBmb3VuZEluZGV4ID0gLTE7CiAgICAgICAgICBmb3IgKGkgPSBieXRlT2Zmc2V0OyBpIDwgYXJyTGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgaWYgKHJlYWQoYXJyLCBpKSA9PT0gcmVhZCh2YWwsIGZvdW5kSW5kZXggPT09IC0xID8gMCA6IGkgLSBmb3VuZEluZGV4KSkgewogICAgICAgICAgICAgIGlmIChmb3VuZEluZGV4ID09PSAtMSkKICAgICAgICAgICAgICAgIGZvdW5kSW5kZXggPSBpOwogICAgICAgICAgICAgIGlmIChpIC0gZm91bmRJbmRleCArIDEgPT09IHZhbExlbmd0aCkKICAgICAgICAgICAgICAgIHJldHVybiBmb3VuZEluZGV4ICogaW5kZXhTaXplOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGlmIChmb3VuZEluZGV4ICE9PSAtMSkKICAgICAgICAgICAgICAgIGkgLT0gaSAtIGZvdW5kSW5kZXg7CiAgICAgICAgICAgICAgZm91bmRJbmRleCA9IC0xOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGlmIChieXRlT2Zmc2V0ICsgdmFsTGVuZ3RoID4gYXJyTGVuZ3RoKQogICAgICAgICAgICBieXRlT2Zmc2V0ID0gYXJyTGVuZ3RoIC0gdmFsTGVuZ3RoOwogICAgICAgICAgZm9yIChpID0gYnl0ZU9mZnNldDsgaSA+PSAwOyBpLS0pIHsKICAgICAgICAgICAgbGV0IGZvdW5kID0gdHJ1ZTsKICAgICAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCB2YWxMZW5ndGg7IGorKykgewogICAgICAgICAgICAgIGlmIChyZWFkKGFyciwgaSArIGopICE9PSByZWFkKHZhbCwgaikpIHsKICAgICAgICAgICAgICAgIGZvdW5kID0gZmFsc2U7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGZvdW5kKQogICAgICAgICAgICAgIHJldHVybiBpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gLTE7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLmluY2x1ZGVzID0gZnVuY3Rpb24gaW5jbHVkZXModmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiB0aGlzLmluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgIT09IC0xOwogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUuaW5kZXhPZiA9IGZ1bmN0aW9uIGluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiBiaWRpcmVjdGlvbmFsSW5kZXhPZih0aGlzLCB2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nLCB0cnVlKTsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLmxhc3RJbmRleE9mID0gZnVuY3Rpb24gbGFzdEluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiBiaWRpcmVjdGlvbmFsSW5kZXhPZih0aGlzLCB2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nLCBmYWxzZSk7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGhleFdyaXRlKGJ1Ziwgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCkgewogICAgICAgIG9mZnNldCA9IE51bWJlcihvZmZzZXQpIHx8IDA7CiAgICAgICAgY29uc3QgcmVtYWluaW5nID0gYnVmLmxlbmd0aCAtIG9mZnNldDsKICAgICAgICBpZiAoIWxlbmd0aCkgewogICAgICAgICAgbGVuZ3RoID0gcmVtYWluaW5nOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBsZW5ndGggPSBOdW1iZXIobGVuZ3RoKTsKICAgICAgICAgIGlmIChsZW5ndGggPiByZW1haW5pbmcpIHsKICAgICAgICAgICAgbGVuZ3RoID0gcmVtYWluaW5nOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb25zdCBzdHJMZW4gPSBzdHJpbmcubGVuZ3RoOwogICAgICAgIGlmIChsZW5ndGggPiBzdHJMZW4gLyAyKSB7CiAgICAgICAgICBsZW5ndGggPSBzdHJMZW4gLyAyOwogICAgICAgIH0KICAgICAgICBsZXQgaTsKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGNvbnN0IHBhcnNlZCA9IHBhcnNlSW50KHN0cmluZy5zdWJzdHIoaSAqIDIsIDIpLCAxNik7CiAgICAgICAgICBpZiAobnVtYmVySXNOYU4ocGFyc2VkKSkKICAgICAgICAgICAgcmV0dXJuIGk7CiAgICAgICAgICBidWZbb2Zmc2V0ICsgaV0gPSBwYXJzZWQ7CiAgICAgICAgfQogICAgICAgIHJldHVybiBpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHV0ZjhXcml0ZShidWYsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpIHsKICAgICAgICByZXR1cm4gYmxpdEJ1ZmZlcih1dGY4VG9CeXRlcyhzdHJpbmcsIGJ1Zi5sZW5ndGggLSBvZmZzZXQpLCBidWYsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBhc2NpaVdyaXRlKGJ1Ziwgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCkgewogICAgICAgIHJldHVybiBibGl0QnVmZmVyKGFzY2lpVG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CiAgICAgICAgICAgIGlmIChlbmNvZGluZyA9PT0gdm9pZCAwKQogICAgICAgICAgICAgIGVuY29kaW5nID0gInV0ZjgiOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgZW5jb2RpbmcgPSBsZW5ndGg7CiAgICAgICAgICAgIGxlbmd0aCA9IHZvaWQgMDsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJCdWZmZXIud3JpdGUoc3RyaW5nLCBlbmNvZGluZywgb2Zmc2V0WywgbGVuZ3RoXSkgaXMgbm8gbG9uZ2VyIHN1cHBvcnRlZCIpOwogICAgICAgIH0KICAgICAgICBjb25zdCByZW1haW5pbmcgPSB0aGlzLmxlbmd0aCAtIG9mZnNldDsKICAgICAgICBpZiAobGVuZ3RoID09PSB2b2lkIDAgfHwgbGVuZ3RoID4gcmVtYWluaW5nKQogICAgICAgICAgbGVuZ3RoID0gcmVtYWluaW5nOwogICAgICAgIGlmIChzdHJpbmcubGVuZ3RoID4gMCAmJiAobGVuZ3RoIDwgMCB8fCBvZmZzZXQgPCAwKSB8fCBvZmZzZXQgPiB0aGlzLmxlbmd0aCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkF0dGVtcHQgdG8gd3JpdGUgb3V0c2lkZSBidWZmZXIgYm91bmRzIik7CiAgICAgICAgfQogICAgICAgIGlmICghZW5jb2RpbmcpCiAgICAgICAgICBlbmNvZGluZyA9ICJ1dGY4IjsKICAgICAgICBsZXQgbG93ZXJlZENhc2UgPSBmYWxzZTsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgICAgICByZXR1cm4gaGV4V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBhc2NpaVdyaXRlKHRoaXMsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpOwogICAgICAgICAgICBjYXNlICJiYXNlNjQiOgogICAgICAgICAgICAgIHJldHVybiBiYXNlNjRXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAidWNzMiI6CiAgICAgICAgICAgIGNhc2UgInVjcy0yIjoKICAgICAgICAgICAgY2FzZSAidXRmMTZsZSI6CiAgICAgICAgICAgIGNhc2UgInV0Zi0xNmxlIjoKICAgICAgICAgICAgICByZXR1cm4gdWNzMldyaXRlKHRoaXMsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpOwogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgIGlmIChsb3dlcmVkQ2FzZSkKICAgICAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoIlVua25vd24gZW5jb2Rpbmc6ICIgKyBlbmNvZGluZyk7CiAgICAgICAgICAgICAgZW5jb2RpbmcgPSAoIiIgKyBlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgICAgICBsb3dlcmVkQ2FzZSA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUudG9KU09OID0gZnVuY3Rpb24gdG9KU09OKCkgewogICAgICAgIHJldHVybiB7CiAgICAgICAgICB0eXBlOiAiQnVmZmVyIiwKICAgICAgICAgIGRhdGE6IEFycmF5LnByb3RvdHlwZS5zbGljZS5jYWxsKHR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ICAgICAgICAgY29kZVBvaW50ID0gZmlyc3RCeXRlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgc2Vjb25kQnl0ZSA9IGJ1ZltpICsgMV07CiAgICAgICAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAzMSkgPDwgNiB8IHNlY29uZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAxMjcpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIDM6CiAgICAgICAgICAgICAgICBzZWNvbmRCeXRlID0gYnVmW2kgKyAxXTsKICAgICAgICAgICAgICAgIHRoaXJkQnl0ZSA9IGJ1ZltpICsgMl07CiAgICAgICAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKHRoaXJkQnl0ZSAmIDE5MikgPT09IDEyOCkgewogICAgICAgICAgICAgICAgICB0ZW1wQ29kZVBvaW50ID0gKGZpcnN0Qnl0ZSAmIDE1KSA8PCAxMiB8IChzZWNvbmRCeXRlICYgNjMpIDw8IDYgfCB0aGlyZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAyMDQ3ICYmICh0ZW1wQ29kZVBvaW50IDwgNTUyOTYgfHwgdGVtcENvZGVQb2ludCA+IDU3MzQzKSkgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgICAgIHNlY29uZEJ5dGUgPSBidWZbaSArIDFdOwogICAgICAgICAgICAgICAgdGhpcmRCeXRlID0gYnVmW2kgKyAyXTsKICAgICAgICAgICAgICAgIGZvdXJ0aEJ5dGUgPSBidWZbaSArIDNdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmICh0aGlyZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKGZvdXJ0aEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAxNSkgPDwgMTggfCAoc2Vjb25kQnl0ZSAmIDYzKSA8PCAxMiB8ICh0aGlyZEJ5dGUgJiA2MykgPDwgNiB8IGZvdXJ0aEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiA2NTUzNSAmJiB0ZW1wQ29kZVBvaW50IDwgMTExNDExMikgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKGNvZGVQb2ludCA9PT0gbnVsbCkgewogICAgICAgICAgICBjb2RlUG9pbnQgPSA2NTUzMzsKICAgICAgICAgICAgYnl0ZXNQZXJTZXF1ZW5jZSA9IDE7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA+IDY1NTM1KSB7CiAgICAgICAgICAgIGNvZGVQb2ludCAtPSA2NTUzNjsKICAgICAgICAgICAgcmVzLnB1c2goY29kZVBvaW50ID4+PiAxMCAmIDEwMjMgfCA1NTI5Nik7CiAgICAgICAgICAgIGNvZGVQb2ludCA9IDU2MzIwIHwgY29kZVBvaW50ICYgMTAyMzsKICAgICAgICAgIH0KICAgICAgICAgIHJlcy5wdXNoKGNvZGVQb2ludCk7CiAgICAgICAgICBpICs9IGJ5dGVzUGVyU2VxdWVuY2U7CiAgICAgICAgfQogICAgICAgIHJldHVybiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkocmVzKTsKICAgICAgfQogICAgICB2YXIgTUFYX0FSR1VNRU5UU19MRU5HVEggPSA0MDk2OwogICAgICBmdW5jdGlvbiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkoY29kZVBvaW50cykgewogICAgICAgIGNvbnN0IGxlbiA9IGNvZGVQb2ludHMubGVuZ3RoOwogICAgICAgIGlmIChsZW4gPD0gTUFYX0FSR1VNRU5UU19MRU5HVEgpIHsKICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cyk7CiAgICAgICAgfQogICAgICAgIGxldCByZXMgPSAiIjsKICAgICAgICBsZXQgaSA9IDA7CiAgICAgICAgd2hpbGUgKGkgPCBsZW4pIHsKICAgICAgICAgIHJlcyArPSBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cy5zbGljZShpLCBpICs9IE1BWF9BUkdVTUVOVFNfTEVOR1RIKSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXNjaWlTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldICYgMTI3KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBsYXRpbjFTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBoZXhTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBjb25zdCBsZW4gPSBidWYubGVuZ3RoOwogICAgICAgIGlmICghc3RhcnQgfHwgc3RhcnQgPCAwKQogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIGlmICghZW5kIHx8IGVuZCA8IDAgfHwgZW5kID4gbGVuKQogICAgICAgICAgZW5kID0gbGVuOwogICAgICAgIGxldCBvdXQgPSAiIjsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgb3V0ICs9IGhleFNsaWNlTG9va3VwVGFibGVbYnVmW2ldXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG91dDsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGYxNmxlU2xpY2UoYnVmLCBzdGFydCwgZW5kKSB7CiAgICAgICAgY29uc3QgYnl0ZXMgPSBidWYuc2xpY2Uoc3RhcnQsIGVuZCk7CiAgICAgICAgbGV0IHJlcyA9ICIiOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgYnl0ZXMubGVuZ3RoIC0gMTsgaSArPSAyKSB7CiAgICAgICAgICByZXMgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShieXRlc1tpXSArIGJ5dGVzW2kgKyAxXSAqIDI1Nik7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnNsaWNlID0gZnVuY3Rpb24gc2xpY2Uoc3RhcnQsIGVuZCkgewogICAgICAgIGNvbnN0IGxlbiA9IHRoaXMubGVuZ3RoOwogICAgICAgIHN0YXJ0ID0gfn5zdGFydDsKICAgICAgICBlbmQgPSBlbmQgPT09IHZvaWQgMCA/IGxlbiA6IH5+ZW5kOwogICAgICAgIGlmIChzdGFydCA8IDApIHsKICAgICAgICAgIHN0YXJ0ICs9IGxlbjsKICAgICAgICAgIGlmIChzdGFydCA8IDApCiAgICAgICAgICAgIHN0YXJ0ID0gMDsKICAgICAgICB9IGVsc2UgaWYgKHN0YXJ0ID4gbGVuKSB7CiAgICAgICAgICBzdGFydCA9IGxlbjsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA8IDApIHsKICAgICAgICAgIGVuZCArPSBsZW47CiAgICAgICAgICBpZiAoZW5kIDwgMCkKICAgICAgICAgICAgZW5kID0gMDsKICAgICAgICB9IGVsc2UgaWYgKGVuZCA+IGxlbikgewogICAgICAgICAgZW5kID0gbGVuOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kIDwgc3RhcnQpCiAgICAgICAgICBlbmQgPSBzdGFydDsKICAgICAgICBjb25zdCBuZXdCdWYgPSB0aGlzLnN1YmFycmF5KHN0YXJ0LCBlbmQpOwogICAgICAgIE9iamVjdC5zZXRQcm90b3R5cGVPZihuZXdCdWYsIEJ1ZmZlcjEwLnByb3RvdHlwZSk7CiAgICAgICAgcmV0dXJuIG5ld0J1ZjsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gY2hlY2tPZmZzZXQob2Zmc2V0LCBleHQsIGxlbmd0aCkgewogICAgICAgIGlmIChvZmZzZXQgJSAxICE9PSAwIHx8IG9mZnNldCA8IDApCiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigib2Zmc2V0IGlzIG5vdCB1aW50Iik7CiAgICAgICAgaWYgKG9mZnNldCArIGV4dC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AmJiAobXVsICo9IDI1NikpIHsKICAgICAgICAgIHZhbCArPSB0aGlzW29mZnNldCArIGldICogbXVsOwogICAgICAgIH0KICAgICAgICBtdWwgKj0gMTI4OwogICAgICAgIGlmICh2YWwgPj0gbXVsKQogICAgICAgICAgdmFsIC09IE1hdGgucG93KDIsIDggKiBieXRlTGVuZ3RoMik7CiAgICAgICAgcmV0dXJuIHZhbDsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnJlYWRJbnRCRSA9IGZ1bmN0aW9uIHJlYWRJbnRCRShvZmZzZXQsIGJ5dGVMZW5ndGgyLCBub0Fzc2VydCkgewogICAgICAgIG9mZnNldCA9IG9mZnNldCA+Pj4gMDsKICAgICAgICBieXRlTGVuZ3RoMiA9IGJ5dGVMZW5ndGgyID4+PiAwOwogICAgICAgIGlmICghbm9Bc3NlcnQpCiAgICAgICAgICBjaGVja09mZnNldChvZmZzZXQsIGJ5dGVMZW5ndGgyLCB0aGlzLmxlbmd0aCk7CiAgICAgICAgbGV0IGkgPSBieXRlTGVuZ3RoMjsKICAgICAgICBsZXQgbXVsID0gMTsKICAgICAgICBsZXQgdmFsID0gdGhpc1tvZmZzZXQgKyAtLWldOwogICAgICAgIHdoaWxlIChpID4gMCAmJiAobXVsICo9IDI1NikpIHsKICAgICAgICAgIHZhbCArPSB0aGlzW29mZnNldCArIC0taV0gKiBtdWw7CiAgICAgICAgfQogICAgICAgIG11bCAqPSAxMjg7CiAgICAgICAgaWYgKHZhbCA+PSBtdWwpCiAgICAgICAgICB2YWwgLT0gTWF0aC5wb3coMiwgOCAqIGJ5dGVMZW5ndGgyKTsKICAgICAgICByZXR1cm4gdmFsOwogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUucmVhZEludDggPSBmdW5jdGlvbiByZWFkSW50OChvZmZzZXQsIG5vQXNzZXJ0KSB7CiAgICAgICAgb2Zmc2V0ID0gb2Zmc2V0ID4+PiAwOwogICAgICAgIGlmICghbm9Bc3N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pb24gZmlsbCh2YWwsIHN0YXJ0LCBlbmQsIGVuY29kaW5nKSB7CiAgICAgICAgaWYgKHR5cGVvZiB2YWwgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICBpZiAodHlwZW9mIHN0YXJ0ID09PSAic3RyaW5nIikgewogICAgICAgICAgICBlbmNvZGluZyA9IHN0YXJ0OwogICAgICAgICAgICBzdGFydCA9IDA7CiAgICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgZW5kID09PSAic3RyaW5nIikgewogICAgICAgICAgICBlbmNvZGluZyA9IGVuZDsKICAgICAgICAgICAgZW5kID0gdGhpcy5sZW5ndGg7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoZW5jb2RpbmcgIT09IHZvaWQgMCAmJiB0eXBlb2YgZW5jb2RpbmcgIT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoImVuY29kaW5nIG11c3QgYmUgYSBzdHJpbmciKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0eXBlb2YgZW5jb2RpbmcgPT09ICJzdHJpbmciICYmICFCdWZmZXIxMC5pc0VuY29kaW5nKGVuY29kaW5nKSkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHZhbC5sZW5ndGggPT09IDEpIHsKICAgICAgICAgICAgY29uc3QgY29kZSA9IHZhbC5jaGFyQ29kZUF0KDApOwogICAgICAgICAgICBpZiAoZW5jb2RpbmcgPT09ICJ1dGY4IiAmJiBjb2RlIDwgMTI4IHx8IGVuY29kaW5nID09PSAibGF0aW4xIikgewogICAgICAgICAgICAgIHZhbCA9IGNvZGU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiB2YWwgPT09ICJ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IH0KICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBlbmQgLSBzdGFydDsgKytpKSB7CiAgICAgICAgICAgIHRoaXNbaSArIHN0YXJ0XSA9IGJ5dGVzW2kgJSBsZW5dOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgdmFyIGVycm9ycyA9IHt9OwogICAgICBmdW5jdGlvbiBFKHN5bSwgZ2V0TWVzc2FnZSwgQmFzZSkgewogICAgICAgIGVycm9yc1tzeW1dID0gY2xhc3MgTm9kZUVycm9yIGV4dGVuZHMgQmFzZSB7CiAgICAgICAgICBjb25zdHJ1Y3RvcigpIHsKICAgICAgICAgICAgc3VwZXIoKTsKICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJtZXNzYWdlIiwgewogICAgICAgICAgICAgIHZhbHVlOiBnZXRNZXNzYWdlLmFwcGx5KHRoaXMsIGFyZ3VtZW50cyksCiAgICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICAgIH0pOwogICAgICAgICAgICB0aGlzLm5hbWUgPSBgJHt0aGlzLm5hbWV9IFske3N5bX1dYDsKICAgICAgICAgICAgdGhpcy5zdGFjazsKICAgICAgICAgICAgZGVsZXRlIHRoaXMubmFtZTsKICAgICAgICAgIH0KICAgICAgICAgIGdldCBjb2RlKCkgewogICAgICAgICAgICByZXR1cm4gc3ltOwogICAgICAgICAgfQogICAgICAgICAgc2V0IGNvZGUodmFsdWUpIHsKICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJjb2RlIiwgewogICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICBlbnVtZXJhYmxlOiB0cnVlLAogICAgICAgICAgICAgIHZhbHVlLAogICAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlCiAg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Ym91bmRzRXJyb3Iob2Zmc2V0LCBidWYubGVuZ3RoIC0gKGJ5dGVMZW5ndGgyICsgMSkpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBjaGVja0ludEJJKHZhbHVlLCBtaW4sIG1heCwgYnVmLCBvZmZzZXQsIGJ5dGVMZW5ndGgyKSB7CiAgICAgICAgaWYgKHZhbHVlID4gbWF4IHx8IHZhbHVlIDwgbWluKSB7CiAgICAgICAgICBjb25zdCBuID0gdHlwZW9mIG1pbiA9PT0gImJpZ2ludCIgPyAibiIgOiAiIjsKICAgICAgICAgIGxldCByYW5nZTsKICAgICAgICAgIGlmIChieXRlTGVuZ3RoMiA+IDMpIHsKICAgICAgICAgICAgaWYgKG1pbiA9PT0gMCB8fCBtaW4gPT09IEJpZ0ludCgwKSkgewogICAgICAgICAgICAgIHJhbmdlID0gYD49IDAke259IGFuZCA8IDIke259ICoqICR7KGJ5dGVMZW5ndGgyICsgMSkgKiA4fSR7bn1gOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHJhbmdlID0gYD49IC0oMiR7bn0gKiogJHsoYnl0ZUxlbmd0aDIgKyAxKSAqIDggLSAxfSR7bn0pIGFuZCA8IDIgKiogJHsoYnl0ZUxlbmd0aDIgKyAxKSAqIDggLSAxfSR7bn1gOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByYW5nZSA9IGA+PSAke21pbn0ke259IGFuZCA8PSAke21heH0ke259YDsKICAgICAgICAgIH0KICAgICAgICAgIHRocm93IG5ldyBlcnJvcnMuRVJSX09VVF9PRl9SQU5HRSgidmFsdWUiLCByYW5nZSwgdmFsdWUpOwogICAgICAgIH0KICAgICAgICBjaGVja0JvdW5kcyhidWYsIG9mZnNldCwgYnl0ZUxlbmd0aDIpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHZhbGlkYXRlTnVtYmVyKHZhbHVlLCBuYW1lKSB7CiAgICAgICAgaWYgKHR5cG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gICAgIH0KICAgICAgICByZXR1cm4gc3RyOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHV0ZjhUb0J5dGVzKHN0cmluZywgdW5pdHMpIHsKICAgICAgICB1bml0cyA9IHVuaXRzIHx8IEluZmluaXR5OwogICAgICAgIGxldCBjb2RlUG9pbnQ7CiAgICAgICAgY29uc3QgbGVuZ3RoID0gc3RyaW5nLmxlbmd0aDsKICAgICAgICBsZXQgbGVhZFN1cnJvZ2F0ZSA9IG51bGw7CiAgICAgICAgY29uc3QgYnl0ZXMgPSBbXTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbmd0aDsgKytpKSB7CiAgICAgICAgICBjb2RlUG9pbnQgPSBzdHJpbmcuY2hhckNvZGVBdChpKTsKICAgICAgICAgIGlmIChjb2RlUG9pbnQgPiA1NTI5NSAmJiBjb2RlUG9pbnQgPCA1NzM0NCkgewogICAgICAgICAgICBpZiAoIWxlYWRTdXJyb2dhdGUpIHsKICAgICAgICAgICAgICBpZiAoY29kZVBvaW50ID4gNTYzMTkpIHsKICAgICAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgIH0gZWxzZSBpZiAoaSArIDEgPT09IGxlbmd0aCkgewogICAgICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGxlYWRTdXJyb2dhdGUgPSBjb2RlUG9pbnQ7CiAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGNvZGVQb2ludCA8IDU2MzIwKSB7CiAgICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgICAgICBsZWFkU3Vycm9nYXRlID0gY29kZVBvaW50OwogICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGNvZGVQb2ludCA9IChsZWFkU3Vycm9nYXRlIC0gNTUyOTYgPDwgMTAgfCBjb2RlUG9pbnQgLSA1NjMyMCkgKyA2NTUzNjsKICAgICAgICAgIH0gZWxzZSBpZiAobGVhZFN1cnJvZ2F0ZSkgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgIH0KICAgICAgICAgIGxlYWRTdXJyb2dhdGUgPSBudWxsOwogICAgICAgICAgaWYgKGNvZGVQb2ludCA8IDEyOCkgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDEpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQpOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPCAyMDQ4KSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMikgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCA+PiA2IHwgMTkyLCBjb2RlUG9pbnQgJiA2MyB8IDEyOCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA8IDY1NTM2KSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCA+PiAxMiB8IDIyNCwgY29kZVBvaW50ID4+IDYgJiA2MyB8IDEyOCwgY29kZVBvaW50ICYgNjMgfCAxMjgpOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPCAxMTE0MTEyKSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gNCkgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCA+PiAxOCB8IDI0MCwgY29kZVBvaW50ID4+IDEyICYgNjMgfCAxMjgsIGNvZGVQb2ludCA+PiA2ICYgNjMgfCAxMjgsIGNvZGVQb2ludCAmIDYzIHwgMTI4KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcigiSW52YWxpZCBjb2RlIHBvaW50Iik7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBieXRlczsKICAgICAgfQogICAgICBmdW5jdGlvbiBhc2NpaVRvQnl0ZXMoc3RyKSB7CiAgICAgICAgY29uc3QgYnl0ZUFycmF5ID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBzdHIubGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGJ5dGVBcnJheS5wdXNoKHN0ci5jaGFyQ29kZUF0KGkpICYgMjU1KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ5dGVBcnJheTsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGYxNmxlVG9CeXRlcyhzdHIsIHVuaXRzKSB7CiAgICAgICAgbGV0IGMsIGhpLCBsbzsKICAgICAgICBjb25zdCBieXRlQXJyYXkgPSBbXTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHN0ci5sZW5ndGg7ICsraSkgewogICAgICAgICAgaWYgKCh1bml0cyAtPSAyKSA8IDApCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgYyA9IHN0ci5jaGFyQ29kZUF0KGkpOwogICAgICAgICAgaGkgPSBjID4+IDg7CiAgICAgICAgICBsbyA9IGMgJSAyNTY7CiAgICAgICAgICBieXRlQXJyYXkucHVzaChsbyk7CiAgIC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GkgPCAxNjsgKytpKSB7CiAgICAgICAgICBjb25zdCBpMTYgPSBpICogMTY7CiAgICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IDE2OyArK2opIHsKICAgICAgICAgICAgdGFibGVbaTE2ICsgal0gPSBhbHBoYWJldFtpXSArIGFscGhhYmV0W2pdOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gdGFibGU7CiAgICAgIH0oKTsKICAgICAgZnVuY3Rpb24gZGVmaW5lQmlnSW50TWV0aG9kKGZuKSB7CiAgICAgICAgcmV0dXJuIHR5cGVvZiBCaWdJbnQgPT09ICJ1bmRlZmluZWQiID8gQnVmZmVyQmlnSW50Tm90RGVmaW5lZCA6IGZuOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIEJ1ZmZlckJpZ0ludE5vdERlZmluZWQoKSB7CiAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJCaWdJbnQgbm90IHN1cHBvcnRlZCIpOwogICAgICB9CiAgICB9CiAgfSk7CgogIC8vIHNyYy9hbGlhcy9idWZmZXItc2hpbS5qcwogIHZhciBpbXBvcnRfYnVmZmVyOwogIHZhciBpbml0X2J1ZmZlcl9zaGltID0gX19lc20oewogICAgInNyYy9hbGlhcy9idWZmZXItc2hpbS5qcyIoKSB7CiAgICAgIGltcG9ydF9idWZmZXIgPSBfX3RvTW9kdWxlKHJlcXVpcmVfYnVmZmVyKCkpOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vYWJvcnRjb250cm9sbGVyLXBvbHlmaWxsQDEuNy41L25vZGVfbW9kdWxlcy9hYm9ydGNvbnRyb2xsZXItcG9seWZpbGwvZGlzdC9janMtcG9ueWZpbGwuanMKICB2YXIgcmVxdWlyZV9janNfcG9ueWZpbGwgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vYWJvcnRjb250cm9sbGVyLXBvbHlmaWxsQDEuNy41L25vZGVfbW9kdWxlcy9hYm9yd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cm9wcykgewogICAgICAgIGlmIChwcm90b1Byb3BzKQogICAgICAgICAgX2RlZmluZVByb3BlcnRpZXMoQ29uc3RydWN0b3IucHJvdG90eXBlLCBwcm90b1Byb3BzKTsKICAgICAgICBpZiAoc3RhdGljUHJvcHMpCiAgICAgICAgICBfZGVmaW5lUHJvcGVydGllcyhDb25zdHJ1Y3Rvciwgc3RhdGljUHJvcHMpOwogICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShDb25zdHJ1Y3RvciwgInByb3RvdHlwZSIsIHsKICAgICAgICAgIHdyaXRhYmxlOiBmYWxzZQogICAgICAgIH0pOwogICAgICAgIHJldHVybiBDb25zdHJ1Y3RvcjsKICAgICAgfQogICAgICBmdW5jdGlvbiBfaW5oZXJpdHMoc3ViQ2xhc3MsIHN1cGVyQ2xhc3MpIHsKICAgICAgICBpZiAodHlwZW9mIHN1cGVyQ2xhc3MgIT09ICJmdW5jdGlvbiIgJiYgc3VwZXJDbGFzcyAhPT0gbnVsbCkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiU3VwZXIgZXhwcmVzc2lvbiBtdXN0IGVpdGhlciBiZSBudWxsIG9yIGEgZnVuY3Rpb24iKTsKICAgICAgICB9CiAgICAgICAgc3ViQ2xhc3MucHJvdG90eXBlID0gT2JqZWN0LmNyZWF0ZShzdXBlckNsYXNzICYmIHN1cGVyQ2xhc3MucHJvdG90eXBlLCB7CiAgICAgICAgICBjb25zdHJ1Y3RvcjogewogICAgICAgICAgICB2YWx1ZTogc3ViQ2xhc3MsCiAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlLAogICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUKICAgICAgICAgIH0KICAgICAgICB9KTsKICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoc3ViQ2xhc3MsICJwcm90b3R5cGUiLCB7CiAgICAgICAgICB3cml0YWJsZTogZmFsc2UKICAgICAgICB9KTsKICAgICAgICBpZiAoc3VwZXJDbGFzcykKICAgICAgICAgIF9zZXRQcm90b3R5cGVPZihzdWJDbGFzcywgc3VwZXJDbGFzcyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mKG8pIHsKICAgICAgICBfZ2V0UHJvdG90eXBlT2YgPSBPYmplY3Quc2V0UHJvdG90eXBlT2YgPyBPYmplY3QuZ2V0UHJvdG90eXBlT2YuYmluZCgpIDogZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mMihvMikgewogICAgICAgICAgcmV0dXJuIG8yLl9fcHJvdG9fXyB8fCBPYmplY3QuZ2V0UHJvdG90eXBlT2YobzIpOwogICAgICAgIH07CiAgICAgICAgcmV0dXJuIF9nZXRQcm90b3R5cGVPZihvKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YobywgcCkgewogICAgICAgIF9zZXRQcm90b3R5cGVPZiA9IE9iamVjdC5zZXRQcm90b3R5cGVPZiA/IE9iamVjdC5zZXRQcm90b3R5cGVPZi5iaW5kKCkgOiBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YyKG8yLCBwMikgewogICAgICAgICAgbzIuX19wcm90b19fID0gcDI7CiAgICAgICAgICByZXR1cm4gbzI7CiAgICAgICAgfTsKICAgICAgICByZXR1cm4gX3NldFByb3RvdHlwZU9mKG8sIHApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9pc05hdGl2ZVJlZmxlY3RDb25zdHJ1Y3QoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ID09PSAidW5kZWZpbmVkIiB8fCAhUmVmbGVjdC5jb25zdHJ1Y3QpCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKFJlZmxlY3QuY29uc3RydWN0LnNoYW0pCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKHR5cGVvZiBQcm94eSA9PT0gImZ1bmN0aW9uIikKICAgICAgICAgIHJldHVybiB0cnVl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dHJ1Y3QgPSBfaXNOYXRpdmVSZWZsZWN0Q29uc3RydWN0KCk7CiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uIF9jcmVhdGVTdXBlckludGVybmFsKCkgewogICAgICAgICAgdmFyIFN1cGVyID0gX2dldFByb3RvdHlwZU9mKERlcml2ZWQpLCByZXN1bHQ7CiAgICAgICAgICBpZiAoaGFzTmF0aXZlUmVmbGVjdENvbnN0cnVjdCkgewogICAgICAgICAgICB2YXIgTmV3VGFyZ2V0ID0gX2dldFByb3RvdHlwZU9mKHRoaXMpLmNvbnN0cnVjdG9yOwogICAgICAgICAgICByZXN1bHQgPSBSZWZsZWN0LmNvbnN0cnVjdChTdXBlciwgYXJndW1lbnRzLCBOZXdUYXJnZXQpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmVzdWx0ID0gU3VwZXIuYXBwbHkodGhpcywgYXJndW1lbnRzKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBfcG9zc2libGVDb25zdHJ1Y3RvclJldHVybih0aGlzLCByZXN1bHQpOwogICAgICAgIH07CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX3N1cGVyUHJvcEJhc2Uob2JqZWN0LCBwcm9wZXJ0eSkgewogICAgICAgIHdoaWxlICghT2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eS5jYWxsKG9iamVjdCwgcHJvcGVydHkpKSB7CiAgICAgICAgICBvYmplY3QgPSBfZ2V0UHJvdG90eXBlT2Yob2JqZWN0KTsKICAgICAgICAgIGlmIChvYmplY3QgPT09IG51bGwpCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICByZXR1cm4gb2JqZWN0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9nZXQoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ICE9PSAidW5kZWZpbmVkIiAmJiBSZWZsZWN0LmdldCkgewogICAgICAgICAgX2dldCA9IFJlZmxlY3QuZ2V0LmJpbmQoKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgX2dldCA9IGZ1bmN0aW9uIF9nZXQyKHRhcmdldCwgcHJvcGVydHksIHJlY2VpdmVyKSB7CiAgICAgICAgICAgIHZhciBiYXNlID0gX3N1cGVyUHJvcEJhc2UodGFyZ2V0LCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmICghYmFzZSkKICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIHZhciBkZXNjID0gT2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcihiYXNlLCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmIChkZXNjLmdldCkgewogICAgICAgICAgICAgIHJldHVybiBkZXNjLmdldC5jYWxsKGFyZ3VtZW50cy5sZW5ndGggPCAzID8gdGFyZ2V0IDogcmVjZWl2ZXIpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBkZXNjLnZhbHVlOwogICAgICAgICAgfTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIF9nZXQuYXBwbHkodGhpcywgYXJndW1lbnRzKTsKICAgICAgfQogICAgICB2YXIgRW1pdHRlciA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbigpIHsKICAgICAgICBmdW5jdGlvbiBFbWl0dGVyMigpIHsKICAgICAgICAgIF9jbGFzc0NhbGxDaGVjayh0aGlzLCBFbWl0dGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgImxpc3RlbmVycyIsIHsKICAgICAgICAgICAgdmFsdWU6IHt9LAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEVtaXR0ZXIyLCBbewogICAgICAgICAga2V5OiAiYWRkRXZlbnRMaXN0ZW5lciIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWRkRXZlbnRMaXN0ZW5lcih0eXBlLCBjYWxsYmFjaywgb3B0aW9ucykgewogICAgICAgICAgICBpZiAoISh0eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHRoaXMubGlzdGVuZXJzW3R5cGVdID0gW107CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5saXN0ZW5lcnNbdHlwZV0ucHVzaCh7CiAgICAgICAgICAgICAgY2FsbGJhY2ssCiAgICAgICAgICAgICAgb3B0aW9ucwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJyZW1vdmVFdmVudExpc3RlbmVyIiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiByZW1vdmVFdmVudExpc3RlbmVyKHR5cGUsIGNhbGxiYWNrKSB7CiAgICAgICAgICAgIGlmICghKHR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW3R5cGVdOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIGlmIChzdGFja1tpXS5jYWxsYmFjayA9PT0gY2FsbGJhY2spIHsKICAgICAgICAgICAgICAgIHN0YWNrLnNwbGljZShpLCAxKTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJkaXNwYXRjaEV2ZW50IiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiBkaXNwYXRjaEV2ZW50KGV2ZW50KSB7CiAgICAgICAgICAgIGlmICghKGV2ZW50LnR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW2V2ZW50LnR5cGVdOwogICAgICAgICAgICB2YXIgc3RhY2tUb0NhbGwgPSBzdGFjay5zbGljZSgpOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrVG9DYWxsLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIHZhciBsaXN0ZW5lciA9IHN0YWNrVG9DYWxsW2ldOwogICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICBsaXN0ZW5lci5jYWxsYmFjay5jYWxsKHRoaXMsIGV2ZW50KTsKICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICBQcm9taXNlLnJlc29sdmUoKS50aGVuKGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChsaXN0ZW5lci5vcHRpb25zICYmIGxpc3RlbmVyLm9wdGlvbnMub25jZSkgewogICAgICAgICAgICAgICAgdGhpcy5yZW1vdmVFdmVudExpc3RlbmVyKGV2ZW50LnR5cGUsIGxpc3RlbmVyLmNhbGxiYWNrKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuICFldmVudC5kZWZhdWx0UHJldmVudGVkOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gRW1pdHRlcjI7CiAgICAgIH0oKTsKICAgICAgdmFyIEFib3J0U2lnbmFsID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKF9FbWl0dGVyKSB7CiAgICAgICAgX2luaGVyaXRzKEFib3J0U2lnbmFsMiwgX0VtaXR0ZXIpOwogICAgICAgIHZhciBfc3VwZXIgPSBfY3JlYXRlU3VwZXIoQWJvcnRTaWduYWwyKTsKICAgICAgICBmdW5jdGlvbiBBYm9ydFNpZ25hbDIoKSB7CiAgICAgICAgICB2YXIgX3RoaXM7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRTaWduYWwyKTsKICAgICAgICAgIF90aGlzID0gX3N1cGVyLmNhbGwodGhpcyk7CiAgICAgICAgICBpZiAoIV90aGlzLmxpc3RlbmVycykgewogICAgICAgICAgICBFbWl0dGVyLmNhbGwoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcykpOwogICAgICAgICAgfQogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KF9hc3NlcnRUaGlzSW5pdGlhbGl6ZWQoX3RoaXMpLCAiYWJvcnRlZCIsIHsKICAgICAgICAgICAgdmFsdWU6IGZhbHNlLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgIm9uYWJvcnQiLCB7CiAgICAgICAgICAgIHZhbHVlOiBudWxsLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgInJlYXNvbiIsIHsKICAgICAgICAgICAgdmFsdWU6IHZvaWQgMCwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICByZXR1cm4gX3RoaXM7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhBYm9ydFNpZ25hbDIsIFt7CiAgICAgICAgICBrZXk6ICJ0b1N0cmluZyIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gdG9TdHJpbmcoKSB7CiAgICAgICAgICAgIHJldHVybiAiW29iamVjdCBBYm9ydFNpZ25hbF0iOwogICAgICAgICAgfQogICAgICAgIH0sIHsKICAgICAgICAgIGtleTogImRpc3BhdGNoRXZlbnQiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGRpc3BhdGNoRXZlbnQoZXZlbnQpIHsKICAgICAgICAgICAgaWYgKGV2ZW50LnR5cGUgPT09ICJhYm9ydCIpIHsKICAgICAgICAgICAgICB0aGlzLmFib3J0ZWQgPSB0cnVlOwogICAgICAgICAgICAgIGlmICh0eXBlb2YgdGhpcy5vbmFib3J0ID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgICAgICB0aGlzLm9uYWJvcnQuY2FsbCh0aGlzLCBldmVudCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIF9nZXQoX2dldFByb3RvdHlwZU9mKEFib3J0U2lnbmFsMi5wcm90b3R5cGUpLCAiZGlzcGF0Y2hFdmVudCIsIHRoaXMpLmNhbGwodGhpcywgZXZlbnQpOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gQWJvcnRTaWduYWwyOwogICAgICB9KEVtaXR0ZXIpOwogICAgICB2YXIgQWJvcnRDb250cm9sbGVyID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKCkgewogICAgICAgIGZ1bmN0aW9uIEFib3J0Q29udHJvbGxlcjIoKSB7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRDb250cm9sbGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgInNpZ25hbCIsIHsKICAgICAgICAgICAgdmFsdWU6IG5ldyBBYm9ydFNpZ25hbCgpLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEFib3J0Q29udHJvbGxlcjIsIFt7CiAgICAgICAgICBrZXk6ICJhYm9ydCIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWJvcnQocmVhc29uKSB7CiAgICAgICAgICAgIHZhciBldmVudDsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBldmVudCA9IG5ldyBFdmVudCgiYWJvcnQiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIGlmICh0eXBlb2YgZG9jdW1lbnQgIT09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICBpZiAoIWRvY3VtZW50LmNyZWF0ZUV2ZW50KSB7CiAgICAgICAgICAgICAgICAgIGV2ZW50ID0gZG9jdW1lbnQuY3JlYXRlRXZlbnRPYmplY3QoKTsKICAgICAgICAgICAgICAgICAgZXZlbnQudHlwZSA9ICJhYm9ydCI7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBldmVudCA9IGRvY3VtZW50LmNyZWF0ZUV2ZW50KCJFdmVudCIpOwogICAgICAgICAgICAgICAgICBldmVudC5pbml0RXZlbnQoImFib3J0IiwgZmFsc2UsIGZhbHNlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZXZlbnQgPSB7CiAgICAgICAgICAgICAgICAgIHR5cGU6ICJhYm9ydCIsCiAgICAgICAgICAgICAgICAgIGJ1YmJsZXM6IGZhbHNlLAogICAgICAgICAgICAgICAgICBjYW5jZWxhYmxlOiBmYWxzZQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIHNpZ25hbFJlYXNvbiA9IHJlYXNvbjsKICAgICAgICAgICAgaWYgKHNpZ25hbFJlYXNvbiA9PT0gdm9pZCAwKSB7CiAgICAgICAgICAgICAgaWYgKHR5cGVvZiBkb2N1bWVudCA9PT0gInVuZGVmaW5lZCIpIHsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbi5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRE9NRXhjZXB0aW9uKCJzaWduYWwgaXMgYWJvcnRlZCB3aXRob3V0IHJlYXNvbiIpOwogICAgICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgICAgc2lnbmFsUmVhc29uLm5hbWUgPSAiQWJvcnRFcnJvciI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuc2lnbmFsLnJlYXNvbiA9IHNpZ25hbFJlYXNvbjsKICAgICAgICAgICAgdGhpcy5zaWduYWwuZGlzcGF0Y2hFdmVudChldmVudCk7CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAidG9TdHJpbmciLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gIltvYmplY3QgQWJvcnRDb250cm9sbGVyXSI7CiAgICAgICAgICB9CiAgICAgICAgfV0pOwogICAgICAgIHJldHVybiBBYm9ydENvbnRyb2xsZXIyOwogICAgICB9KCk7CiAgICAgIGlmICh0eXBlb2YgU3ltYm9sICE9PSAidW5kZWZpbmVkIiAmJiBTe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dCA9IGZ1bmN0aW9uIFJlcXVlc3QyKGlucHV0LCBpbml0MikgewogICAgICAgICAgICB2YXIgc2lnbmFsOwogICAgICAgICAgICBpZiAoaW5pdDIgJiYgaW5pdDIuc2lnbmFsKSB7CiAgICAgICAgICAgICAgc2lnbmFsID0gaW5pdDIuc2lnbmFsOwogICAgICAgICAgICAgIGRlbGV0ZSBpbml0Mi5zaWduYWw7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIHJlcXVlc3QgPSBuZXcgTmF0aXZlUmVxdWVzdChpbnB1dCwgaW5pdDIpOwogICAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHJlcXVlc3QsICJzaWduYWwiLCB7CiAgICAgICAgICAgICAgICB3cml0YWJsZTogZmFsc2UsCiAgICAgICAgICAgICAgICBlbnVtZXJhYmxlOiBmYWxzZSwKICAgICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICAgIHZhbHVlOiBzaWduYWwKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gcmVxdWVzdDsKICAgICAgICAgIH07CiAgICAgICAgICBSZXF1ZXN0LnByb3RvdHlwZSA9IE5hdGl2ZVJlcXVlc3QucHJvdG90eXBlOwogICAgICAgIH0KICAgICAgICB2YXIgcmVhbEZldGNoID0gZmV0Y2g7CiAgICAgICAgdmFyIGFib3J0YWJsZUZldGNoID0gZnVuY3Rpb24gYWJvcnRhYmxlRmV0Y2gyKGlucHV0LCBpbml0MikgewogICAgICAgICAgdmFyIHNpZ25hbCA9IFJlcXVlc3QgJiYgUmVxdWVzdC5wcm90b3R5cGUuaXNQcm90b3R5cGVPZihpbnB1dCkgPyBpbnB1dC5zaWduYWwgOiBpbml0MiA/IGluaXQyLnNpZ25hbCA6IHZvaWQgMDsKICAgICAgICAgIGlmIChzaWduYWwpIHsKICAgICAgICAgICAgdmFyIGFib3J0RXJyb3I7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgYWJvcnRFcnJvciA9IG5ldyBET01FeGNlcHRpb24oIkFib3J0ZWQiLCAiQWJvcnRFcnJvciIpOwogICAgICAgICAgICB9IGNhdGNoIChlcnIpIHsKICAgICAgICAgICAgICBhYm9ydEVycm9yID0gbmV3IEVycm9yKCJBYm9ydGVkIik7CiAgICAgICAgICAgICAgYWJvcnRFcnJvci5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzaWduYWwuYWJvcnRlZCkgewogICAgICAgICAgICAgIHJldHVybiBQcm9taXNlLnJlamVjdChhYm9ydEVycm9yKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB2YXIgY2FuY2VsbGF0aW9uID0gbmV3IFByb21pc2UoZnVuY3Rpb24oXywgcmVqZWN0KSB7CiAgICAgICAgICAgICAgc2lnbmFsLmFkZEV2ZW50TGlzdGVuZXIoImFib3J0IiwgZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gcmVqZWN0KGFib3J0RXJyb3IpOwogICAgICAgICAgICAgIH0sIHsKICAgICAgICAgICAgICAgIG9uY2U6IHRydWUKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIGlmIChpbml0MiAmJiBpbml0Mi5zaWduYWwpIHsKICAgICAgICAgICAgICBkZWxldGUgaW5pdDIuc2lnbmFsOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBQcm9taXNlLnJhY2UoW2NhbmNlbGxhdGlvbiwgcmVhbEZldGNoKGlucHV0LCBpbml0MildKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiByZWFsRmV0Y2goaW5wdXQsIGluaXQyKTsKICAgICAgICB9OwogICAgICAgIHJldHVybiB7CiAgICAgICAgICBmZXRjaDogYWJvcnRhYmxlRmV0Y2gsCiAgICAgICAgICBSZXF1ZXN0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m9taXNlLWNhY2hlQDEuNS4wL25vZGVfbW9kdWxlcy9hYm9ydGFibGUtcHJvbWlzZS1jYWNoZS9lc20vQWdncmVnYXRlQWJvcnRDb250cm9sbGVyLmpzIihleHBvcnRzMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KGV4cG9ydHMyLCAiX19lc01vZHVsZSIsIHsgdmFsdWU6IHRydWUgfSk7CiAgICAgIHZhciBhYm9ydGNvbnRyb2xsZXJfcG9ueWZpbGxfMSA9IHJlcXVpcmVfYWJvcnRjb250cm9sbGVyX3BvbnlmaWxsKCk7CiAgICAgIHZhciBOdWxsU2lnbmFsID0gY2xhc3MgewogICAgICB9OwogICAgICB2YXIgQWdncmVnYXRlQWJvcnRDb250cm9sbGVyID0gY2xhc3MgewogICAgICAgIGNvbnN0cnVjdG9yKCkgewogICAgICAgICAgdGhpcy5zaWduYWxzID0gbmV3IFNldCgpOwogICAgICAgICAgdGhpcy5hYm9ydENvbnRyb2xsZXIgPSBuZXcgYWJvcnRjb250cm9sbGVyX3BvbnlmaWxsXzEuQWJvcnRDb250cm9sbGVyKCk7CiAgICAgICAgfQogICAgICAgIGFkZFNpZ25hbChzaWduYWwgPSBuZXcgTnVsbFNpZ25hbCgpKSB7CiAgICAgICAgICBpZiAodGhpcy5zaWduYWwuYWJvcnRlZCkgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImNhbm5vdCBhZGQgYSBzaWduYWwsIGFscmVhZHkgYWJvcnRlZCEiKTsKICAgICAgICAgIH0KICAgICAgICAgIHRoaXMuc2lnbmFscy5hZGQoc2lnbmFsKTsKICAgICAgICAgIGlmIChzaWduYWwuYWJvcnRlZCkgewogICAgICAgICAgICB0aGlzLmhhbmRsZUFib3J0ZWQoc2lnbmFsKTsKICAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHNpZ25hbC5hZGRFdmVudEx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gc2lnbmFsLCBzdGF0dXNDYWxsYmFjaykgewogICAgICAgICAgY29uc3QgYWJvcnRlciA9IG5ldyBBZ2dyZWdhdGVBYm9ydENvbnRyb2xsZXJfMS5kZWZhdWx0KCk7CiAgICAgICAgICBjb25zdCBzdGF0dXNSZXBvcnRlciA9IG5ldyBBZ2dyZWdhdGVTdGF0dXNSZXBvcnRlcl8xLmRlZmF1bHQoKTsKICAgICAgICAgIHN0YXR1c1JlcG9ydGVyLmFkZENhbGxiYWNrKHN0YXR1c0NhbGxiYWNrKTsKICAgICAgICAgIGNvbnN0IG5ld0VudHJ5ID0gewogICAgICAgICAgICBhYm9ydGVyLAogICAgICAgICAgICBwcm9taXNlOiB0aGlzLmZpbGxDYWxsYmFjayhkYXRhLCBhYm9ydGVyLnNpZ25hbCwgKG1lc3NhZ2UpID0+IHsKICAgICAgICAgICAgICBzdGF0dXNSZXBvcnRlci5jYWxsYmFjayhtZXNzYWdlKTsKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIHNldHRsZWQ6IGZhbHNlLAogICAgICAgICAgICBzdGF0dXNSZXBvcnRlciwKICAgICAgICAgICAgZ2V0IGFib3J0ZWQoKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuYWJvcnRlci5zaWduYWwuYWJvcnRlZDsKICAgICAgICAgICAgfQogICAgICAgICAgfTsKICAgICAgICAgIG5ld0VudHJ5LmFib3J0ZXIuYWRkU2lnbmFsKHNpZ25hbCk7CiAgICAgICAgICBuZXdFbnRyeS5hYm9ydGVyLnNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsICgpID0+IHsKICAgICAgICAgICAgaWYgKCFuZXdFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgdGhpcy5ldmljdChrZXksIG5ld0VudHJ5KTsKICAgICAgICAgICAgfQogICAgICAgICAgfSk7CiAgICAgICAgICBuZXdFbnRyeS5wcm9taXNlLnRoZW4oKCkgPT4gewogICAgICAgICAgICBuZXdFbnRyeS5zZXR0bGVkID0gdHJ1ZTsKICAgICAgICAgIH0sICgpID0+IHsKICAgICAgICAgICAgbmV3RW50cnkuc2V0dGxlZCA9IHRydWU7CiAgICAgICAgICAgIHRoaXMuZXZpY3Qoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgICB9KS5jYXRjaCgoZSkgPT4gewogICAgICAgICAgICBjb25zb2xlLmVycm9yKGUpOwogICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgfSk7CiAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIG5ld0VudHJ5KTsKICAgICAgICB9CiAgICAgICAgc3RhdGljIGNoZWNrU2luZ2xlUHJvbWlzZShwcm9taXNlLCBzaWduYWwpIHsKICAgICAgICAgIGZ1bmN0aW9uIGNoZWNrRm9yU2luZ2xlQWJvcnQoKSB7CiAgICAgICAgICAgIGlmIChzaWduYWwgJiYgc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICB0aHJvdyBPYmplY3QuYXNzaWduKG5ldyBFcnJvcigiYWJvcnRlZCIpLCB7IGNvZGU6ICJFUlJfQUJPUlRFRCIgfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBwcm9taXNlLnRoZW4oKHJlc3VsdCkgPT4gewogICAgICAgICAgICBjaGVja0ZvclNpbmdsZUFib3J0KCk7CiAgICAgICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgICAgICB9LCAoZXJyb3IpID0+IHsKICAgICAgICAgICAgY2hlY2tGb3JTaW5nbGVBYm9ydCgpOwogICAgICAgICAgICB0aHJvdyBlcnJvcjsKICAgICAgICAgIH0pOwogICAgICAgIH0KICAgICAgICBoYXMoa2V5KSB7CiAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5oYXMoa2V5KTsKICAgICAgICB9CiAgICAgICAgZ2V0KGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjaykgewogICAgICAgICAgaWYgKCFzaWduY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sYmFjayk7CiAgICAgICAgICByZXR1cm4gQWJvcnRhYmxlUHJvbWlzZUNhY2hlMi5jaGVja1NpbmdsZVByb21pc2UodGhpcy5jYWNoZS5nZXQoa2V5KS5wcm9taXNlLCBzaWduYWwpOwogICAgICAgIH0KICAgICAgICBkZWxldGUoa2V5KSB7CiAgICAgICAgICBjb25zdCBjYWNoZWRFbnRyeSA9IHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICBpZiAoY2FjaGVkRW50cnkpIHsKICAgICAgICAgICAgaWYgKCFjYWNoZWRFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgY2FjaGVkRW50cnkuYWJvcnRlci5hYm9ydCgpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuY2FjaGUuZGVsZXRlKGtleSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNsZWFyKCkgewogICAgICAgICAgY29uc3Qga2V5SXRlciA9IHRoaXMuY2FjaGUua2V5cygpOwogICAgICAgICAgbGV0IGRlbGV0ZUNvdW50ID0gMDsKICAgICAgICAgIGZvciAobGV0IHJlc3VsdCA9IGtleUl0ZXIubmV4dCgpOyAhcmVzdWx0LmRvbmU7IHJlc3VsdCA9IGtleUl0ZXIubmV4dCgpKSB7CiAgICAgICAgICAgIHRoaXMuZGVsZXRlKHJlc3VsdC52YWx1ZSk7CiAgICAgICAgICAgIGRlbGV0ZUNvdW50ICs9IDE7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gZGVsZXRlQ291bnQ7CiAgICAgICAgfQogICAgICB9OwogICAgICBleHBvcnRzMi5kZWZhdWx0ID0gQWJvcnRhYmxlUHJvbWlzZUNhY2hlMjsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL2Fib3J0YWJsZS1wcm9taXNlLWNhY2hlQDEuNS4wL25vZGVfbW9kdWxlcy9hYm9ydGFibGUtcHJvbWlzZS1jYWNoZS9lc20vaW5kZXguan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7CiAgICAgIHZhciBRdWlja0xSVSA9IGNsYXNzIHsKICAgICAgICBjb25zdHJ1Y3RvcihvcHRpb25zID0ge30pIHsKICAgICAgICAgIGlmICghKG9wdGlvbnMubWF4U2l6ZSAmJiBvcHRpb25zLm1heFNpemUgPiAwKSkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJgbWF4U2l6ZWAgbXVzdCBiZSBhIG51bWJlciBncmVhdGVyIHRoYW4gMCIpOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5tYXhTaXplID0gb3B0aW9ucy5tYXhTaXplOwogICAgICAgICAgdGhpcy5jYWNoZSA9IG5ldyBNYXAoKTsKICAgICAgICAgIHRoaXMub2xkQ2FjaGUgPSBuZXcgTWFwKCk7CiAgICAgICAgICB0aGlzLl9zaXplID0gMDsKICAgICAgICB9CiAgICAgICAgX3NldChrZXksIHZhbHVlKSB7CiAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIHZhbHVlKTsKICAgICAgICAgIHRoaXMuX3NpemUrKzsKICAgICAgICAgIGlmICh0aGlzLl9zaXplID49IHRoaXMubWF4U2l6ZSkgewogICAgICAgICAgICB0aGlzLl9zaXplID0gMDsKICAgICAgICAgICAgdGhpcy5vbGRDYWNoZSA9IHRoaXMuY2FjaGU7CiAgICAgICAgICAgIHRoaXMuY2FjaGUgPSBuZXcgTWFwKCk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGdldChrZXkpIHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzLmNhY2hlLmdldChrZXkpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHRoaXMub2xkQ2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgY29uc3QgdmFsdWUgPSB0aGlzLm9sZENhY2hlLmdldChrZXkpOwogICAgICAgICAgICB0aGlzLm9sZENhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgICB0aGlzLl9zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICAgIHJldHVybiB2YWx1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgc2V0KGtleSwgdmFsdWUpIHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHRoaXMuY2FjaGUuc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdGhpcy5fc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgfQogICAgICAgIGhhcyhrZXkpIHsKICAgICAgICAgIHJldHVybiB0aGlzLmNhY2hlLmhhcyhrZXkpIHx8IHRoaXMub2xkQ2FjaGUuaGFzKGtleSk7CiAgICAgICAgfQogICAgICAgIHBlZWsoa2V5KSB7CiAgICAgICAgICBpZiAodGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5nZXQoa2V5KTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0aGlzLm9sZENhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzLm9sZENhY2hlLmdldChrZXkpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBkZWxldGUoa2V5KSB7CiAgICAgICAgICBjb25zdCBkZWxldGVkID0gdGhpcy5jYWNoZS5kZWxldGUoa2V5KTsKICAgICAgICAgIGlmIChkZWxldGVkKSB7CiAgICAgICAgICAgIHRoaXMuX3NpemUtLTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiB0aGlzLm9sZENhY2hlLmRlbGV0ZShrZXkpIHx8IGRlbGV0ZWQ7CiAgICAgICAgfQogICAgICAgIGNsZWFyKCkgewogICAgICAgICAgdGhpcy5jYWNoZS5jbGVhcigpOwogICAgICAgICAgdGhpcy5vbGRDYWNoZS5jbGVhcigpOwogICAgICAgICAgdGhpcy5fc2l6ZSA9IDA7CiAgICAgICAgfQogICAgICAgICprZXlzKCkgewogICAgICAgICAgZm9yIChjb25zdCBba2V5XSBvZiB0aGlzKSB7CiAgICAgICAgICAgIHlpZWxkIGtleTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgKnZhbHVlcygpIHsKICAgICAgICAgIGZvciAoY29uc3QgWywgdmFsdWVdIG9mIHRoaXMpIHsKICAgICAgICAgICAgeWllbGQgdmFsdWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgICpbU3ltYm9sLml0ZXJhdG9yXSgpIHsKICAgICAgICAgIGZvciAoY29uc3QgaXRlbSBvZiB0aGlzLmNhY2hlKSB7CiAgICAgICAgICAgIHlpZWxkIGl0ZW07CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKGNvbnN0IGl0ZW0gb2YgdGhpcy5vbGRDYWNoZSkgewogICAgICAgICAgICBjb25zdCBba2V5XSA9IGl0ZW07CiAgICAgICAgICAgIGlmICghdGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICAgIHlpZWxkIGl0ZW07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZ2V0IHNpemUoKSB7CiAgICAgICAgICBsZXQgb2xkQ2FjaGVTaXplID0gMDsKICAgICAgICAgIGZvciAoY29uc3Qga2V5IG9mIHRoaXMub2xkQ2FjaGUua2V5cygpKSB7CiAgICAgICAgICAgIGlmICghdGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICAgIG9sZENhY2hlU2l6ZSsrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gdGhpcy5fc2l6ZSArIG9sZENhY2hlU2l6ZTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIG1vZHVsZTIuZXhwb3J0cyA9IFF1aWNrTFJVOwogICAgfQogIH0pOwoKICAvLyAoZGlzYWJsZWQpOm5vZGVfbW9kdWxlc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woYXJndW1lbnRzLCAxKTsKICAgICAgICB3aGlsZSAoc291cmNlcy5sZW5ndGgpIHsKICAgICAgICAgIHZhciBzb3VyY2UgPSBzb3VyY2VzLnNoaWZ0KCk7CiAgICAgICAgICBpZiAoIXNvdXJjZSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0eXBlb2Ygc291cmNlICE9PSAib2JqZWN0IikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKHNvdXJjZSArICJtdXN0IGJlIG5vbi1vYmplY3QiKTsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAodmFyIHAgaW4gc291cmNlKSB7CiAgICAgICAgICAgIGlmIChfaGFzKHNvdXJjZSwgcCkpIHsKICAgICAgICAgICAgICBvYmpbcF0gPSBzb3VyY2VbcF07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIG9iajsKICAgICAgfTsKICAgICAgZXhwb3J0czIuc2hyaW5rQnVmID0gZnVuY3Rpb24oYnVmLCBzaXplKSB7CiAgICAgICAgaWYgKGJ1Zi5sZW5ndGggPT09IHNpemUpIHsKICAgICAgICAgIHJldHVybiBidWY7CiAgICAgICAgfQogICAgICAgIGlmIChidWYuc3ViYXJyYXkpIHsKICAgICAgICAgIHJldHVybiBidWYuc3ViYXJyYXkoMCwgc2l6ZSk7CiAgICAgICAgfQogICAgICAgIGJ1Zi5sZW5ndGggPSBzaXplOwogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIHZhciBmblR5cGVkID0gewogICAgICAgIGFycmF5U2V0OiBmdW5jdGlvbihkZXN0LCBzcmMsIHNyY19vZmZzLCBsZW4sIGRlc3Rfb2ZmcykgewogICAgICAgICAgaWYgKHNyYy5zdWJhcnJheSAmJiBkZXN0LnN1YmFycmF5KSB7CiAgICAgICAgICAgIGRlc3Quc2V0KHNyYy5zdWJhcnJheShzcmNfb2Zmcywgc3JjX29mZnMgKyBsZW4pLCBkZXN0X29mZnMpOwogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgICAgIGRlc3RbZGVzdF9vZmZzICsgaV0gPSBzcmNbc3JjX29mZnMgKyBpXTsKICAgICAgICAgIH0KICAgICAgICB9LAogICAgICAgIGZsYXR0ZW5DaHVua3M6IGZ1bmN0aW9uKGNodW5rcykgewogICAgICAgICAgdmFyIGksIGwsIGxlbiwgcG9zLCBjaHVuaywgcmVzdWx0OwogICAgICAgICAgbGVuID0gMDsKICAgICAgICAgIGZvciAoaSA9IDAsIGwgPSBjaHVua3MubGVuZ3RoOyBpIDwgbDsgaSsrKSB7CiAgICAgICAgICAgIGxlbiArPSBjaHVua3NbaV0ubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgICAgcmVzdWx0ID0gbmV3IFVpbnQ4QXJyYXkobGVuKTsKICAgICAgICAgIHBvcyA9IDA7CiAgICAgICAgICBmb3IgKGkgPSAwLCBsID0gY2h1bmtzLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICBjaHVuayA9IGNodW5rc1tpXTsKICAgICAgICAgICAgcmVzdWx0LnNldChjaHVuaywgcG9zKTsKICAgICAgICAgICAgcG9zICs9IGNodW5rLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgICAgfQogICAgICB9OwogICAgICB2YXIgZm5VbnR5cGVkID0gewogICAgICAgIGFycmF5U2V0OiBmdW5jdGlvbihkZXN0LCBzcmMsIHNyY19vZmZzLCBsZW4sIGRlc3Rfb2ZmcykgewogICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgICBkZXN0W2Rlc3Rfb2ZmcyArIGldID0gc3JjW3NyY19vZmZzICsgaV07CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBm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RCA9IDQ7CiAgICAgIHZhciBaX0JJTkFSWSA9IDA7CiAgICAgIHZhciBaX1RFWFQgPSAxOwogICAgICB2YXIgWl9VTktOT1dOID0gMjsKICAgICAgZnVuY3Rpb24gemVybyhidWYpIHsKICAgICAgICB2YXIgbGVuID0gYnVmLmxlbmd0aDsKICAgICAgICB3aGlsZSAoLS1sZW4gPj0gMCkgewogICAgICAgICAgYnVmW2xlbl0gPSAwOwogICAgICAgIH0KICAgICAgfQogICAgICB2YXIgU1RPUkVEX0JMT0NLID0gMDsKICAgICAgdmFyIFNUQVRJQ19UUkVFUyA9IDE7CiAgICAgIHZhciBEWU5fVFJFRVMgPSAyOwogICAgICB2YXIgTUlOX01BVENIID0gMzsKICAgICAgdmFyIE1BWF9NQVRDSCA9IDI1ODsKICAgICAgdmFyIExFTkdUSF9DT0RFUyA9IDI5OwogICAgICB2YXIgTElURVJBTFMgPSAyNTY7CiAgICAgIHZhciBMX0NPREVTID0gTElURVJBTFMgKyAxICsgTEVOR1RIX0NPREVTOwogICAgICB2YXIgRF9DT0RFUyA9IDMwOwogICAgICB2YXIgQkxfQ09ERVMgPSAxOTsKICAgICAgdmFyIEhFQVBfU0laRSA9IDIgKiBMX0NPREVTICsgMTsKICAgICAgdmFyIE1BWF9CSVRTID0gMTU7CiAgICAgIHZhciBCdWZfc2l6ZSA9IDE2OwogICAgICB2YXIgTUFYX0JMX0JJVFMgPSA3OwogICAgICB2YXIgRU5EX0JMT0NLID0gMjU2OwogICAgICB2YXIgUkVQXzNfNiA9IDE2OwogICAgICB2YXIgUkVQWl8zXzEwID0gMTc7CiAgICAgIHZhciBSRVBaXzExXzEzOCA9IDE4OwogICAgICB2YXIgZXh0cmFfbGJpdHMgPSBbMCwgMCwgMCwgMCwgMCwgMCwgMCwgMCwgMSwgMSwgMSwgMSwgMiwgMiwgMiwgMiwgMywgMywgMywgMywgNCwgNCwgNCwgNCwgNSwgNSwgNSwgNSwgMF07CiAgICAgIHZhciBleHRyYV9kYml0cy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mlfYnVmICYgMjU1OwogICAgICAgICAgcy5iaV9idWYgPj49IDg7CiAgICAgICAgICBzLmJpX3ZhbGlkIC09IDg7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGdlbl9iaXRsZW4ocywgZGVzYykgewogICAgICAgIHZhciB0cmVlID0gZGVzYy5keW5fdHJlZTsKICAgICAgICB2YXIgbWF4X2NvZGUgPSBkZXNjLm1heF9jb2RlOwogICAgICAgIHZhciBzdHJlZSA9IGRlc2Muc3RhdF9kZXNjLnN0YXRpY190cmVlOwogICAgICAgIHZhciBoYXNfc3RyZWUgPSBkZXNjLnN0YXRfZGVzYy5oYXNfc3RyZWU7CiAgICAgICAgdmFyIGV4dHJhID0gZGVzYy5zdGF0X2Rlc2MuZXh0cmFfYml0czsKICAgICAgICB2YXIgYmFzZSA9IGRlc2Muc3RhdF9kZXNjLmV4dHJhX2Jhc2U7CiAgICAgICAgdmFyIG1heF9sZW5ndGggPSBkZXNjLnN0YXRfZGVzYy5tYXhfbGVuZ3RoOwogICAgICAgIHZhciBoOwogICAgICAgIHZhciBuLCBtOwogICAgICAgIHZhciBiaXRzOwogICAgICAgIHZhciB4Yml0czsKICAgICAgICB2YXIgZjsKICAgICAgICB2YXIgb3ZlcmZsb3cgPSAwOwogICAgICAgIGZvciAoYml0cyA9IDA7IGJpdHMgPD0gTUFYX0JJVFM7IGJpdHMrKykgewogICAgICAgICAgcy5ibF9jb3VudFtiaXRzXSA9IDA7CiAgICAgICAgfQogICAgICAgIHRyZWVbcy5oZWFwW3MuaGVhcF9tYXhdICogMiArIDFdID0gMDsKICAgICAgICBmb3IgKGggPSBzLmhlYXBfbWF4ICsgMTsgaCA8IEhFQVBfU0laRTsgaCsrKSB7CiAgICAgICAgICBuID0gcy5oZWFwW2hdOwogICAgICAgICAgYml0cyA9IHRyZWVbdHJlZVtuICogMiArIDFdICogMiArIDFdICsgMTsKICAgICAgICAgIGlmIChiaXRzID4gbWF4X2xlbmd0aCkgewogICAgICAgICAgICBiaXRzID0gbWF4X2xlbmd0aDsKICAgICAgICAgICAgb3ZlcmZsb3crKzsKICAgICAgICAgIH0KICAgICAgICAgIHRyZWVbbiAqIDIgKyAxXSA9IGJpdHM7CiAgICAgICAgICBpZiAobiA+IG1heF9jb2RlKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgcy5ibF9jb3VudFtiaXRzXSsrOwogICAgICAgICAgeGJpdHMgPSAwOwogICAgICAgICAgaWYgKG4gPj0gYmFzZSkgewogICAgICAgICAgICB4Yml0cyA9IGV4dHJhW24gLSBiYXNlXTsKICAgICAgICAgIH0KICAgICAgICAgIGYgPSB0cmVlW24gKiAyXTsKICAgICAgICAgIHMub3B0X2xlbiArPSBmICogKGJpdHMgKyB4Yml0cyk7CiAgICAgICAgICBpZiAoaGFzX3N0cmVlKSB7CiAgICAgICAgICAgIHMuc3RhdGljX2xlbiArPSBmICogKHN0cmVlW24gKiAyICsgMV0gKyB4Yml0cyk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChvdmVyZmxvdyA9PT0gMCkgewogICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KICAgICAgICBkbyB7CiAgICAgICAgICBiaXRzID0gbWF4X2xlbmd0aCAtIDE7CiAgICAgICAgICB3aGlsZSAocy5ibF9jb3VudFtiaXRzXSA9PT0gMCkgewogICAgICAgICAgICBiaXRzLS07CiAgICAgICAgICB9CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHNdLS07CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHMgKyAxXSArPSAyOwogICAgICAgICAgcy5ibF9jb3VudFttYXhfbGVuZ3RoXS0tOwogICAgICAgICAgb3ZlcmZsb3cgLT0gMjsKICAgICAgICB9IHdoaWxlIChvdmVyZmxvdyA+IDApOwogICAgICAgIGZvciAoYml0cyA9IG1heF9sZW5ndGg7IGJpdHMgIT09IDA7IGJpdHMtLSkgewogICAgICAgICAgbiA9IHMuYmxfY291bnRbYml0c107CiAgICAgICAgICB3aGlsZSAobiAhPT0gMCkgewogICAgICAgICAgICBtID0gcy5oZWFwWy0taF07CiAgICAgICAgICAgIGlmIChtID4gbWF4X2NvZGUpIHsKICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodHJlZVttICogMiArIDFdICE9PSBiaXRzKSB7CiAgICAgICAgICAgICAgcy5vcHRfbGVuICs9IChiaXRzIC0gdHJlZVttICogMiArIDFdKSAqIHRyZWVbbSAqIDJdOwogICAgICAgICAgICAgIHRyZWVbbSAqIDIgKyAxXSA9IGJpdHM7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbi0tOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBnZW5fY29kZXModHJlZSwgbWF4X2NvZGUsIGJsX2NvdW50KSB7CiAgICAgICAgdmFyIG5leHRfY29kZSA9IG5ldyBBcnJheShNQVhfQklUUyArIDEpOwogICAgICAgIHZhciBjb2RlID0gMDsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgbjsKICAgICAgICBmb3IgKGJpdHMgPSAxOyBiaXRzIDw9IE1BWF9CSVRTOyBiaXRzKyspIHsKICAgICAgICAgIG5leHRfY29kZVtiaXRzXSA9IGNvZGUgPSBjb2RlICsgYmxfY291bnRbYml0cyAtIDFdIDw8IDE7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPD0gbWF4X2NvZGU7IG4rKykgewogICAgICAgICAgdmFyIGxlbiA9IHRyZWVbbiAqIDIgKyAxXTsKICAgICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICB0cmVlW24gKiAyXSA9IGJpX3JldmVyc2UobmV4dF9jb2RlW2xlbl0rKywgbGVuKTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdHJfc3RhdGljX2luaXQoKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIGxlbmd0aDsKICAgICAgICB2YXIgY29kZTsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgYmxfY291bnQgPSBuZXcgQXJyYXkoTUFYX0JJVFMgKyAxKTsKICAgICAgICBsZW5ndGggPSAwOwogICAgICAgIGZvciAoY29kZSA9IDA7IGNvZGUgPCBMRU5HVEhfQ09ERVMgLSAxOyBjb2RlKyspIHsKICAgICAgICAgIGJhc2VfbGVuZ3RoW2NvZGVdID0gbGVuZ3RoOwogICAgICAgICAgZm9yIChuID0gMDsgbiA8IDEgPDwgZXh0cmFfbGJpdHNbY29kZV07IG4rKykgewogICAgICAgICAgICBfbGVuZ3RoX2NvZGVbbGVuZ3RoKytdID0gY29kZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgX2xlbmd0aF9jb2RlW2xlbmd0aCAtIDFdID0gY29kZTsKICAgICAgICBkaXN0ID0gMDsKICAgICAgICBmb3IgKGNvZGUgPSAwOyBjb2RlIDwgMTY7IGNvZGUrKykgewogICAgICAgICAgYmFzZV9kaXN0W2NvZGVdID0gZGlzdDsKICAgICAgICAgIGZvciAobiA9IDA7IG4gPCAxIDw8IGV4dHJhX2RiaXRzW2NvZGVdOyBuKyspIHsKICAgICAgICAgICAgX2Rpc3RfY29kZVtkaXN0KytdID0gY29kZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZGlzdCA+Pj0gNzsKICAgICAgICBmb3IgKDsgY29kZSA8IERfQ09ERVM7IGNvZGUrKykgewogICAgICAgICAgYmFzZV9kaXN0W2NvZGVdID0gZGlzdCA8PCA3OwogICAgICAgICAgZm9yIChuID0gMDsgbiA8IDEgPDwgZXh0cmFfZGJpdHNbY29kZV0gLSA3OyBuKyspIHsKICAgICAgICAgICAgX2Rpc3RfY29kZVsyNTYgKyBkaXN0KytdID0gY29kZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZm9yIChiaXRzID0gMDsgYml0cyA8PSBNQVhfQklUUzsgYml0cysrKSB7CiAgICAgICAgICBibF9jb3VudFtiaXRzXSA9IDA7CiAgICAgICAgfQogICAgICAgIG4gPSAwOwogICAgICAgIHdoaWxlIChuIDw9IDE0MykgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA4OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbOF0rKzsKICAgICAgICB9CiAgICAgICAgd2hpbGUgKG4gPD0gMjU1KSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDk7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs5XSsrOwogICAgICAgIH0KICAgICAgICB3aGlsZSAobiA8PSAyNzkpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gNzsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzddKys7CiAgICAgICAgfQogICAgICAgIHdoaWxlIChuIDw9IDI4NykgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA4OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbOF0rKzsKICAgICAgICB9CiAgICAgICAgZ2VuX2NvZGVzKHN0YXRpY19sdHJlZSwgTF9DT0RFUyArIDEsIGJsX2NvdW50KTsKICAgICAgICBmb3IgKG4gPSAwOyBuIDwgRF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzdGF0aWNfZHRyZWVbbiAqIDIgKyAxXSA9IDU7CiAgICAgICAgICBzdGF0aWNfZHRyZWVbbiAqIDJdID0gYmlfcmV2ZXJzZShuLCA1KTsKICAgICAgICB9CiAgICAgICAgc3RhdGljX2xfZGVzYyA9IG5ldyBTdGF0aWNUcmVlRGVzYyhzdGF0aWNfbHRyZWUsIGV4dHJhX2xiaXRzLCBMSVRFUkFMUyArIDEsIExfQ09ERVMsIE1BWF9CSVRTKTsKICAgICAgICBzdGF0aWNfZF9kZXNjID0gbmV3IFN0YXRpY1RyZWVEZXNjKHN0YXRpY19kdHJlZSwgZXh0cmFfZGJpdHMsIDAsIERfQ09ERVMsIE1BWF9CSVRTKTsKICAgICAgICBzdGF0aWNfYmxfZGVzYyA9IG5ldyBTdGF0aWNUcmVlRGVzYyhuZXcgQXJyYXkoMCksIGV4dHJhX2JsYml0cywgMCwgQkxfQ09ERVMsIE1BWF9CTF9CSVRTKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbml0X2Jsb2NrKHMpIHsKICAgICAgICB2YXIgbjsKICAgICAgICBmb3IgKG4gPSAwOyBuIDwgTF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzLmR5bl9sdHJlZVtuICogMl0gPSAwOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDwgRF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzLmR5bl9kdHJlZVtuICogMl0gPSAwOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDwgQkxfQ09ERVM7IG4rKykgewogICAgICAgICAgcy5ibF90cmVlW24gKiAyXSA9IDA7CiAgICAgICAgfQogICAgICAgIHMuZHluX2x0cmVlW0VORF9CTE9DSyAqIDJdID0gMTsKICAgICAgICBzLm9wdF9sZW4gPSBzLnN0YXRpY19sZW4gPSAwOwogICAgICAgIHMubGFzdF9saXQgPSBzLm1hdGNoZXMgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJpX3dpbmR1cChzKSB7CiAgICAgICAgaWYgKHMuYmlfdmFsaWQgPiA4KSB7CiAgICAgICAgICBwdXRfc2hvcnQocywgcy5iaV9idWYpOwogICAgICAgIH0gZWxzZSBpZiAocy5iaV92YWxpZCA+IDApIHsKICAgICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gcy5iaV9idWY7CiAgICAgICAgfQogICAgICAgIHMuYmlfYnVmID0gMDsKICAgICAgICBzLmJpX3ZhbGlkID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBjb3B5X2Jsb2NrKHMsIGJ1ZiwgbGVuLCBoZWFkZXIpIHsKICAgICAgICBiaV93aW5kdXAocyk7CiAgICAgICAgaWYgKGhlYWRlcikgewogICAgICAgICAgcHV0X3Nob3J0KHMsIGxlbik7CiAgICAgICAgICBwdXRfc2hvcnQocywgfmxlbik7CiAgICAgICAgfQogICAgICAgIHV0aWxzLmFycmF5U2V0KHMucGVuZGluZ19idWYsIHMud2luZG93LCBidWYsIGxlbiwgcy5wZW5kaW5nKTsKICAgICAgICBzLnBlbmRpbmcgKz0gbGVuOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNtYWxsZXIodHJlZSwgbiwgbSwgZGVwdGgpIHsKICAgICAgICB2YXIgX24yID0gbiAqIDI7CiAgICAgICAgdmFyIF9tMiA9IG0gKiAyOwogICAgICAgIHJldHVybiB0cmVlW19uMl0gPCB0cmVlW19tMl0gfHwgdHJlZVtfbjJdID09PSB0cmVlW19tMl0gJiYgZGVwdGhbbl0gPD0gZGVwdGhbbV07CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcHFkb3duaGVhcChzLCB0cmVlLCBrKSB7CiAgICAgICAgdmFyIHYgPSBzLmhlYXBba107CiAgICAgICAgdmFyIGogPSBrIDw8IDE7CiAgICAgICAgd2hpbGUgKGogPD0gcy5oZWFwX2xlbikgewogICAgICAgICAgaWYgKGogPCBzLmhlYXBfbGVuICYmIHNtYWxsZXIodHJlZSwgcy5oZWFwW2ogKyAxXSwgcy5oZWFwW2pdLCBzLmRlcHRoKSkgewogICAgICAgICAgICBqKys7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc21hbGxlcih0cmVlLCB2LCBzLmhlYXBbal0sIHMuZGVwdGgpKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgcy5oZWFwW2tdID0gcy5oZWFwW2pdOwogICAgICAgICAgayA9IGo7CiAgICAgICAgICBqIDw8PSAxOwogICAgICAgIH0KICAgICAgICBzLmhlYXBba10gPSB2OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGNvbXByZXNzX2Jsb2NrKHMsIGx0cmVlLCBkdHJlZSkgewogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBsYzsKICAgICAgICB2YXIgbHggPSAwOwogICAgICAgIHZhciBjb2RlOwogICAgICAgIHZhciBleHRyYTsKICAgICAgICBpZiAocy5sYXN0X2xpdCAhPT0gMCkgewogICAgICAgICAgZG8gewogICAgICAgICAgICBkaXN0ID0gcy5wZW5kaW5nX2J1ZltzLmRfYnVmICsgbHggKiAyXSA8PCA4IHwgcy5wZW5kaW5nX2J1ZltzLmRfYnVmICsgbHggKiAyICsgMV07CiAgICAgICAgICAgIGxjID0gcy5wZW5kaW5nX2J1ZltzLmxfYnVmICsgbHhdOwogICAgICAgICAgICBseCsrOwogICAgICAgICAgICBpZiAoZGlzdCA9PT0gMCkgewogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBsYywgbHRyZWUpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGNvZGUgPSBfbGVuZ3RoX2NvZGVbbGNdOwogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjb2RlICsgTElURVJBTFMgKyAxLCBsdHJlZSk7CiAgICAgICAgICAgICAgZXh0cmEgPSBleHRyYV9sYml0c1tjb2RlXTsKICAgICAgICAgICAgICBpZiAoZXh0cmEgIT09IDApIHsKICAgICAgICAgICAgICAgIGxjIC09IGJhc2VfbGVuZ3RoW2NvZGVdOwogICAgICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGxjLCBleHRyYSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGRpc3QtLTsKICAgICAgICAgICAgICBjb2RlID0gZF9jb2RlKGRpc3QpOwogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjb2RlLCBkdHJlZSk7CiAgICAgICAgICAgICAgZXh0cmEgPSBleHRyYV9kYml0c1tjb2RlXTsKICAgICAgICAgICAgICBpZiAoZXh0cmEgIT09IDApIHsKICAgICAgICAgICAgICAgIGRpc3QgLT0gYmFzZV9kaXN0W2NvZGVdOwogICAgICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGRpc3QsIGV4dHJhKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gd2hpbGUgKGx4IDwgcy5sYXN0X2xpdCk7CiAgICAgICAgfQogICAgICAgIHNlbmRfY29kZShzLCBFTkRfQkxPQ0ssIGx0cmVlKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBidWlsZF90cmVlKHMsIGRlc2MpIHsKICAgICAgICB2YXIgdHJlZSA9IGRlc2MuZHluX3RyZWU7CiAgICAgICAgdmFyIHN0cmVlID0gZGVzYy5zdGF0X2Rlc2Muc3RhdGljX3RyZWU7CiAgICAgICAgdmFyIGhhc19zdHJlZSA9IGRlc2Muc3RhdF9kZXNjLmhhc19zdHJlZTsKICAgICAgICB2YXIgZWxlbXMgPSBkZXNjLnN0YXRfZGVzYy5lbGVtczsKICAgICAgICB2YXIgbiwgbTsKICAgICAgICB2YXIgbWF4X2NvZGUgPSAtMTsKICAgICAgICB2YXIgbm9kZTsKICAgICAgICBzLmhlYXBfbGVuID0gMDsKICAgICAgICBzLmhlYXBfbWF4ID0gSEVBUF9TSVpFOwogICAgICAgIGZvciAobiA9IDA7IG4gPCBlbGVtczsgbisrKSB7CiAgICAgICAgICBpZiAodHJlZVtuICogMl0gIT09IDApIHsKICAgICAgICAgICAgcy5oZWFwWysrcy5oZWFwX2xlbl0gPSBtYXhfY29kZSA9IG47CiAgICAgICAgICAgIHMuZGVwdGhbbl0gPSAwOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdHJlZVtuICogMiArIDFdID0gMDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgd2hpbGUgKHMuaGVhcF9sZW4gPCAyKSB7CiAgICAgICAgICBub2RlID0gcy5oZWFwWysrcy5oZWFwX2xlbl0gPSBtYXhfY29kZSA8IDIgPyArK21heF9jb2RlIDogMDsKICAgICAgICAgIHRyZWVbbm9kZSAqIDJdID0gMTsKICAgICAgICAgIHMuZGVwdGhbbm9kZV0gPSAwOwogICAgICAgICAgcy5vcHRfbGVuLS07CiAgICAgICAgICBpZiAoaGFzX3N0cmVlKSB7CiAgICAgICAgICAgIHMuc3RhdGljX2xlbiAtPSBzdHJlZVtub2RlICogMiArIDFdOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBkZXNjLm1heF9jb2RlID0gbWF4X2NvZGU7CiAgICAgICAgZm9yIChuID0gcy5oZWFwX2xlbiA+PiAxOyBuID49IDE7IG4tLSkgewogICAgICAgICAgcHFkb3duaGVhcChzLCB0cmVlLCBuKTsKICAgICAgICB9CiAgICAgICAgbm9kZSA9IGVsZW1zOwogICAgICAgIGRvIHsKICAgICAgICAgIG4gPSBzLmhlYXBbMV07CiAgICAgICAgICBzLmhlYXBbMV0gPSBzLmhlYXBbcy5oZWFwX2xlbi0tXTsKICAgICAgICAgIHBxZG93bmhlYXAocywgdHJlZSwgMSk7CiAgICAgICAgICBtID0gcy5oZWFwWzFdOwogICAgICAgICAgcy5oZWFwWy0tcy5oZWFwX21heF0gPSBuOwogICAgICAgICAgcy5oZWFwWy0tcy5oZWFwX21heF0gPSBtOwogICAgICAgICAgdHJlZVtub2RlICogMl0gPSB0cmVlW24gKiAyXSArIHRyZWVbbSAqIDJdOwogICAgICAgICAgcy5kZXB0aFtub2RlXSA9IChzLmRlcHRoW25dID49IHMuZGVwdGhbbV0gPyBzLmRlcHRoW25dIDogcy5kZXB0aFttXSkgKyAxOwogICAgICAgICAgdHJlZVtuICogMiArIDFdID0gdHJlZVttICogMiArIDFdID0gbm9kZTsKICAgICAgICAgIHMuaGVhcFsxXSA9IG5vZGUrKzsKICAgICAgICAgIHBxZG93bmhlYXAocywgdHJlZSwgMSk7CiAgICAgICAgfSB3aGlsZSAocy5oZWFwX2xlbiA+PSAyKTsKICAgICAgICBzLmhlYXBbLS1zLmhlYXBfbWF4XSA9IHMuaGVhcFsxXTsKICAgICAgICBnZW5fYml0bGVuKHMsIGRlc2MpOwogICAgICAgIGdlbl9jb2Rlcyh0cmVlLCBtYXhfY29kZSwgcy5ibF9jb3VudCk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2Nhbl90cmVlKHMsIHRyZWUsIG1heF9jb2RlKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIHByZXZsZW4gPSAtMTsKICAgICAgICB2YXIgY3VybGVuOwogICAgICAgIHZhciBuZXh0bGVuID0gdHJlZVswICogMiArIDFdOwogICAgICAgIHZhciBjb3VudCA9IDA7CiAgICAgICAgdmFyIG1heF9jb3VudCA9IDc7CiAgICAgICAgdmFyIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgfQogICAgICAgIHRyZWVbKG1heF9jb2RlICsgMSkgKiAyICsgMV0gPSA2NTUzNTsKICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IG1heF9jb2RlOyBuKyspIHsKICAgICAgICAgIGN1cmxlbiA9IG5leHRsZW47CiAgICAgICAgICBuZXh0bGVuID0gdHJlZVsobiArIDEpICogMiArIDFdOwogICAgICAgICAgaWYgKCsrY291bnQgPCBtYXhfY291bnQgJiYgY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8IG1pbl9jb3VudCkgewogICAgICAgICAgICBzLmJsX3RyZWVbY3VybGVuICogMl0gKz0gY291bnQ7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiAhPT0gMCkgewogICAgICAgICAgICBpZiAoY3VybGVuICE9PSBwcmV2bGVuKSB7CiAgICAgICAgICAgICAgcy5ibF90cmVlW2N1cmxlbiAqIDJdKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcy5ibF90cmVlW1JFUF8zXzYgKiAyXSsrOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8PSAxMCkgewogICAgICAgICAgICBzLmJsX3RyZWVbUkVQWl8zXzEwICogMl0rKzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuYmxfdHJlZVtSRVBaXzExXzEzOCAqIDJdKys7CiAgICAgICAgICB9CiAgICAgICAgICBjb3VudCA9IDA7CiAgICAgICAgICBwcmV2bGVuID0gY3VybGVuOwogICAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNjsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDc7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNlbmRfdHJlZShzLCB0cmVlLCBtYXhfY29kZSkgewogICAgICAgIHZhciBuOwogICAgICAgIHZhciBwcmV2bGVuID0gLTE7CiAgICAgICAgdmFyIGN1cmxlbjsKICAgICAgICB2YXIgbmV4dGxlbiA9IHRyZWVbMCAqIDIgKyAxXTsKICAgICAgICB2YXIgY291bnQgPSAwOwogICAgICAgIHZhciBtYXhfY291bnQgPSA3OwogICAgICAgIHZhciBtaW5fY291bnQgPSA0OwogICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IG1heF9jb2RlOyBuKyspIHsKICAgICAgICAgIGN1cmxlbiA9IG5leHRsZW47CiAgICAgICAgICBuZXh0bGVuID0gdHJlZVsobiArIDEpICogMiArIDFdOwogICAgICAgICAgaWYgKCsrY291bnQgPCBtYXhfY291bnQgJiYgY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8IG1pbl9jb3VudCkgewogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGN1cmxlbiwgcy5ibF90cmVlKTsKICAgICAgICAgICAgfSB3aGlsZSAoLS1jb3VudCAhPT0gMCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiAhPT0gMCkgewogICAgICAgICAgICBpZiAoY3VybGVuICE9PSBwcmV2bGVuKSB7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGN1cmxlbiwgcy5ibF90cmVlKTsKICAgICAgICAgICAgICBjb3VudC0tOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHNlbmRfY29kZShzLCBSRVBfM182LCBzLmJsX3RyZWUpOwogICAgICAgICAgICBzZW5kX2JpdHMocywgY291bnQgLSAzLCAyKTsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPD0gMTApIHsKICAgICAgICAgICAgc2VuZF9jb2RlKHMsIFJFUFpfM18xMCwgcy5ibF90cmVlKTsKICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGNvdW50IC0gMywgMyk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzZW5kX2NvZGUocywgUkVQWl8xMV8xMzgsIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIHNlbmRfYml0cyhzLCBjb3VudCAtIDExLCA3KTsKICAgICAgICAgIH0KICAgICAgICAgIGNvdW50ID0gMDsKICAgICAgICAgIHByZXZsZW4gPSBjdXJsZW47CiAgICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBtYXhfY291bnQgPSA2OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNzsKICAgICAgICAgICAgbWluX2NvdW50ID0gNDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYnVpbGRfYmxfdHJlZShzKSB7CiAgICAgICAgdmFyIG1heF9ibGluZGV4OwogICAgICAgIHNjYW5fdHJlZShzLCBzLmR5bl9sdHJlZSwgcy5sX2Rlc2MubWF4X2NvZGUpOwogICAgICAgIHNjYW5fdHJlZShzLCBzLmR5bl9kdHJlZSwgcy5kX2Rlc2MubWF4X2NvZGUpOwogICAgICAgIGJ1aWxkX3RyZWUocywgcy5ibF9kZXNjKTsKICAgICAgICBmb3IgKG1heF9ibGluZGV4ID0gQkxfQ09ERVMgLSAxOyBtYXhfYmxpbmRleCA+PSAzOyBtYXhfYmxpbmRleC0tKSB7CiAgICAgICAgICBpZiAocy5ibF90cmVlW2JsX29yZGVyW21heF9ibGluZGV4XSAqIDIgKyAxXSAhPT0gMCkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5vcHRfbGVuICs9IDMgKiAobWF4X2JsaW5kZXggKyAxKSArIDUgKyA1ICsgNDsKICAgICAgICByZXR1cm4gbWF4X2JsaW5kZXg7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2VuZF9hbGxfdHJlZXMocywgbGNvZGVzLCBkY29kZXMsIGJsY29kZXMpIHsKICAgICAgICB2YXIgcmFuazsKICAgICAgICBzZW5kX2JpdHMocywgbGNvZGVzIC0gMjU3LCA1KTsKICAgICAgICBzZW5kX2JpdHMocywgZGNvZGVzIC0gMSwgNSk7CiAgICAgICAgc2VuZF9iaXRzKHMsIGJsY29kZXMgLSA0LCA0KTsKICAgICAgICBmb3IgKHJhbmsgPSAwOyByYW5rIDwgYmxjb2RlczsgcmFuaysrKSB7CiAgICAgICAgICBzZW5kX2JpdHMocywgcy5ibF90cmVlW2JsX29yZGVyW3JhbmtdICogMiArIDFdLCAzKTsKICAgICAgICB9CiAgICAgICAgc2VuZF90cmVlKHMsIHMuZHluX2x0cmVlLCBsY29kZXMgLSAxKTsKICAgICAgICBzZW5kX3RyZWUocywgcy5keW5fZHRyZWUsIGRjb2RlcyAtIDEpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRldGVjdF9kYXRhX3R5cGUocykgewogICAgICAgIHZhciBibGFja19tYXNrID0gNDA5MzYyNDQ0NzsKICAgICAgICB2YXIgbjsKICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IDMxOyBuKyssIGJsYWNrX21hc2sgPj4+PSAxKSB7CiAgICAgICAgICBpZiAoYmxhY2tfbWFzayAmIDEgJiYgcy5keW5fbHRyZWVbbiAqIDJdICE9PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBaX0JJTkFSWTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuZHluX2x0cmVlWzkgKiAyXSAhPT0gMCB8fCBzLmR5bl9sdHJlZVsxMCAqIDJdICE9PSAwIHx8IHMuZHluX2x0cmVlWzEzICogMl0gIT09IDApIHsKICAgICAgICAgIHJldHVybiBaX1RFWFQ7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDMyOyBuIDwgTElURVJBTFM7IG4rKykgewogICAgICAgICAgaWYgKHMuZHluX2x0cmVlW24gKiAyXSAhPT0gMCkgewogICAgICAgICAgICByZXR1cm4gWl9URVhUOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gWl9CSU5BUlk7CiAgICAgIH0KICAgICAgdmFyIHN0YXRpY19pbml0X2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IgbWF4X2JsaW5kZXggPSAwOwogICAgICAgIGlmIChzLmxldmVsID4gMCkgewogICAgICAgICAgaWYgKHMuc3RybS5kYXRhX3R5cGUgPT09IFpfVU5LTk9XTikgewogICAgICAgICAgICBzLnN0cm0uZGF0YV90eXBlID0gZGV0ZWN0X2RhdGFfdHlwZShzKTsKICAgICAgICAgIH0KICAgICAgICAgIGJ1aWxkX3RyZWUocywgcy5sX2Rlc2MpOwogICAgICAgICAgYnVpbGRfdHJlZShzLCBzLmRfZGVzYyk7CiAgICAgICAgICBtYXhfYmxpbmRleCA9IGJ1aWxkX2JsX3RyZWUocyk7CiAgICAgICAgICBvcHRfbGVuYiA9IHMub3B0X2xlbiArIDMgKyA3ID4+PiAzOwogICAgICAgICAgc3RhdGljX2xlbmIgPSBzLnN0YXRpY19sZW4gKyAzICsgNyA+Pj4gMzsKICAgICAgICAgIGlmIChzdGF0aWNfbGVuYiA8PSBvcHRfbGVuYikgewogICAgICAgICAgICBvcHRfbGVuYiA9IHN0YXRpY19sZW5iOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBvcHRfbGVuYiA9IHN0YXRpY19sZW5iID0gc3RvcmVkX2xlbiArIDU7CiAgICAgICAgfQogICAgICAgIGlmIChzdG9yZWRfbGVuICsgNCA8PSBvcHRfbGVuYiAmJiBidWYgIT09IC0xKSB7CiAgICAgICAgICBfdHJfc3RvcmVkX2Jsb2NrKHMsIGJ1Ziwgc3RvcmVkX2xlbiwgbGFzdCk7CiAgICAgICAgfSBlbHNlIGlmIChzLnN0cmF0ZWd5ID09PSBaX0ZJWEVEIHx8IHN0YXRpY19sZW5iID09PSBvcHRfbGVuYikgewogICAgICAgICAgc2VuZF9iaXRzKHMsIChTVEFUSUNfVFJFRVMgPDwgMSkgKyAobGFzdCA/IDEgOiAwKSwgMyk7CiAgICAgICAgICBjb21wcmVzc19ibG9jayhzLCBzdGF0aWNfbHRyZWUsIHN0YXRpY19kdHJlZSk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHNlbmRfYml0cyhzLCAoRFlOX1RSRUVTIDw8IDEpICsgKGxhc3QgPyAxIDogMCksIDMpOwogICAgICAgICAgc2VuZF9hbGxfdHJlZXMocywgcy5sX2Rlc2MubWF4X2NvZGUgKyAxLCBzLmRfZGVzYy5tYXhfY29kZSArIDEsIG1heF9ibGluZGV4ICsgMSk7CiAgICAgICAgICBjb21wcmVzc19ibG9jayhzLCBzLmR5bl9sdHJlZSwgcy5keW5fZHRyZWUpOwogICAgICAgIH0KICAgICAgICBpbml0X2Jsb2NrKHMpOwogICAgICAgIGlmIChsYXN0KSB7CiAgICAgICAgICBiaV93aW5kdXAocyk7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIF90cl90YWxseShzLCBkaXN0LCBsYykgewogICAgICAgIHMucGVuZGluZ19idWZbcy5kX2J1ZiArIHMubGFzdF9saXQgKiAyXSA9IGRpc3QgPj4+IDggJiAyNTU7CiAgICAgICAgcy5wZW5kaW5nX2J1ZltzLmRfYnVmICsgcy5sYXN0X2xpdCAqIDIgKyAxXSA9IGRpc3QgJiAyNTU7CiAgICAgICAgcy5wZW5kaW5nX2J1ZltzLmxfYnVmICsgcy5sYXN0X2xpdF0gPSBsYyAmIDI1NTsKICAgICAgICBzLmxhc3RfbGl0Kys7CiAgICAgICAgaWYgKGRpc3QgPT09IDApIHsKICAgICAgICAgIHMuZHluX2x0cmVlW2xjICogMl0rKzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgcy5tYXRjaGVzKys7CiAgICAgICAgICBkaXN0LS07CiAgICAgICAgICBzLmR5bl9sdHJlZVsoX2xlbmd0aF9jb2RlW2xjXSArIExJVEVSQUxTICsgMSkgKiAyXSsrOwogICAgICAgICAgcy5keW5fZHRyZWVbZF9jb2RlKGRpc3QpICogMl0rKzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHMubGFzdF9saXQgPT09IHMubGl0X2J1ZnNpemUgLSAxOwogICAgICB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CiAgICAgICAgfQogICAgICAgIHJldHVybiBzMSB8IHMyIDw8IDE2IHwgMDsKICAgICAgfQogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBhZGxlcjMyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvY3JjMzIuanMKICB2YXIgcmVxdWlyZV9jcmMzMiA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9jcmMzMi5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIGZ1bmN0aW9uIG1ha2VUYWJsZSgpIHsKICAgICAgICB2YXIgYywgdGFibGUgPSBbXTsKICAgICAgICBmb3IgKHZhciBuID0gMDsgbiA8IDI1NjsgbisrKSB7CiAgICAgICAgICBjID0gbjsKICAgICAgICAgIGZvciAodmFyIGsgPSAwOyBrIDwgODsgaysrKSB7CiAgICAgICAgICAgIGMgPSBjICYgMSA/IDM5ODgyOTIzODQgXiBjID4+PiAxIDogYyA+Pj4gMTsKICAgICAgICAgIH0KICAgICAgICAgIHRhYmxlW25dID0gYzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRhYmxlOwogICAgICB9CiAgICAgIHZhciBjcmNUYWJsZSA9IG1ha2VUYWJsZSgpOwogICAgICBmdW5jdGlvbiBjcmMzMihjcmMsIGJ1ZiwgbGVuLCBwb3MpIHsKICAgICAgICB2YXIgdCA9IGNyY1RhYmxlLCBlbmQgPSBwb3MgKyBsZW47CiAgICAgICAgY3JjIF49IC0xOwogICAgICAgIGZvciAodmFyIGkgPSBwb3M7IGkgPCBlbmQ7IGkrKykgewogICAgICAgICAgY3JjID0gY3JjID4+PiA4IF4gdFsoY3JjIF4gYnVmW2ldKSAmIDI1NV07CiAgICAgICAgfQogICAgICAgIHJldHVybiBjcmMgXiAtMTsKICAgICAgfQogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBjcmMzMjsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL21lc3NhZ2VzLmpzCiAgdmFyIHJlcXVpcmVfbWVzc2FnZXMgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvbWVzc2FnZXMuanMiKGV4cG9ydHMyLCBtb2R1bGUyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSB7CiAgICAgICAgMjogIm5lZWQgZGljdGlvbmFyeSIsCiAgICAgICAgMTogInN0cmVhbSBlbmQiLAogICAgICAgIDA6ICIiLAogICAgICAgICItMSI6ICJmaWxlIGVycm9yIiwKICAgICAgICAiLTIiOiAic3RyZWFtIGVycm9yIiwKICAgICAgICAiLTMiOiAiZGF0YSBlcnJvciIsCiAgICAgICAgIi00IjogImluc3VmZmljaWVudCBtZW1vcnkiLAogICAgICAgICItNSI6ICJidWZmZXIgZXJyb3IiLAogICAgICAgICItNiI6ICJpbmNvbXBhdGlibGUgdmVyc2lvbiIKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2RlZmxhdGUuanMKICB2YXIgcmVxdWlyZV9kZWZsYXRlID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2RlZmxhd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gPyA5IDogMCk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gemVybyhidWYpIHsKICAgICAgICB2YXIgbGVuID0gYnVmLmxlbmd0aDsKICAgICAgICB3aGlsZSAoLS1sZW4gPj0gMCkgewogICAgICAgICAgYnVmW2xlbl0gPSAwOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBmbHVzaF9wZW5kaW5nKHN0cm0pIHsKICAgICAgICB2YXIgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgdmFyIGxlbiA9IHMucGVuZGluZzsKICAgICAgICBpZiAobGVuID4gc3RybS5hdmFpbF9vdXQpIHsKICAgICAgICAgIGxlbiA9IHN0cm0uYXZhaWxfb3V0OwogICAgICAgIH0KICAgICAgICBpZiAobGVuID09PSAwKSB7CiAgICAgICAgICByZXR1cm47CiAgICAgICAgfQogICAgICAgIHV0aWxzLmFycmF5U2V0KHN0cm0ub3V0cHV0LCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmdfb3V0LCBsZW4sIHN0cm0ubmV4dF9vdXQpOwogICAgICAgIHN0cm0ubmV4dF9vdXQgKz0gbGVuOwogICAgICAgIHMucGVuZGluZ19vdXQgKz0gbGVuOwogICAgICAgIHN0cm0udG90YWxfb3V0ICs9IGxlbjsKICAgICAgICBzdHJtLmF2YWlsX291dCAtPSBsZW47CiAgICAgICAgcy5wZW5kaW5nIC09IGxlbjsKICAgICAgICBpZiAocy5wZW5kaW5nID09PSAwKSB7CiAgICAgICAgICBzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZmx1c2hfYmxvY2tfb25seShzLCBsYXN0KSB7CiAgICAgICAgdHJlZXMuX3RyX2ZsdXNoX2Jsb2NrKHMsIHMuYmxvY2tfc3RhcnQgPj0gMCA/IHMuYmxvY2tfc3RhcnQgOiAtMSwgcy5zdHJzdGFydCAtIHMuYmxvY2tfc3RhcnQsIGxhc3QpOwogICAgICAgIHMuYm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9IGxlbjsKICAgICAgICByZXR1cm4gbGVuOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGxvbmdlc3RfbWF0Y2gocywgY3VyX21hdGNoKSB7CiAgICAgICAgdmFyIGNoYWluX2xlbmd0aCA9IHMubWF4X2NoYWluX2xlbmd0aDsKICAgICAgICB2YXIgc2NhbiA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgdmFyIG1hdGNoOwogICAgICAgIHZhciBsZW47CiAgICAgICAgdmFyIGJlc3RfbGVuID0gcy5wcmV2X2xlbmd0aDsKICAgICAgICB2YXIgbmljZV9tYXRjaCA9IHMubmljZV9tYXRjaDsKICAgICAgICB2YXIgbGltaXQgPSBzLnN0cnN0YXJ0ID4gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEID8gcy5zdHJzdGFydCAtIChzLndfc2l6ZSAtIE1JTl9MT09LQUhFQUQpIDogMDsKICAgICAgICB2YXIgX3dpbiA9IHMud2luZG93OwogICAgICAgIHZhciB3bWFzayA9IHMud19tYXNrOwogICAgICAgIHZhciBwcmV2ID0gcy5wcmV2OwogICAgICAgIHZhciBzdHJlbmQgPSBzLnN0cnN0YXJ0ICsgTUFYX01BVENIOwogICAgICAgIHZhciBzY2FuX2VuZDEgPSBfd2luW3NjYW4gKyBiZXN0X2xlbiAtIDFdOwogICAgICAgIHZhciBzY2FuX2VuZCA9IF93aW5bc2NhbiArIGJlc3RfbGVuXTsKICAgICAgICBpZiAocy5wcmV2X2xlbmd0aCA+PSBzLmdvb2RfbWF0Y2gpIHsKICAgICAgICAgIGNoYWluX2xlbmd0aCA+Pj0gMjsKICAgICAgICB9CiAgICAgICAgaWYgKG5pY2VfbWF0Y2ggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgbmljZV9tYXRjaCA9IHMubG9va2FoZWFkOwogICAgICAgIH0KICAgICAgICBkbyB7CiAgICAgICAgICBtYXRjaCA9IGN1cl9tYXRjaDsKICAgICAgICAgIGlmIChfd2luW21hdGNoICsgYmVzdF9sZW5dICE9PSBzY2FuX2VuZCB8fCBfd2luW21hdGNoICsgYmVzdF9sZW4gLSAxXSAhPT0gc2Nhbl9lbmQxIHx8IF93aW5bbWF0Y2hdICE9PSBfd2luW3NjYW5dIHx8IF93aW5bKyttYXRjaF0gIT09IF93aW5bc2NhbiArIDFdKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgc2NhbiArPSAyOwogICAgICAgICAgbWF0Y2grKzsKICAgICAgICAgIGRvIHsKICAgICAgICAgIH0gd2hpbGUgKF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgc2NhbiA8IHN0cmVuZCk7CiAgICAgICAgICBsZW4gPSBNQVhfTUFUQ0ggLSAoc3RyZW5kIC0gc2Nhbik7CiAgICAgICAgICBzY2FuID0gc3RyZW5kIC0gTUFYX01BVENIOwogICAgICAgICAgaWYgKGxlbiA+IGJlc3RfbGVuKSB7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgPSBjdXJfbWF0Y2g7CiAgICAgICAgICAgIGJlc3RfbGVuID0gbGVuOwogICAgICAgICAgICBpZiAobGVuID49IG5pY2VfbWF0Y2gpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBzY2FuX2VuZDEgPSBfd2luW3NjYW4gKyBiZXN0X2xlbiAtIDFdOwogICAgICAgICAgICBzY2FuX2VuZCA9IF93aW5bc2NhbiArIGJlc3RfbGVuXTsKICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlICgoY3VyX21hdGNoID0gcHJldltjdXJfbWF0Y2ggJiB3bWFza10pID4gbGltaXQgJiYgLS1jaGFpbl9sZW5ndGggIT09IDApOwogICAgICAgIGlmIChiZXN0X2xlbiA8PSBzLmxvb2thaGVhZCkgewogICAgICAgICAgcmV0dXJuIGJlc3RfbGVuOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcy5sb29rYWhlYWQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZmlsbF93aW5kb3cocykgewogICAgICAgIHZhciBfd19zaXplID0gcy53X3NpemU7CiAgICAgICAgdmFyIHAsIG4sIG0sIG1vcmUsIHN0cjsKICAgICAgICBkbyB7CiAgICAgICAgICBtb3JlID0gcy53aW5kb3dfc2l6ZSAtIHMubG9va2FoZWFkIC0gcy5zdHJzdGFydDsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID49IF93X3NpemUgKyAoX3dfc2l6ZSAtIE1JTl9MT09LQUhFQUQpKSB7CiAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHMud2luZG93LCBzLndpbmRvdywgX3dfc2l6ZSwgX3dfc2l6ZSwgMCk7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgLT0gX3dfc2l6ZTsKICAgICAgICAgICAgcy5zdHJzdGFydCAtPSBfd19zaXplOwogICAgICAgICAgICBzLmJsb2NrX3N0YXJ0IC09IF93X3NpemU7CiAgICAgICAgICAgIG4gPSBzLmhhc2hfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5oZWFkWy0tcF07CiAgICAgICAgICAgICAgcy5oZWFkW3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBuID0gX3dfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5wcmV2Wy0tcF07CiAgICAgICAgICAgICAgcy5wcmV2W3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBtb3JlICs9IF93X3NpemU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX2luID09PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgbiA9IHJlYWRfYnVmKHMuc3RybSwgcy53aW5kb3csIHMuc3Ryc3RhcnQgKyBzLmxvb2thaGVhZCwgbW9yZSk7CiAgICAgICAgICBzLmxvb2thaGVhZCArPSBuOwogICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHN0ciA9IHMuc3Ryc3RhcnQgLSBzLmluc2VydDsKICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3N0cl07CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgd2hpbGUgKHMuaW5zZXJ0KSB7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3N0ciArIE1JTl9NQVRDSCAtIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gc3RyOwogICAgICAgICAgICAgIHN0cisrOwogICAgICAgICAgICAgIHMuaW5zZXJ0LS07CiAgICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPCBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBzLnN0cm0uYXZhaWxfaW4gIT09IDApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfc3RvcmVkKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIG1heF9ibG9ja19zaXplID0gNjU1MzU7CiAgICAgICAgaWYgKG1heF9ibG9ja19zaXplID4gcy5wZW5kaW5nX2J1Zl9zaXplIC0gNSkgewogICAgICAgICAgbWF4X2Jsb2NrX3NpemUgPSBzLnBlbmRpbmdfYnVmX3NpemUgLSA1OwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSAxKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDAgJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubG9va2FoZWFkOwogICAgICAgICAgcy5sb29rYWhlYWQgPSAwOwogICAgICAgICAgdmFyIG1heF9zdGFydCA9IHMuYmxvY2tfc3RhcnQgKyBtYXhfYmxvY2tfc2l6ZTsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID09PSAwIHx8IHMuc3Ryc3RhcnQgPj0gbWF4X3N0YXJ0KSB7CiAgICAgICAgICAgIHMubG9va2FoZWFkID0gcy5zdHJzdGFydCAtIG1heF9zdGFydDsKICAgICAgICAgICAgcy5zdHJzdGFydCA9IG1heF9zdGFydDsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgLSBzLmJsb2NrX3N0YXJ0ID49IHMud19zaXplIC0gTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5zdHJzdGFydCA+IHMuYmxvY2tfc3RhcnQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX2Zhc3QocywgZmx1c2gpIHsKICAgICAgICB2YXIgaGFzaF9oZWFkOwogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEICYmIGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaGFzaF9oZWFkID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgaGFzaF9oZWFkID0gcy5wcmV2W3Muc3Ryc3RhcnQgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaGFzaF9oZWFkICE9PSAwICYmIHMuc3Ryc3RhcnQgLSBoYXNoX2hlYWQgPD0gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gbG9uZ2VzdF9tYXRjaChzLCBoYXNoX2hlYWQpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHMubWF0Y2hfbGVuZ3RoID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgcy5zdHJzdGFydCAtIHMubWF0Y2hfc3RhcnQsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA8PSBzLm1heF9sYXp5X21hdGNoICYmIHMubG9va2FoZWFkID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoLS07CiAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9IHdoaWxlICgtLXMubWF0Y2hfbGVuZ3RoICE9PSAwKTsKICAgICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcy5zdHJzdGFydCArPSBzLm1hdGNoX2xlbmd0aDsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3Muc3Ryc3RhcnRdOwogICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IHMuc3Ryc3RhcnQgPCBNSU5fTUFUQ0ggLSAxID8gcy5zdHJzdGFydCA6IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9zbG93KHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGhhc2hfaGVhZDsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIHZhciBtYXhfaW5zZXJ0OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGhhc2hfaGVhZCA9IDA7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICBzLmhlYWRbcy5pbnNfaF0gPSBzLnN0cnN0YXJ0OwogICAgICAgICAgfQogICAgICAgICAgcy5wcmV2X2xlbmd0aCA9IHMubWF0Y2hfbGVuZ3RoOwogICAgICAgICAgcy5wcmV2X21hdGNoID0gcy5tYXRjaF9zdGFydDsKICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gTUlOX01BVENIIC0gMTsKICAgICAgICAgIGlmIChoYXNoX2hlYWQgIT09IDAgJiYgcy5wcmV2X2xlbmd0aCA8IHMubWF4X2xhenlfbWF0Y2ggJiYgcy5zdHJzdGFydCAtIGhhc2hfaG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ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gd2hpbGUgKC0tcy5wcmV2X2xlbmd0aCAhPT0gMCk7CiAgICAgICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMDsKICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAocy5tYXRjaF9hdmFpbGFibGUpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5tYXRjaF9hdmFpbGFibGUgPSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLm1hdGNoX2F2YWlsYWJsZSkgewogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gcy5zdHJzdGFydCA8IE1JTl9NQVRDSCAtIDEgPyBzLnN0cnN0YXJ0IDogTUlOX01BVENIIC0gMTsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5sYXN0X2xpdCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gQlNfQkxPQ0tfRE9ORTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX3JsZShzLCBmbHVzaCkgewogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgdmFyIHByZXY7CiAgICAgICAgdmFyIHNjYW4sIHN0cmVuZDsKICAgICAgICB2YXIgX3dpbiA9IHMud2luZG93OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0ggJiYgcy5zdHJzdGFydCA+IDApIHsKICAgICAgICAgICAgc2NhbiA9IHMuc3Ryc3RhcnQgLSAxOwogICAgICAgICAgICBwcmV2ID0gX3dpbltzY2FuXTsKICAgICAgICAgICAgaWYgKHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dKSB7CiAgICAgICAgICAgICAgc3RyZW5kID0gcy5zdHJzdGFydCArIE1BWF9NQVRDSDsKICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgfSB3aGlsZSAocHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBzY2FuIDwgc3RyZW5kKTsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IE1BWF9NQVRDSCAtIChzdHJlbmQgLSBzY2FuKTsKICAgICAgICAgICAgICBpZiAocy5tYXRjaF9sZW5ndGggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBzLmxvb2thaGVhZDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDEsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgKz0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9odWZmKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGJmbHVzaDsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSAwOwogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnRdKTsKICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19CTE9DS19ET05FOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIENvbmZpZyhnb29kX2xlbmd0aCwgbWF4X2xhenksIG5pY2VfbGVuZ3RoLCBtYXhfY2hhaW4sIGZ1bmMpIHsKICAgICAgICB0aGlzLmdvb2RfbGVuZ3RoID0gZ29vZF9sZW5ndGg7CiAgICAgICAgdGhpcy5tYXhfbGF6eSA9IG1heF9sYXp5OwogICAgICAgIHRoaXMubmljZV9sZW5ndGggPSBuaWNlX2xlbmd0aDsKICAgICAgICB0aGlzLm1heF9jaGFpbiA9IG1heF9jaGFpbjsKICAgICAgICB0aGlzLmZ1bmMgPSBmdW5jOwogICAgICB9CiAgICAgIHZhciBjb25maWd1cmF0aW9uX3RhYmxlOwogICAgICBjb25maWd1cmF0aW9uX3RhYmxlID0gWwogICAgICAgIG5ldyBDb25maWcoMCwgMCwgMCwgMCwgZGVmbGF0ZV9zdG9yZWQpLAogICAgICAgIG5ldyBDb25maWcoNCwgNCwgOCwgNCwgZGVmbGF0ZV9mYXN0KSwKICAgICAgICBuZXcgQ29uZmlnKDQsIDUsIDE2LCA4LCBkZWZsYXRlX2Zhc3QpLA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d0aCA9IHMucHJldl9sZW5ndGggPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMDsKICAgICAgICBzLmluc19oID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBEZWZsYXRlU3RhdGUoKSB7CiAgICAgICAgdGhpcy5zdHJtID0gbnVsbDsKICAgICAgICB0aGlzLnN0YXR1cyA9IDA7CiAgICAgICAgdGhpcy5wZW5kaW5nX2J1ZiA9IG51bGw7CiAgICAgICAgdGhpcy5wZW5kaW5nX2J1Zl9zaXplID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmcgPSAwOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5nemhlYWQgPSBudWxsOwogICAgICAgIHRoaXMuZ3ppbmRleCA9IDA7CiAgICAgICAgdGhpcy5tZXRob2QgPSBaX0RFRkxBVEVEOwogICAgICAgIHRoaXMubGFzdF9mbHVzaCA9IC0xOwogICAgICAgIHRoaXMud19zaXplID0gMDsKICAgICAgICB0aGlzLndfYml0cyA9IDA7CiAgICAgICAgdGhpcy53X21hc2sgPSAwOwogICAgICAgIHRoaXMud2luZG93ID0gbnVsbDsKICAgICAgICB0aGlzLndpbmRvd19zaXplID0gMDsKICAgICAgICB0aGlzLnByZXYgPSBudWxsOwogICAgICAgIHRoaXMuaGVhZCA9IG51bGw7CiAgICAgICAgdGhpcy5pbnNfaCA9IDA7CiAgICAgICAgdGhpcy5oYXNoX3NpemUgPSAwOwogICAgICAgIHRoaXMuaGFzaF9iaXRzID0gMDsKICAgICAgICB0aGlzLmhhc2hfbWFzayA9IDA7CiAgICAgICAgdGhpcy5oYXNoX3NoaWZ0ID0gMDsKICAgICAgICB0aGlzLmJsb2NrX3N0YXJ0ID0gMDsKICAgICAgICB0aGlzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgdGhpcy5wcmV2X21hdGNoID0gMDsKICAgICAgICB0aGlzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgdGhpcy5zdHJzdGFydCA9IDA7CiAgICAgICAgdGhpcy5tYXRjaF9zdGFydCA9IDA7CiAgICAgICAgdGhpcy5sb29rYWhlYWQgPSAwOwogICAgICAgIHRoaXMucHJldl9sZW5ndGggPSAwOwogICAgICAgIHRoaXMubWF4X2NoYWluX2xlbmd0aCA9IDA7CiAgICAgICAgdGhpcy5tYXhfbGF6eV9tYXRjaCA9IDA7CiAgICAgICAgdGhpcy5sZXZlbCA9IDA7CiAgICAgICAgdGhpcy5zdHJhdGVneSA9IDA7CiAgICAgICAgdGhpcy5nb29kX21hdGNoID0gMDsKICAgICAgICB0aGlzLm5pY2VfbWF0Y2ggPSAwOwogICAgICAgIHRoaXMuZHluX2x0cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KEhFQVBfU0laRSAqIDIpOwogICAgICAgIHRoaXMuZHluX2R0cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KCgyICogRF9DT0RFUyArIDEpICogMik7CiAgICAgICAgdGhpcy5ibF90cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KCgyICogQkxfQ09ERVMgKyAxKSAqIDIpOwogICAgICAgIHplcm8odGhpcy5keW5fbHRyZWUpOwogICAgICAgIHplcm8odGhpcy5keW5fZHRyZWUpOwogICAgICAgIHplcm8odGhpcy5ibF90cmVlKTsKICAgICAgICB0aGlzLmxfZGVzYyA9IG51bGw7CiAgICAgICAgdGhpcy5kX2Rlc2MgPSBudWxsOwogICAgICAgIHRoaXMuYmxfZGVzYyA9IG51bGw7CiAgICAgICAgdGhpcy5ibF9jb3VudCA9IG5ldyB1dGlscy5CdWYxNihNQVhfQklUUyArIDEpOwogICAgICAgIHRoaXMuaGVhcCA9IG5ldyB1dGlscy5CdWYxNigyICogTF9DT0RFUyArIDEpOwogICAgICAgIHplcm8odGhpcy5oZWFwKTsKICAgICAgICB0aGlzLmhlYXBfbGVuID0gMDsKICAgICAgICB0aGlzLmhlYXBfbWF4ID0gMDsKICAgICAgICB0aGlzLmRlcHRoID0gbmV3IHV0aWxzLkJ1ZjE2KDIgKiBMX0NPREVTICsgMSk7CiAgICAgICAgemVybyh0aGlzLmRlcHRoKTsKICAgICAgICB0aGlzLmxfYnVmID0gMDsKICAgICAgICB0aGlzLmxpdF9idWZzaXplID0gMDsKICAgICAgICB0aGlzLmxhc3RfbGl0ID0gMDsKICAgICAgICB0aGlzLmRfYnVmID0gMDsKICAgICAgICB0aGlzLm9wdF9sZW4gPSAwOwogICAgICAgIHRoaXMuc3RhdGljX2xlbiA9IDA7CiAgICAgICAgdGhpcy5tYXRjaGVzID0gMDsKICAgICAgICB0aGlzLmluc2VydCA9IDA7CiAgICAgICAgdGhpcy5iaV9idWYgPSAwOwogICAgICAgIHRoaXMuYmlfdmFsaWQgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVSZXNldEtlZXAoc3RybSkgewogICAgICAgIHZhciBzOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBaX1NUUkVBTV9FUlJPUik7CiAgICAgICAgfQogICAgICAgIHN0cm0udG90YWxfaW4gPSBzdHJtLnRvdGFsX291dCA9IDA7CiAgICAgICAgc3RybS5kYXRhX3R5cGUgPSBaX1VOS05PV047CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgcy5wZW5kaW5nID0gMDsKICAgICAgICBzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICBpZiAocy53cmFwIDwgMCkgewogICAgICAgICAgcy53cmFwID0gLXMud3JhcDsKICAgICAgICB9CiAgICAgICAgcy5zdGF0dXMgPSBzLndyYXAgPyBJTklUX1NUQVRFIDogQlVTWV9TVEFURTsKICAgICAgICBzdHJtLmFkbGVyID0gcy53cmFwID09PSAyID8gMCA6IDE7CiAgICAgICAgcy5sYXN0X2ZsdXNoID0gWl9OT19GTFVTSDsKICAgICAgICB0cmVlcy5fdHJfaW5pdChzKTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmVzZXQoc3RybSkgewogICAgICAgIHZhciByZXQgPSBkZWZsYXRlUmVzZXRLZWVwKHN0cm0pOwogICAgICAgIGlmIChyZXQgPT09IFpfT0spIHsKICAgICAgICAgIGxtX2luaXQoc3RybS5zdGF0ZSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZVNldEhlYWRlcihzdHJtLCBoZWFkKSB7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmIChzdHJtLnN0YXRlLndyYXAgIT09IDIpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RybS5zdGF0ZS5nemhlYWQgPSBoZWFkOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVJbml0MihzdHJtLCBsZXZlbCwgbWV0aG9kLCB3aW5kb3dCaXRzLCBtZW1MZXZlbCwgc3RyYXRlZ3kpIHsKICAgICAgICBpZiAoIXN0cm0pIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgdmFyIHdyYXAgPSAxOwogICAgICAgIGlmIChsZXZlbCA9PT0gWl9ERUZBVUxUX0NPTVBSRVNTSU9OKSB7CiAgICAgICAgICBsZXZlbCA9IDY7CiAgICAgICAgfQogICAgICAgIGlmICh3aW5kb3dCaXRzIDwgMCkgewogICAgICAgICAgd3JhcCA9IDA7CiAgICAgICAgICB3aW5kb3dCaXRzID0gLXdpbmRvd0JpdHM7CiAgICAgICAgfSBlbHNlIGlmICh3aW5kb3dCaXRzID4gMTUpIHsKICAgICAgICAgIHdyYXAgPSAyOwogICAgICAgICAgd2luZG93Qml0cyAtPSAxNjsKICAgICAgICB9CiAgICAgICAgaWYgKG1lbUxldmVsIDwgMSB8fCBtZW1MZXZlbCA+IE1BWF9NRU1fTEVWRUwgfHwgbWV0aG9kICE9PSBaX0RFRkxBVEVEIHx8IHdpbmRvd0JpdHMgPCA4IHx8IHdpbmRvd0JpdHMgPiAxNSB8fCBsZXZlbCA8IDAgfHwgbGV2ZWwgPiA5IHx8IHN0cmF0ZWd5IDwgMCB8fCBzdHJhdGVneSA+IFpfRklYRUQpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyA9PT0gOCkgewogICAgICAgICAgd2luZG93Qml0cyA9IDk7CiAgICAgICAgfQogICAgICAgIHZhciBzID0gbmV3IERlZmxhdGVTdGF0ZSgpOwogICAgICAgIHN0cm0uc3RhdGUgPSBzOwogICAgICAgIHMuc3RybSA9IHN0cm07CiAgICAgICAgcy53cmFwID0gd3JhcDsKICAgICAgICBzLmd6aGVhZCA9IG51bGw7CiAgICAgICAgcy53X2JpdHMgPSB3aW5kb3dCaXRzOwogICAgICAgIHMud19zaXplID0gMSA8PCBzLndfYml0czsKICAgICAgICBzLndfbWFzayA9IHMud19zaXplIC0gMTsKICAgICAgICBzLmhhc2hfYml0cyA9IG1lbUxldmVsICsgNzsKICAgICAgICBzLmhhc2hfc2l6ZSA9IDEgPDwgcy5oYXNoX2JpdHM7CiAgICAgICAgcy5oYXNoX21hc2sgPSBzLmhhc2hfc2l6ZSAtIDE7CiAgICAgICAgcy5oYXNoX3NoaWZ0ID0gfn4oKHMuaGFzaF9iaXRzICsgTUlOX01BVENIIC0gMSkgLyBNSU5fTUFUQ0gpOwogICAgICAgIHMud2luZG93ID0gbmV3IHV0aWxzLkJ1Zjgocy53X3NpemUgK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ICAgfQogICAgICAgIHMgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmICghc3RybS5vdXRwdXQgfHwgIXN0cm0uaW5wdXQgJiYgc3RybS5hdmFpbF9pbiAhPT0gMCB8fCBzLnN0YXR1cyA9PT0gRklOSVNIX1NUQVRFICYmIGZsdXNoICE9PSBaX0ZJTklTSCkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBzdHJtLmF2YWlsX291dCA9PT0gMCA/IFpfQlVGX0VSUk9SIDogWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBzLnN0cm0gPSBzdHJtOwogICAgICAgIG9sZF9mbHVzaCA9IHMubGFzdF9mbHVzaDsKICAgICAgICBzLmxhc3RfZmx1c2ggPSBmbHVzaDsKICAgICAgICBpZiAocy5zdGF0dXMgPT09IElOSVRfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLndyYXAgPT09IDIpIHsKICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgIHB1dF9ieXRlKHMsIDMxKTsKICAgICAgICAgICAgcHV0X2J5dGUocywgMTM5KTsKICAgICAgICAgICAgcHV0X2J5dGUocywgOCk7CiAgICAgICAgICAgIGlmICghcy5nemhlYWQpIHsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgT1NfQ09ERSk7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIChzLmd6aGVhZC50ZXh0ID8gMSA6IDApICsgKHMuZ3poZWFkLmhjcmMgPyAyIDogMCkgKyAoIXMuZ3poZWFkLmV4dHJhID8gMCA6IDQpICsgKCFzLmd6aGVhZC5uYW1lID8gMCA6IDgpICsgKCFzLmd6aGVhZC5jb21tZW50ID8gMCA6IDE2KSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiA4ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDE2ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDI0ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQub3MgJiAyNTUpOwogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5leHRyYSAmJiBzLmd6aGVhZC5leHRyYS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLmV4dHJhLmxlbmd0aCAmIDI1NSk7CiAgICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYS5sZW5ndGggPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjKSB7CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nLCAwKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcy5nemluZGV4ID0gMDsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IEVYVFJBX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB2YXIgaGVhZGVyID0gWl9ERUZMQVRFRCArIChzLndfYml0cyAtIDggPDwgNCkgPDwgODsKICAgICAgICAgICAgdmFyIGxldmVsX2ZsYWdzID0gLTE7CiAgICAgICAgICAgIGlmIChzLnN0cmF0ZWd5ID49IFpfSFVGRk1BTl9PTkxZIHx8IHMubGV2ZWwgPCAyKSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAwOwogICAgICAgICAgICB9IGVsc2UgaWYgKHMubGV2ZWwgPCA2KSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAxOwogICAgICAgICAgICB9IGVsc2UgaWYgKHMubGV2ZWwgPT09IDYpIHsKICAgICAgICAgICAgICBsZXZlbF9mbGFncyA9IDI7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAzOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGhlYWRlciB8PSBsZXZlbF9mbGFncyA8PCA2OwogICAgICAgICAgICBpZiAocy5zdHJzdGFydCAhPT0gMCkgewogICAgICAgICAgICAgIGhlYWRlciB8PSBQUkVTRVRfRElDVDsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZWFkZXIgKz0gMzEgLSBoZWFkZXIgJSAzMTsKICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBoZWFkZXIpOwogICAgICAgICAgICBpZiAocy5zdHJzdGFydCAhPT0gMCkgewogICAgICAgICAgICAgIHB1dFNob3J0TVNCKHMsIHN0cm0uYWRsZXIgPj4+IDE2KTsKICAgICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBzdHJtLmFkbGVyICYgNjU1MzUpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHN0cm0uYWRsZXIgPSAxOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IEVYVFJBX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy5nemhlYWQuZXh0cmEpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICB3aGlsZSAocy5nemluZGV4IDwgKHMuZ3poZWFkLmV4dHJhLmxlbmd0aCAmIDY1NTM1KSkgewogICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYVtzLmd6aW5kZXhdICYgMjU1KTsKICAgICAgICAgICAgICBzLmd6aW5kZXgrKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPT09IHMuZ3poZWFkLmV4dHJhLmxlbmd0aCkgewogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBOQU1FX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IE5BTUVfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gTkFNRV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLm5hbWUpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgICAgdmFsID0gMTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPCBzLmd6aGVhZC5uYW1lLmxlbmd0aCkgewogICAgICAgICAgICAgICAgdmFsID0gcy5nemhlYWQubmFtZS5jaGFyQ29kZUF0KHMuZ3ppbmRleCsrKSAmIDI1NTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdmFsID0gMDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgdmFsKTsKICAgICAgICAgICAgfSB3aGlsZSAodmFsICE9PSAwKTsKICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodmFsID09PSAwKSB7CiAgICAgICAgICAgICAgcy5nemluZGV4ID0gMDsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IENPTU1FTlRfU1RBVEU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQ09NTUVOVF9TVEFURTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBDT01NRU5UX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy5nemhlYWQuY29tbWVudCkgewogICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgICB2YWwgPSAxOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHMuZ3ppbmRleCA8IHMuZ3poZWFkLmNvbW1lbnQubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICB2YWwgPSBzLmd6aGVhZC5jb21tZW50LmNoYXJDb2RlQXQocy5nemluZGV4KyspICYgMjU1OwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB2YWwgPSAwOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBwdXRfYnl0ZShzLCB2YWwpOwogICAgICAgICAgICB9IHdoaWxlICh2YWwgIT09IDApOwogICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh2YWwgPT09IDApIHsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IEhDUkNfU1RBVEU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gSENSQ19TVEFURTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBIQ1JDX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYykgewogICAgICAgICAgICBpZiAocy5wZW5kaW5nICsgMiA+IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMucGVuZGluZyArIDIgPD0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciA+PiA4ICYgMjU1KTsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gMDsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IEJVU1lfU1RBVEU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMucGVuZGluZyAhPT0gMCkgewogICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIGlmIChzdHJtLmF2YWlsX2luID09PSAwICYmIHJhbmsoZmx1c2gpIDw9IHJhbmsob2xkX2ZsdXNoKSAmJiBmbHVzaCAhPT0gWl9GSU5JU0gpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9CVUZfRVJST1IpOwogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IEZJTklTSF9TVEFURSAmJiBzdHJtLmF2YWlsX2luICE9PSAwKSB7CiAgICAgICAgICByZXR1cm4gZXJyKHN0cm0sIFpfQlVGX0VSUk9SKTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0cm0uYXZhaWxfaW4gIT09IDAgfHwgcy5sb29rYWhlYWQgIT09IDAgfHwgZmx1c2ggIT09IFpfTk9fRkxVU0ggJiYgcy5zdGF0dXMgIT09IEZJTklTSF9TVEFURSkgewogICAgICAgICAgdmFyIGJzdGF0ZSA9IHMuc3RyYXRlZ3kgPT09IFpfSFVGRk1BTl9PTkxZID8gZGVmbGF0ZV9odWZmKHMsIGZsdXNoKSA6IHMuc3RyYXRlZ3kgPT09IFpfUkxFID8gZGVmbGF0ZV9ybGUocywgZmx1c2gpIDogY29uZmlndXJhdGlvbl90YWJsZVtzLmxldmVsXS5mdW5jKHMsIGZsdXNoKTsKICAgICAgICAgIGlmIChic3RhdGUgPT09IEJTX0ZJTklTSF9TVEFSVEVEIHx8IGJzdGF0ZSA9PT0gQlNfRklOSVNIX0RPTkUpIHsKICAgICAgICAgICAgcy5zdGF0dXMgPSBGSU5JU0hfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYnN0YXRlID09PSBCU19ORUVEX01PUkUgfHwgYnN0YXRlID09PSBCU19GSU5JU0hfU1RBUlRFRCkgewogICAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICBzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChic3RhdGUgPT09IEJTX0JMT0NLX0RPTkUpIHsKICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX1BBUlRJQUxfRkxVU0gpIHsKICAgICAgICAgICAgICB0cmVlcy5fdHJfYWxpZ24ocyk7CiAgICAgICAgICAgIH0gZWxzZSBpZiAoZmx1c2ggIT09IFpfQkxPQ0spIHsKICAgICAgICAgICAgICB0cmVlcy5fdHJfc3RvcmVkX2Jsb2NrKHMsIDAsIDAsIGZhbHNlKTsKICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfRlVMTF9GTFVTSCkgewogICAgICAgICAgICAgICAgemVybyhzLmhlYWQpOwogICAgICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHMuc3Ryc3RhcnQgPSAwOwogICAgICAgICAgICAgICAgICBzLmJsb2NrX3N0YXJ0ID0gMDsKICAgICAgICAgICAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICBzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoZmx1c2ggIT09IFpfRklOSVNIKSB7CiAgICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKHMud3JhcCA8PSAwKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRU5EOwogICAgICAgIH0KICAgICAgICBpZiAocy53cmFwID09PSAyKSB7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gOCAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDE2ICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gMjQgJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLnRvdGFsX2luID4+IDggJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiA+PiAxNiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLnRvdGFsX2luID4+IDI0ICYgMjU1KTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxl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7CiAgICAgICAgdmFyIHM7CiAgICAgICAgdmFyIHN0ciwgbjsKICAgICAgICB2YXIgd3JhcDsKICAgICAgICB2YXIgYXZhaWw7CiAgICAgICAgdmFyIG5leHQ7CiAgICAgICAgdmFyIGlucHV0OwogICAgICAgIHZhciB0bXBEaWN0OwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzID0gc3RybS5zdGF0ZTsKICAgICAgICB3cmFwID0gcy53cmFwOwogICAgICAgIGlmICh3cmFwID09PSAyIHx8IHdyYXAgPT09IDEgJiYgcy5zdGF0dXMgIT09IElOSVRfU1RBVEUgfHwgcy5sb29rYWhlYWQpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgaWYgKHdyYXAgPT09IDEpIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBhZGxlcjMyKHN0cm0uYWRsZXIsIGRpY3Rpb25hcnksIGRpY3RMZW5ndGgsIDApOwogICAgICAgIH0KICAgICAgICBzLndyYXAgPSAwOwogICAgICAgIGlmIChkaWN0TGVuZ3RoID49IHMud19zaXplKSB7CiAgICAgICAgICBpZiAod3JhcCA9PT0gMCkgewogICAgICAgICAgICB6ZXJvKHMuaGVhZCk7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgPSAwOwogICAgICAgICAgICBzLmJsb2NrX3N0YXJ0ID0gMDsKICAgICAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgICAgfQogICAgICAgICAgdG1wRGljdCA9IG5ldyB1dGlscy5CdWY4KHMud19zaXplKTsKICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHRtcERpY3QsIGRpY3Rpb25hcnksIGRpY3RMZW5ndGggLSBzLndfc2l6ZSwgcy53X3NpemUsIDApOwogICAgICAgICAgZGljdGlvbmFyeSA9IHRtcERpY3Q7CiAgICAgICAgICBkaWN0TGVuZ3RoID0gcy53X3NpemU7CiAgICAgICAgfQogICAgICAgIGF2YWlsID0gc3RybS5hdmFpbF9pbjsKICAgICAgICBuZXh0ID0gc3RybS5uZXh0X2luOwogICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gZGljdExlbmd0aDsKICAgICAgICBzdHJtLm5leHRfaW4gPSAwOwogICAgICAgIHN0cm0uaW5wdXQgPSBkaWN0aW9uYXJ5OwogICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgIHdoaWxlIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgIHN0ciA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICBuID0gcy5sb29rYWhlYWQgLSAoTUlOX01BVENIIC0gMSk7CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgcy5wcmV2W3N0ciAmIHMud19tYXNrXSA9IHMuaGVhZFtzLmluc19oXTsKICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gc3RyOwogICAgICAgICAgICBzdHIrKzsKICAgICAgICAgIH0gd2hpbGUgKC0tbik7CiAgICAgICAgICBzLnN0cnN0YXJ0ID0gc3RyOwogICAgICAgICAgcy5sb29rYWhlYWQgPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgICAgZmlsbF93aW5kb3cocyk7CiAgICAgICAgfQogICAgICAgIHMuc3Ryc3RhcnQgKz0gcy5sb29rYWhlYWQ7CiAgICAgICAgcy5ibG9ja19zdGFydCA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgcy5pbnNlcnQgPSBzLmxvb2thaGVhZDsKICAgICAgICBzLmxvb2thaGVhZCA9IDA7CiAgICAgICAgcy5tYXRjaF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ykgewogICAgICAgICAgYyA9IHN0ci5jaGFyQ29kZUF0KG1fcG9zKTsKICAgICAgICAgIGlmICgoYyAmIDY0NTEyKSA9PT0gNTUyOTYgJiYgbV9wb3MgKyAxIDwgc3RyX2xlbikgewogICAgICAgICAgICBjMiA9IHN0ci5jaGFyQ29kZUF0KG1fcG9zICsgMSk7CiAgICAgICAgICAgIGlmICgoYzIgJiA2NDUxMikgPT09IDU2MzIwKSB7CiAgICAgICAgICAgICAgYyA9IDY1NTM2ICsgKGMgLSA1NTI5NiA8PCAxMCkgKyAoYzIgLSA1NjMyMCk7CiAgICAgICAgICAgICAgbV9wb3MrKzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgYnVmX2xlbiArPSBjIDwgMTI4ID8gMSA6IGMgPCAyMDQ4ID8gMiA6IGMgPCA2NTUzNiA/IDMgOiA0OwogICAgICAgIH0KICAgICAgICBidWYgPSBuZXcgdXRpbHMuQnVmOChidWZfbGVuKTsKICAgICAgICBmb3IgKGkgPSAwLCBtX3BvcyA9IDA7IGkgPCBidWZfbGVuOyBtX3BvcysrKSB7CiAgICAgICAgICBjID0gc3RyLmNoYXJDb2RlQXQobV9wb3MpOwogICAgICAgICAgaWYgKChjICYgNjQ1MTIpID09PSA1NTI5NiAmJiBtX3BvcyArIDEgPCBzdHJfbGVuKSB7CiAgICAgICAgICAgIGMyID0gc3RyLmNoYXJDb2RlQXQobV9wb3MgKyAxKTsKICAgICAgICAgICAgaWYgKChjMiAmIDY0NTEyKSA9PT0gNTYzMjApIHsKICAgICAgICAgICAgICBjID0gNjU1MzYgKyAoYyAtIDU1Mjk2IDw8IDEwKSArIChjMiAtIDU2MzIwKTsKICAgICAgICAgICAgICBtX3BvcysrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDEyOCkgewogICAgICAgICAgICBidWZbaSsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCAyMDQ4KSB7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTkyIHwgYyA+Pj4gNjsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCA2NTUzNikgewogICAgICAgICAgICBidWZbaSsrXSA9IDIyNCB8IGMgPj4+IDEyOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDYgJiA2MzsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBidWZbaSsrXSA9IDI0MCB8IGMgPj4+IDE4OwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDEyICYgNjM7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyA+Pj4gNiAmIDYzOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgJiA2MzsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gYnVmMmJpbnN0cmluZyhidWYsIGxlbikgewogICAgICAgIGlmIChsZW4gPCA2NTUzNCkgewogICAgICAgICAgaWYgKGJ1Zi5zdWJhcnJheSAmJiBTVFJfQVBQTFlfVUlBX09LIHx8ICFidWYuc3ViYXJyYXkgJiYgU1RSX0FQUExZX09LKSB7CiAgICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KG51bGwsIHV0aWxzLnNocmlua0J1ZihidWYsIGxlbikpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgcmVzdWx0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgfQogICAgICBleHBvcnRzMi5idWYyYmluc3RyaW5nID0gZnVuY3Rpb24oYnVmKSB7CiAgICAgICAgcmV0dXJuIGJ1ZjJiaW5zdHJpbmcoYnVmLCBidWYubGVuZ3RoKTsKICAgICAgfTsKICAgICAgZXhwb3J0czIuYmluc3RyaW5nMmJ1ZiA9IGZ1bmN0aW9uKHN0cikgewogICAgICAgIHZhciBidWYgPSBuZXcgdXRpbHMuQnVmOChzdHIubGVuZ3RoKTsKICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gYnVmLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgICBidWZbaV0gPSBzdHIuY2hhckNvZGVBdChpKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgZXhwb3J0czIuYnVmMnN0cmluZyA9IGZ1bmN0aW9uKGJ1ZiwgbWF4KSB7CiAgICAgICAgdmFyIGksIG91dCwgYywgY19sZW47CiAgICAgICAgdmFyIGxlbiA9IG1heCB8fCBidWYubGVuZ3RoOwogICAgICAgIHZhciB1dGYxNmJ1ZiA9IG5ldyBBcnJheShsZW4gKiAyKTsKICAgICAgICBmb3IgKG91dCA9IDAsIGkgPSAwOyBpIDwgbGVuOyApIHsKICAgICAgICAgIGMgPSBidWZbaSsrXTsKICAgICAgICAgIGlmIChjIDwgMTI4KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgY19sZW4gPSBfdXRmOGxlbltjXTsKICAgICAgICAgIGlmIChjX2xlbiA+IDQpIHsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNjU1MzM7CiAgICAgICAgICAgIGkgKz0gY19sZW4gLSAxOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGMgJj0gY19sZW4gPT09IDIgPyAzMSA6IGNfbGVuID09PSAzID8gMTUgOiA3OwogICAgICAgICAgd2hpbGUgKGNfbGVuID4gMSAmJiBpIDwgbGVuKSB7CiAgICAgICAgICAgIGMgPSBjIDw8IDYgfCBidWZbaSsrXSAmIDYzOwogICAgICAgICAgICBjX2xlbi0tOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGNfbGVuID4gMSkgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA2NTUzMzsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDY1NTM2KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjIC09IDY1NTM2OwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NTI5NiB8IGMgPj4gMTAgJiAxMDIzOwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NjMyMCB8IGMgJiAxMDIzOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gYnVmMmJpbnN0cmluZyh1dGYxNmJ1Ziwgb3V0KTsKICAgICAgfTsKICAgICAgZXhwb3J0czIudXRmOGJvcmRlciA9IGZ1bmN0aW9uKGJ1ZiwgbWF4KSB7CiAgICAgICAgdmFyIHBvczsKICAgICAgICBtYXggPSBtYXggfHwgYnVmLmxlbmd0aDsKICAgICAgICBpZiAobWF4ID4gYnVmLmxlbmd0aCkgewogICAgICAgICAgbWF4ID0gYnVmLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgcG9zID0gbWF4IC0gMTsKICAgICAgICB3aGlsZSAocG9zID49IDAgJiYgKGJ1Zltwb3NdICYgMTkyKSA9PT0gMTI4KSB7CiAgICAgICAgICBwb3MtLTsKICAgICAgICB9CiAgICAgICAgaWYgKHBvcyA8IDApIHsKICAgICAgICAgIHJldHVybiBtYXg7CiAgICAgICAgfQogICAgICAgIGlmIChwb3MgPT09IDApIHsKICAgICAgICAgIHJldHVybi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b3B0LmhlYWRlcik7CiAgICAgICAgfQogICAgICAgIGlmIChvcHQuZGljdGlvbmFyeSkgewogICAgICAgICAgdmFyIGRpY3Q7CiAgICAgICAgICBpZiAodHlwZW9mIG9wdC5kaWN0aW9uYXJ5ID09PSAic3RyaW5nIikgewogICAgICAgICAgICBkaWN0ID0gc3RyaW5ncy5zdHJpbmcyYnVmKG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0gZWxzZSBpZiAodG9TdHJpbmcuY2FsbChvcHQuZGljdGlvbmFyeSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgICAgZGljdCA9IG5ldyBVaW50OEFycmF5KG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGRpY3QgPSBvcHQuZGljdGlvbmFyeTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlU2V0RGljdGlvbmFyeSh0aGlzLnN0cm0sIGRpY3QpOwogICAgICAgICAgaWYgKHN0YXR1cyAhPT0gWl9PSykgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IobXNnW3N0YXR1c10pOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5fZGljdF9zZXQgPSB0cnVlOwogICAgICAgIH0KICAgICAgfQogICAgICBEZWZsYXRlLnByb3RvdHlwZS5wdXNoID0gZnVuY3Rpb24oZGF0YSwgbW9kZSkgewogICAgICAgIHZhciBzdHJtID0gdGhpcy5zdHJtOwogICAgICAgIHZhciBjaHVua1NpemUgPSB0aGlzLm9wdGlvbnMuY2h1bmtTaXplOwogICAgICAgIHZhciBzdGF0dXMsIF9tb2RlOwogICAgICAgIGlmICh0aGlzLmVuZGVkKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICAgIF9tb2RlID0gbW9kZSA9PT0gfn5tb2RlID8gbW9kZSA6IG1vZGUgPT09IHRydWUgPyBaX0ZJTklTSCA6IFpfTk9fRkxVU0g7CiAgICAgICAgaWYgKHR5cGVvZiBkYXRhID09PSAic3RyaW5nIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IHN0cmluZ3Muc3RyaW5nMmJ1ZihkYXRhKTsKICAgICAgICB9IGVsc2UgaWYgKHRvU3RyaW5nLmNhbGwoZGF0YSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBuZXcgVWludDhBcnJheShkYXRhKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgc3RybS5pbnB1dCA9IGRhdGE7CiAgICAgICAgfQogICAgICAgIHN0cm0ubmV4dF9pbiA9IDA7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IHN0cm0uaW5wdXQubGVuZ3RoOwogICAgICAgIGRvIHsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzdHJtLm91dHB1dCA9IG5ldyB1dGlscy5CdWY4KGNodW5rU2l6ZSk7CiAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSAwOwogICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlKHN0cm0sIF9tb2RlKTsKICAgICAgICAgIGlmIChzdGF0dXMgIT09IFpfU1RSRUFNX0VORCAmJiBzdGF0dXMgIT09IFpfT0spIHsKICAgICAgICAgICAgdGhpcy5vbkVuZChzdGF0dXMpOwogICAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwIHx8IHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgKF9tb2RlID09PSBaX0ZJTklTSCB8fCBfbW9kZSA9PT0gWl9TWU5DX0ZMVVNIMikpIHsKICAgICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICB0aGlzLm9uRGF0YShzdHJpbmdzLmJ1ZjJiaW5zdHJpbmcodXRpbHMuc2hyaW5rQnVmKHN0cm0ub3V0cHV0LCBzdHJtLm5leHRfb3V0KSkpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKHN0cm0uYXZhaWxfaW4gPiAwIHx8IHN0cm0uYXZhaWxfb3V0ID09PSAwKSAmJiBzdGF0dXMgIT09IFpfU1RSRUFNX0VORCk7CiAgICAgICAgaWYgKF9tb2RlID09PSBaX0ZJTklTSCkgewogICAgICAgICAgc3RhdHVzID0gemxpYl9kZWZsYXRlLmRlZmxhdGVFbmQodGhpcy5zdHJtKTsKICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgcmV0dXJuIHN0YXR1cyA9PT0gWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBaX1NZTkNfRkxVU0gyKSB7CiAgICAgICAgICB0aGlzLm9uRW5kKFpfT0spOwogICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0cnVlOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkRhdGEgPSBmdW5jdGlvbihjaHVuaykgewogICAgICAgIHRoaXMuY2h1bmtzLnB1c2goY2h1bmspOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkVuZCA9IGZ1bmN0aW9uKHN0YXR1cykgewogICAgICAgIGlmIChzdGF0dXMgPT09IFpfT0spIHsKICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdGhpcy5jaHVua3Muam9pbigiIik7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHV0aWxzLmZsYXR0ZW5DaHVua3ModGhpcy5jaHVua3MpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuZXJyID0gc3RhdHVzOwogICAgICAgIHRoaXMubXNnID0gdGhpcy5zdHJtLm1zZzsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gZGVmbGF0ZShpbnB1dCwgb3B0aW9ucykgewogICAgICAgIHZhciBkZWZsYXRvciA9IG5ldyBEZWZsYXRlKG9wdGlvbnMpOwogICAgICAgIGRlZmxhdG9yLnB1c2goaW5wdXQsIHRydWUpOwogICAgICAgIGlmIChkZWZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IGRlZmxhdG9yLm1zZyB8fCBtc2dbZGVmbGF0b3IuZXJyXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGRlZmxhdG9yLnJlc3VsdDsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmF3KGlucHV0LCBvcHRpb25zKSB7CiAgICAgICAgb3B0aW9ucyA9IG9wdGlvbnMgfHwge307CiAgICAgICAgb3B0aW9ucy5yYXcgPSB0cnVlOwogICAgICAgIHJldHVybiBkZWZsYXRlKGlucHV0LCBvcHRpb25zKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBnemlwKGlucHV0LCBvcHRpb25zKSB7CiAgICAgICAgb3B0aW9ucyA9IG9wdGlvbnMgfHwge307CiAgICAgICAgb3B0aW9ucy5nemlwID0gdHJ1ZTsKICAgICAgICByZXR1cm4gZGVmbG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kbWFzazsKICAgICAgICB2YXIgaGVyZTsKICAgICAgICB2YXIgb3A7CiAgICAgICAgdmFyIGxlbjsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgZnJvbTsKICAgICAgICB2YXIgZnJvbV9zb3VyY2U7CiAgICAgICAgdmFyIGlucHV0LCBvdXRwdXQ7CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIF9pbiA9IHN0cm0ubmV4dF9pbjsKICAgICAgICBpbnB1dCA9IHN0cm0uaW5wdXQ7CiAgICAgICAgbGFzdCA9IF9pbiArIChzdHJtLmF2YWlsX2luIC0gNSk7CiAgICAgICAgX291dCA9IHN0cm0ubmV4dF9vdXQ7CiAgICAgICAgb3V0cHV0ID0gc3RybS5vdXRwdXQ7CiAgICAgICAgYmVnID0gX291dCAtIChzdGFydCAtIHN0cm0uYXZhaWxfb3V0KTsKICAgICAgICBlbmQgPSBfb3V0ICsgKHN0cm0uYXZhaWxfb3V0IC0gMjU3KTsKICAgICAgICBkbWF4ID0gc3RhdGUuZG1heDsKICAgICAgICB3c2l6ZSA9IHN0YXRlLndzaXplOwogICAgICAgIHdoYXZlID0gc3RhdGUud2hhdmU7CiAgICAgICAgd25leHQgPSBzdGF0ZS53bmV4dDsKICAgICAgICBzX3dpbmRvdyA9IHN0YXRlLndpbmRvdzsKICAgICAgICBob2xkID0gc3RhdGUuaG9sZDsKICAgICAgICBiaXRzID0gc3RhdGUuYml0czsKICAgICAgICBsY29kZSA9IHN0YXRlLmxlbmNvZGU7CiAgICAgICAgZGNvZGUgPSBzdGF0ZS5kaXN0Y29kZTsKICAgICAgICBsbWFzayA9ICgxIDw8IHN0YXRlLmxlbmJpdHMpIC0gMTsKICAgICAgICBkbWFzayA9ICgxIDw8IHN0YXRlLmRpc3RiaXRzKSAtIDE7CiAgICAgICAgdG9wOgogICAgICAgICAgZG8gewogICAgICAgICAgICBpZiAoYml0cyA8IDE1KSB7CiAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaGVyZSA9IGxjb2RlW2hvbGQgJiBsbWFza107CiAgICAgICAgICAgIGRvbGVuOgogICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAyNDsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgaWYgKG9wID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChvcCAmIDE2KSB7CiAgICAgICAgICAgICAgICAgIGxlbiA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgb3AgJj0gMTU7CiAgICAgICAgICAgICAgICAgIGlmIChvcCkgewogICAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGxlbiArPSBob2xkICYgKDEgPDwgb3ApIC0gMTsKICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IDE1KSB7CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGVyZSA9IGRjb2RlW2hvbGQgJiBkbWFza107CiAgICAgICAgICAgICAgICAgIGRvZGlzdDoKICAgICAgICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCAmIDE2KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGRpc3QgPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICAgICAgICAgIG9wICY9IDE1OwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgZGlzdCArPSBob2xkICYgKDEgPDwgb3ApIC0gMTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGRpc3QgPiBkbWF4KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2siOwogICAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgb3AgPSBfb3V0IC0gYmVnOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZGlzdCA+IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgb3AgPSBkaXN0IC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wID4gd2hhdmUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5zYW5lKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgdG9vIGZhciBiYWNrIjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IHNfd2luZG93OwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh3bmV4dCA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSArPSB3c2l6ZSAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wIDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmICh3bmV4dCA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tICs9IHdzaXplICsgd25leHQgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9wIC09IHduZXh0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wIDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSAwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAod25leHQgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvcCA9IHduZXh0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gKz0gd25leHQgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAobGVuID4gMikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IDM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4gPiAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSAzOwogICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKGxlbiA+IDIpOwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuID4gMSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmICgob3AgJiA2NCkgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgaGVyZSA9IGRjb2RlWyhoZXJlICYgNjU1MzUpICsgKGhvbGQgJiAoMSA8PCBvcCkgLSAxKV07CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlIGRvZGlzdDsKICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgY29kZSI7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoKG9wICYgNjQpID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGhlcmUgPSBsY29kZVsoaGVyZSAmIDY1NTM1KSArIChob2xkICYgKDEgPDwgb3ApIC0gMSldOwogICAgICAgICAgICAgICAgICBjb250aW51ZSBkb2xlbjsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAob3AgJiAzMikgewogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBsaXRlcmFsL2xlbmd0aCBjb2RlIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgfQogICAgICAgICAgfSB3aGlsZSAoX2luIDwgbGFzdCAmJiBfb3V0IDwgZW5kKTsKICAgICAgICBsZW4gPSBiaXRzID4+IDM7CiAgICAgICAgX2luIC09IGxlbjsKICAgICAgICBiaXRzIC09IGxlbiA8PCAzOwogICAgICAgIGhvbGQgJj0gKDEgPDwgYml0cykgLSAxOwogICAgICAgIHN0cm0ubmV4dF9pbiA9IF9pbjsKICAgICAgICBzdHJtLm5leHRfb3V0ID0gX291dDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gX2luIDwgbGFzdCA/IDUgKyAobGFzdCAtIF9pbikgOiA1IC0gKF9pbiAtIGxhc3QpOwogICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gX291dCA8IGVuZCA/IDI1NyArIChlbmQgLSBfb3V0KSA6IDI1NyAtIChfb3V0IC0gZW5kKTsKICAgICAgICBzdGF0ZS5ob2xkID0gaG9sZDsKICAgICAgICBzdGF0ZS5iaXRzID0gYml0czsKICAgICAgICByZXR1cm47CiAgICAgIH07CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9pbmZ0cmVlcy5qcwogIHZhciByZXF1aXJlX2luZnRyZWVzID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZnRyZWVzLmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24oKTsKICAgICAgdmFyIE1BWEJJVFMgPSAxNTsKICAgICAgdmFyIEVOT1VHSF9MRU5TID0gODUyOwogICAgICB2YXIgRU5PVUdIX0RJU1RTID0gNTkyOwogICAgICB2YXIgQ09ERVMgPSAwOwogICAgICB2YXIgTEVOUyA9IDE7CiAgICAgIHZhciBESVNUUyA9IDI7CiAgICAgIHZhciBsYmFzZSA9IFsKICAgICAgICAzLAogICAgICAgIDQsCiAgICAgICAgNSwKICAgICAgICA2LAogICAgICAgIDcsCiAgICAgICAgOCwKICAgICAgICA5LAogICAgICAgIDEwLAogICAgICAgIDExLAogICAgICAgIDEzLAogICAgICAgIDE1LAogICAgICAgIDE3LAogICAgICAgIDE5LAogICAgICAgIDIzLAogICAgICAgIDI3LAogICAgICAgIDMxLAogICAgICAgIDM1LAogICAgICAgIDQzLAogICAgICAgIDUxLAogICAgICAgIDU5LAogICAgICAgIDY3LAogICAgICAgIDgzLAogICAgICAgIDk5LAogICAgICAgIDExNSwKICAgICAgICAxMzEsCiAgICAgICAgMTYzLAogICAgICAgIDE5NSwKICAgICAgICAyMjcsCiAgICAgICAgMjU4LAogICAgICAgIDAsCiAgICAgICAgMAogICAgICBdOwogICAgICB2YXIgbGV4dCA9IFsKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAxNiwKICAgICAgICA3MiwKICAgICAgICA3OAogICAgICBdOwogICAgICB2YXIgZGJhc2UgPSBbCiAgICAgICAgMSwKICAgICAgICAyLAogICAgICAgIDMsCiAgICAgICAgNCwKICAgICAgICA1LAogICAgICAgIDcsCiAgICAgICAgOSwKICAgICAgICAxMywKICAgICAgICAxNywKICAgICAgICAyNSwKICAgICAgICAzMywKICAgICAgICA0OSwKICAgICAgICA2NSwKICAgICAgICA5NywKICAgICAgICAxMjksCiAgICAgICAgMTkzLAogICAgICAgIDI1NywKICAgICAgICAzODUsCiAgICAgICAgNTEzLAogICAgICAgIDc2OSwKICAgICAgICAxMDI1LAogICAgICAgIDE1MzcsCiAgICAgICAgMjA0OSwKICAgICAgICAzMDczLAogICAgICAgIDQwOTcsCiAgICAgICAgNjE0NSwKICAgICAgICA4MTkzLAogICAgICAgIDEyMjg5LAogICAgICAgIDE2Mzg1LAogICAgICAgIDI0NTc3LAogICAgICAgIDAsCiAgICAgICAgMAogICAgICBdOwogICAgICB2YXIgZGV4dCA9IFsKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAyMiwKICAgICAgICAyMiwKICAgICAgICAyMywKICAgICAgICAyMywKICAgICAgICAyNCwKICAgICAgICAyNCwKICAgICAgICAyNSwKICAgICAgICAyNSwKICAgICAgICAyNiwKICAgICAgICAyNiwKICAgICAgICAyNywKICAgICAgICAyNywKICAgICAgICAyOCwKICAgICAgICAyOCwKICAgICAgICAyOSwKICAgICAgICAyOSwKICAgICAgICA2NCwKICAgICAgICA2NAogICAgICBdOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBmdW5jdGlvbiBpbmZsYXRlX3RhYmxlKHR5cGUsIGxlbnMsIGxlbnNfaW5kZXgsIGNvZGVzLCB0YWJsZSwgdGFibGVfaW5kZXgsIHdvcmssIG9wdHMpIHsKICAgICAgICB2YXIgYml0cyA9IG9wdHMuYml0czsKICAgICAgICB2YXIgbGVuID0gMDsKICAgICAgICB2YXIgc3ltID0gMDsKICAgICAgICB2YXIgbWluID0gMCwgbWF4ID0gMDsKICAgICAgICB2YXIgcm9vdDIgPSAwOwogICAgICAgIHZhciBjdXJyID0gMDsKICAgICAgICB2YXIgZHJvcCA9IDA7CiAgICAgICAgdmFyIGxlZnQgPSAwOwogICAgICAgIHZhciB1c2VkID0gMDsKICAgICAgICB2YXIgaHVmZiA9IDA7CiAgICAgICAgdmFyIGluY3I7CiAgICAgICAgdmFyIGZpbGw7CiAgICAgICAgdmFyIGxvdzsKICAgICAgICB2YXIgbWFzazsKICAgICAgICB2YXIgbmV4dDsKICAgICAgICB2YXIgYmFzZSA9IG51bGw7CiAgICAgICAgdmFyIGJhc2VfaW5kZXggPSAwOwogICAgICAgIHZhciBlbmQ7CiAgICAgICAgdmFyIGNvdW50ID0gbmV3IHV0aWxzLkJ1ZjE2KE1BWEJJVFMgKyAxKTsKICAgICAgICB2YXIgb2ZmcyA9IG5ldyB1dGlscy5CdWYxNihNQVhCSVRTICsgMSk7CiAgICAgICAgdmFyIGV4dHJhID0gbnVsbDsKICAgICAgICB2YXIgZXh0cmFfaW5kZXggPSAwOwogICAgICAgIHZhciBoZXJlX2JpdHMsIGhlcmVfb3AsIGhlcmVfdmFsOwogICAgICAgIGZvciAobGVuID0gMDsgbGVuIDw9IE1BWEJJVFM7IGxlbisrKSB7CiAgICAgICAgICBjb3VudFtsZW5dID0gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChzeW0gPSAwOyBzeW0gPCBjb2Rlczsgc3ltKyspIHsKICAgICAgICAgIGNvdW50W2xlbnNbbGVuc19pbmRleCArIHN5bV1dKys7CiAgICAgICAgfQogICAgICAgIHJvb3QyID0gYml0czsKICAgICAgICBmb3IgKG1heCA9IE1BWEJJVFM7IG1heCA+PSAxOyBtYXgtLSkgewogICAgICAgICAgaWYgKGNvdW50W21heF0gIT09IDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChyb290MiA+IG1heCkgewogICAgICAgICAgcm9vdDIgPSBtYXg7CiAgICAgICAgfQogICAgICAgIGlmIChtYXggPT09IDApIHsKICAgICAgICAgIHRhYmxlW3RhYmxlX2luZGV4KytdID0gMSA8PCAyNCB8IDY0IDw8IDE2IHwgMDsKICAgICAgICAgIHRhYmxlW3RhYmxlX2luZGV4KytdID0gMSA8PCAyNCB8IDY0IDw8IDE2IHwgMDsKICAgICAgICAgIG9wdHMuYml0cyA9IDE7CiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChtaW4gPSAxOyBtaW4gPCBtYXg7IG1pbisrKSB7CiAgICAgICAgICBpZiAoY291bnRbbWluXSAhPT0gMCkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHJvb3QyIDwgbWluKSB7CiAgICAgICAgICByb290MiA9IG1pbjsKICAgICAgICB9CiAgICAgICAgbGVmdCA9IDE7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPD0gTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIGxlZnQgPDw9IDE7CiAgICAgICAgICBsZWZ0IC09IGNvdW50W2xlbl07CiAgICAgICAgICBpZiAobGVmdCA8IDApIHsKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAobGVmdCA+IDAgJiYgKHR5cGUgPT09IENPREVTIHx8IG1heCAhPT0gMSkpIHsKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgb2Zmc1sxXSA9IDA7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPCBNQVhCSVRTOyBsZW4rKykgewogICAgICAgICAgb2Zmc1tsZW4gKyAxXSA9IG9mZnNbbGVuXSArIGNvdW50W2xlbl07CiAgICAgICAgfQogICAgICAgIGZvciAoc3ltID0gMDsgc3ltIDwgY29kZXM7IHN5bSsrKSB7CiAgICAgICAgICBpZiAobGVuc1tsZW5zX2luZGV4ICsgc3ltXSAhPT0gMCkgewogICAgICAgICAgICB3b3JrW29mZnNbbGVuc1tsZW5zX2luZGV4ICsgc3ltXV0rK10gPSBzeW07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlID09PSBDT0RFUykgewogICAgICAgICAgYmFzZSA9IGV4dHJhID0gd29yazsKICAgICAgICAgIGVuZCA9IDE5OwogICAgICAgIH0gZWxzZSBpZiAodHlwZSA9PT0gTEVOUykgewogICAgICAgICAgYmFzZSA9IGxiYXNlOwogICAgICAgICAgYmFzZV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBleHRyYSA9IGxleHQ7CiAgICAgICAgICBleHRyYV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBlbmQgPSAyNTY7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGJhc2UgPSBkYmFzZTsKICAgICAgICAgIGV4dHJhID0gZGV4dDsKICAgICAgICAgIGVuZCA9IC0xOwogICAgICAgIH0KICAgICAgICBodWZmID0gMDsKICAgICAgICBzeW0gPSAwOwogICAgICAgIGxlbiA9IG1pbjsKICAgICAgICBuZXh0ID0gdGFibGVfaW5kZXg7CiAgICAgICAgY3VyciA9IHJvb3QyOwogICAgICAgIGRyb3AgPSAwOwogICAgICAgIGxvdyA9IC0xOwogICAgICAgIHVzZWQgPSAxIDw8IHJvb3QyOwogICAgICAgIG1hc2sgPSB1c2VkIC0gMTsKICAgICAgICBpZiAodHlwZSA9PT0gTEVOUyAmJiB1c2VkID4gRU5PVUdIX0xFTlMgfHwgdHlwZSA9PT0gRElTVFMgJiYgdXNlZCA+IEVOT1VHSF9ESVNUUykgewogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgfQogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaGVyZV9iaXRzID0gbGVuIC0gZHJvcDsKICAgICAgICAgIGlmICh3b3JrW3N5bV0gPCBlbmQpIHsKICAgICAgICAgICAgaGVyZV9vcCA9IDA7CiAgICAgICAgICAgIGhlcmVfdmFsID0gd29ya1tzeW1dOwogICAgICAgICAgfSBlbHNlIGlmICh3b3JrW3N5bV0gPiBlbmQpIHsKICAgICAgICAgICAgaGVyZV9vcCA9IGV4dHJhW2V4dHJhX2luZGV4ICsgd29ya1tzeW1dXTsKICAgICAgICAgICAgaGVyZV92YWwgPSBiYXNlW2Jhc2VfaW5kZXggKyB3b3JrW3N5bV1dOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaGVyZV9vcCA9IDMyICsgNjQ7CiAgICAgICAgICAgIGhlcmVfdmFsID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIGluY3IgPSAxIDw8IGxlbiAtIGRyb3A7CiAgICAgICAgICBmaWxsID0gMSA8PCBjdXJyOwogICAgICAgICAgbWluID0gZmlsbDsKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgZmlsbCAtPSBpbmNyOwogICAgICAgICAgICB0YWJsZVtuZXh0ICsgKGh1ZmYgPj4gZHJvcCkgKyBmaWxsXSA9IGhlcmVfYml0cyA8PCAyNCB8IGhlcmVfb3AgPDwgMTYgfCBoZXJlX3ZhbCB8IDA7CiAgICAgICAgICB9IHdoaWxlIChmaWxsICE9PSAwKTsKICAgICAgICAgIGluY3IgPSAxIDw8IGxlbiAtIDE7CiAgICAgICAgICB3aGlsZSAoaHVmZiAmIGluY3IpIHsKICAgICAgICAgICAgaW5jciA+Pj0gMTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChpbmNyICE9PSAwKSB7CiAgICAgICAgICAgIGh1ZmYgJj0gaW5jciAtIDE7CiAgICAgICAgICAgIGh1ZmYgKz0gaW5jcjsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGh1ZmYgPSAwOwogICAgICAgICAgfQogICAgICAgICAgc3ltKys7CiAgICAgICAgICBpZiAoLS1jb3VudFtsZW5dID09PSAwKSB7CiAgICAgICAgICAgIGlmIChsZW4gPT09IG1heCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxlbiA9IGxlbnNbbGVuc19pbmRleCArIHdvcmtbc3ltXV07CiAgICAgICAgICB9CiAgICAgICAgICBpZiAobGVuID4gcm9vdDIgJiYgKGh1ZmYgJiBtYXNrKSAhPT0gbG93KSB7CiAgICAgICAgICAgIGlmIChkcm9wID09PSAwKSB7CiAgICAgICAgICAgICAgZHJvcCA9IHJvb3QyOwogICAgICAgICAgICB9CiAgICAgICAgICAgIG5leHQgKz0gbWluOwogICAgICAgICAgICBjdXJyID0gbGVuIC0gZHJvcDsKICAgICAgICAgICAgbGVmdCA9IDEgPDwgY3VycjsKICAgICAgICAgICAgd2hpbGUgKGN1cnIgKyBkcm9wIDwgbWF4KSB7CiAgICAgICAgICAgICAgbGVmdCAtPSBjb3VudFtjdXJyICsgZHJvcF07CiAgICAgICAgICAgICAgaWYgKGxlZnQgPD0gMCkgewogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGN1cnIrKzsKICAgICAgICAgICAgICBsZWZ0IDw8PSAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHVzZWQgKz0gMSA8PCBjdXJyOwogICAgICAgICAgICBpZiAodHlwZSA9PT0gTEVOUyAmJiB1c2VkID4gRU5PVUdIX0xFTlMgfHwgdHlwZSA9PT0gRElTVFMgJiYgdXNlZCA+IEVOT1VHSF9ESVNUUykgewogICAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxvdyA9IGh1ZmYgJiBtYXNrOwogICAgICAgICAgICB0YWJsZVtsb3ddID0gcm9vdDIgPDwgMjQgfCBjdXJyIDw8IDE2IHwgbmV4dCAtIHRhYmxlX2luZGV4IHwgMDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGh1ZmYgIT09IDApIHsKICAgICAgICAgIHRhYmxlW25leHQgKyBodWZmXSA9IGxlbiAtIGRyb3AgPDwgMjQgfCA2NCA8PCAxNiB8IDA7CiAgICAgICAgfQogICAgICAgIG9wdHMuYml0cyA9IHJvb3QyOwogICAgICAgIHJldHVybiAwOwogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mbGF0ZS5qcwogIHZhciByZXF1aXJlX2luZmxhdGUgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mbGF0ZS5qcyIoZXhwb3J0czIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIHZhciB1dGlscyA9IHJlcXVpcmVfY29tbW9uKCk7CiAgICAgIHZhciBhZGxlcjMyID0gcmVxdWlyZV9hZGxlcjMyKCk7CiAgICAgIHZhciBjcmMzMiA9IHJlcXVpcmVfY3JjMzIoKTsKICAgICAgdmFyIGluZmxhdGVfZmFzdCA9IHJlcXVpcmVfaW5mZmFzdCgpOwogICAgICB2YXIgaW5mbGF0ZV90YWJsZSA9IHJlcXVpcmVfaW5mdHJlZXMoKTsKICAgICAgdmFyIENPREVTID0gMDsKICAgICAgdmFyIExFTlMgPSAxOwogICAgICB2YXIgRElTVFMgPSAyOwogICAgICB2YXIgWl9GSU5JU0ggPSA0OwogICAgICB2YXIgWl9CTE9DSyA9IDU7CiAgICAgIHZhciBaX1RSRUVTID0gNjsKICAgICAgdmFyIFpfT0sgPSAwOwogICAgICB2YXIgWl9TVFJFQU1fRU5EID0gMTsKICAgICAgdmFyIFpfTkVFRF9ESUNUID0gMjsKICAgICAgdmFyIFpfU1RSRUFNX0VSUk9SID0gLTI7CiAgICAgIHZhciBaX0RBVEFfRVJST1IgPSAtMzsKICAgICAgdmFyIFpfTUVNX0VSUk9SID0gLTQ7CiAgICAgIHZhciBaX0JVRl9FUlJPUiA9IC01OwogICAgICB2YXIgWl9ERUZMQVRFRCA9IDg7CiAgICAgIHZhciBIRUFEID0gMTsKICAgICAgdmFyIEZMQUdTID0gMjsKICAgICAgdmFyIFRJTUUgPSAzOwogICAgICB2YXIgT1MgPSA0OwogICAgICB2YXIgRVhMRU4gPSA1OwogICAgICB2YXIgRVhUUkEgPSA2OwogICAgICB2YXIgTkFNRSA9IDc7CiAgICAgIHZhciBDT01NRU5UID0gODsKICAgICAgdmFyIEhDUkMgPSA5OwogICAgICB2YXIgRElDVElEID0gMTA7CiAgICAgIHZhciBESUNUID0gMTE7CiAgICAgIHZhciBUWVBFID0gMTI7CiAgICAgIHZhciBUWVBFRE8gPSAxMzsKICAgICAgdmFyIFNUT1JFRCA9IDE0OwogICAgICB2YXIgQ09QWV8gPSAxNTsKICAgICAgdmFyIENPUFkgPSAxNjsKICAgICAgdmFyIFRBQkxFID0gMTc7CiAgICAgIHZhciBMRU5MRU5TID0gMTg7CiAgICAgIHZhciBDT0RFTEVOUyA9IDE5OwogICAgICB2YXIgTEVOXyA9IDIwOwogICAgICB2YXIgTEVOID0gMjE7CiAgICAgIHZhciBMRU5FWFQgPSAyMjsKICAgICAgdmFyIERJU1QgPSAyMzsKICAgICAgdmFyIERJU1RFWFQgPSAyNDsKICAgICAgdmFyIE1BVENIID0gMjU7CiAgICAgIHZhciBMSVQgPSAyNjsKICAgICAgdmFyIENIRUNLID0gMjc7CiAgICAgIHZhciBMRU5HVEggPSAyODsKICAgICAgdmFyIERPTkUgPSAyOTsKICAgICAgdmFyIEJBRCA9IDMwOwogICAgICB2YXIgTUVNID0gMzE7CiAgICAgIHZhciBTWU5DID0gMzI7CiAgICAgIHZhciBFTk9VR0hfTEVOUyA9IDg1MjsKICAgICAgdmFyIEVOT1VHSF9ESVNUUyA9IDU5MjsKICAgICAgdmFyIE1BWF9XQklUUyA9IDE1OwogICAgICB2YXIgREVGX1dCSVRTID0gTUFYX1dCSVRTOwogICAgICBmdW5jdGlvbiB6c3dhcDMyKHEpIHsKICAgICAgICByZXR1cm4gKHEgPj4+IDI0ICYgMjU1KSArIChxID4+PiA4ICYgNjUyODApICsgKChxICYgNjUyODApIDw8IDgpICsgKChxICYgMjU1KSA8PCAyNCk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gSW5mbGF0ZVN0YXRlKCkgewogICAgICAgIHRoaXMubW9kZSA9IDA7CiAgICAgICAgdGhpcy5sYXN0ID0gZmFsc2U7CiAgICAgICAgdGhpcy53cmFwID0gMDsKICAgICAgICB0aGlzLmhhdmVkaWN0ID0gZmFsc2U7CiAgICAgICAgdGhpcy5mbGFncyA9IDA7CiAgICAgICAgdGhpcy5kbWF4ID0gMDsKICAgICAgICB0aGlzLmNoZWNrID0gMDsKICAgICAgICB0aGlzLnRvdGFsID0gMDsKICAgICAgICB0aGlzLmhlYWQgPSBudWxsOwogICAgICAgIHRoaXMud2JpdHMgPSAwOwogICAgICAgIHRoaXMud3NpemUgPSAwOwogICAgICAgIHRoaXMud2hhdmUgPSAwOwogICAgICAgIHRoaXMud25leHQgPSAwOwogICAgICAgIHRoaXMud2luZG93ID0gbnVsbDsKICAgICAgICB0aGlzLmhvbGQgPSAwOwogICAgICAgIHRoaXMuYml0cyA9IDA7CiAgICAgICAgdGhpcy5sZW5ndGggPSAwOwogICAgICAgIHRoaXMub2Zmc2V0ID0gMDsKICAgICAgICB0aGlzLmV4dHJhID0gMDsKICAgICAgICB0aGlzLmxlbmNvZGUgPSBudWxsOwogICAgICAgIHRoaXMuZGlzdGNvZGUgPSBudWxsOwogICAgICAgIHRoaXMubGVuYml0cyA9IDA7CiAgICAgICAgdGhpcy5kaXN0Yml0cyA9IDA7CiAgICAgICAgdGhpcy5uY29kZSA9IDA7CiAgICAgICAgdGhpcy5ubGVuID0gMDsKICAgICAgICB0aGlzLm5kaXN0ID0gMDsKICAgICAgICB0aGlzLmhhdmUgPSAwOwogICAgICAgIHRoaXMubmV4dCA9IG51bGw7CiAgICAgICAgdGhpcy5sZW5zID0gbmV3IHV0aWxzLkJ1ZjE2KDMyMCk7CiAgICAgICAgdGhpcy53b3JrID0gbmV3IHV0aWxzLkJ1ZjE2KDI4OCk7CiAgICAgICAgdGhpcy5sZW5keW4gPSBudWxsOwogICAgICAgIHRoaXMuZGlzdGR5biA9IG51bGw7CiAgICAgICAgdGhpcy5zYW5lID0gMDsKICAgICAgICB0aGlzLmJhY2sgPSAwOwogICAgICAgIHRoaXMud2FzID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlUmVzZXRLZWVwKHN0cm0pIHsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBzdHJtLnRvdGFsX2luID0gc3RybS50b3RhbF9vdXQgPSBzdGF0ZS50b3RhbCA9IDA7CiAgICAgICAgc3RybS5tc2cgPSAiIjsKICAgICAgICBpZiAoc3RhdGUud3JhcCkgewogICAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLndyYXAgJiAxOwogICAgICAgIH0KICAgICAgICBzdGF0ZS5tb2RlID0gSEVBRDsKICAgICAgICBzdGF0ZS5sYXN0ID0gMDsKICAgICAgICBzdGF0ZS5oYXZlZGljdCA9IDA7CiAgICAgICAgc3RhdGUuZG1heCA9IDMyNzY4OwogICAgICAgIHN0YXRlLmhlYWQgPSBudWxsOwogICAgICAgIHN0YXRlLmhvbGQgPSAwOwogICAgICAgIHN0YXRlLmJpdHMgPSAwOwogICAgICAgIHN0YXRlLmxlbmNvZGUgPSBzdGF0ZS5sZW5keW4gPSBuZXcgdXRpbHMuQnVmMzIoRU5PVUdIX0xFTlMpOwogICAgICAgIHN0YXRlLmRpc3Rjb2RlID0gc3RhdGUuZGlzdGR5biA9IG5ldyB1dGlscy5CdWYzMihFTk9VR0hfRElTVFMpOwogICAgICAgIHN0YXRlLnNhbmUgPSAxOwogICAgICAgIHN0YXRlLmJhY2sgPSAtMTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlUmVzZXQoc3RybSkgewogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIHN0YXRlLndzaXplID0gMDsKICAgICAgICBzdGF0ZS53aGF2ZSA9IDA7CiAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgIHJldHVybiBpbmZsYXRlUmVzZXRLZWVwKHN0cm0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVSZXNldDIoc3RybSwgd2luZG93Qml0cykgewogICAgICAgIHZhciB3cmFwOwogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmICh3aW5kb3dCaXRzIDwgMCkgewogICAgICAgICAgd3JhcCA9IDA7CiAgICAgICAgICB3aW5kb3dCaXRzID0gLXdpbmRvd0JpdHM7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHdyYXAgPSAod2luZG93Qml0cyA+PiA0KSArIDE7CiAgICAgICAgICBpZiAod2luZG93Qml0cyA8IDQ4KSB7CiAgICAgICAgICAgIHdpbmRvd0JpdHMgJj0gMTU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICh3aW5kb3dCaXRzICYmICh3aW5kb3dCaXRzIDwgOCB8fCB3aW5kb3dCaXRzID4gMTUpKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmIChzdGF0ZS53aW5kb3cgIT09IG51bGwgJiYgc3RhdGUud2JpdHMgIT09IHdpbmRvd0JpdHMpIHsKICAgICAgICAgIHN0YXRlLndpbmRvdyA9IG51bGw7CiAgICAgICAgfQogICAgICAgIHN0YXRlLndyYXAgPSB3cmFwOwogICAgICAgIHN0YXRlLndiaXRzID0gd2luZG93Qml0czsKICAgICAgICByZXR1cm4gaW5mbGF0ZVJlc2V0KHN0cm0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVJbml0MihzdHJtLCB3aW5kb3dCaXRzKSB7CiAgICAgICAgdmFyIHJldDsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgaWYgKCFzdHJtKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gbmV3IEluZmxhdGVTdGF0ZSgpOwogICAgICAgIHN0cm0uc3RhdGUgPSBzdGF0ZTsKICAgICAgICBzdGF0ZS53aW5kb3cgPSBudWxsOwogICAgICAgIHJldCA9IGluZmxhdGVSZXNldDIoc3RybSwgd2luZG93Qml0cyk7CiAgICAgICAgaWYgKHJldCAhPT0gWl9PSykgewogICAgICAgICAgc3RybS5zdGF0ZSA9IG51bGw7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZUluaXQoc3RybSkgewogICAgICAgIHJldHVybiBpbmZsYXRlSW5pdDIoc3RybSwgREVGX1dCSVRTKTsKICAgICAgfQogICAgICB2YXIgdmlyZ2luID0gdHJ1ZTsKICAgICAgdmFyIGxlbmZpeDsKICAgICAgdmFyIGRpc3RmaXg7CiAgICAgIGZ1bmN0aW9uIGZpeGVkdGFibGVzKHN0YXRlKSB7CiAgICAgICAgaWYgKHZpcmdpbikgewogICAgICAgICAgdmFyIHN5bTsKICAgICAgICAgIGxlbmZpeCA9IG5ldyB1dGlscy5CdWYzMig1MTIpOwogICAgICAgICAgZGlzdGZpeCA9IG5ldyB1dGlscy5CdWYzMigzMik7CiAgICAgICAgICBzeW0gPSAwOwogICAgICAgICAgd2hpbGUgKHN5bSA8IDE0NCkgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDg7CiAgICAgICAgICB9CiAgICAgICAgICB3aGlsZSAoc3ltIDwgMjU2KSB7CiAgICAgICAgICAgIHN0YXRlLmxlbnNbc3ltKytdID0gOTsKICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzeW0gPCAyODApIHsKICAgICAgICAgICAgc3RhdGUubGVuc1tzeW0rK10gPSA3OwogICAgICAgICAgfQogICAgICAgICAgd2hpbGUgKHN5bSA8IDI4OCkgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDg7CiAgICAgICAgICB9CiAgICAgICAgICBpbmZsYXRlX3RhYmxlKExFTlMsIHN0YXRlLmxlbnMsIDAsIDI4OCwgbGVuZml4LCAwLCBzdGF0ZS53b3JrLCB7IGJpdHM6IDkgfSk7CiAgICAgICAgICBzeW0gPSAwOwogICAgICAgICAgd2hpbGUgKHN5bSA8IDMyKSB7CiAgICAgICAgICAgIHN0YXRlLmxlbnNbc3ltKytdID0gNTsKICAgICAgICAgIH0KICAgICAgICAgIGluZmxhdGVfdGFibGUoRElTVFMsIHN0YXRlLmxlbnMsIDAsIDMyLCBkaXN0Zml4LCAwLCBzdGF0ZS53b3JrLCB7IGJpdHM6IDUgfSk7CiAgICAgICAgICB2aXJnaW4gPSBmYWxzZTsKICAgICAgICB9CiAgICAgICAgc3RhdGUubGVuY29kZSA9IGxlbmZpeDsKICAgICAgICBzdGF0ZS5sZW5iaXRzID0gOTsKICAgICAgICBzdGF0ZS5kaXN0Y29kZSA9IGRpc3RmaXg7CiAgICAgICAgc3RhdGUuZGlzdGJpdHMgPSA1OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHVwZGF0ZXdpbmRvdyhzdHJtLCBzcmMsIGVuZCwgY29weSkgewogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgaWYgKHN0YXRlLndpbmRvdyA9PT0gbnVsbCkgewogICAgICAgICAgc3RhdGUud3NpemUgPSAxIDw8IHN0YXRlLndiaXRzOwogICAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgICAgc3RhdGUud2hhdmUgPSAwOwogICAgICAgICAgc3RhdGUud2luZG93ID0gbmV3IHV0aWxzLkJ1Zjgoc3RhdGUud3NpemUpOwogICAgICAgIH0KICAgICAgICBpZiAoY29weSA+PSBzdGF0ZS53c2l6ZSkgewogICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RhdGUud2luZG93LCBzcmMsIGVuZCAtIHN0YXRlLndzaXplLCBzdGF0ZS53c2l6ZSwgMCk7CiAgICAgICAgICBzdGF0ZS53bmV4dCA9IDA7CiAgICAgICAgICBzdGF0ZS53aGF2ZSA9IHN0YXRlLndzaXplOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBkaXN0ID0gc3RhdGUud3NpemUgLSBzdGF0ZS53bmV4dDsKICAgICAgICAgIGlmIChkaXN0ID4gY29weSkgewogICAgICAgICAgICBkaXN0ID0gY29weTsKICAgICAgICAgIH0KICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHN0YXRlLndpbmRvdywgc3JjLCBlbmQgLSBjb3B5LCBkaXN0LCBzdGF0ZS53bmV4dCk7CiAgICAgICAgICBjb3B5IC09IGRpc3Q7CiAgICAgICAgICBpZiAoY29weSkgewogICAgICAgICAgICB1dGlscy5hcnJheVNldChzdGF0ZS53aW5kb3csIHNyYywgZW5kIC0gY29weSwgY29weSwgMCk7CiAgICAgICAgICAgIHN0YXRlLnduZXh0ID0gY29weTsKICAgICAgICAgICAgc3RhdGUud2hhdmUgPSBzdGF0ZS53c2l6ZTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHN0YXRlLnduZXh0ICs9IGRpc3Q7CiAgICAgICAgICAgIGlmIChzdGF0ZS53bmV4dCA9PT0gc3RhdGUud3NpemUpIHsKICAgICAgICAgICAgICBzdGF0ZS53bmV4dCA9IDA7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHN0YXRlLndoYXZlIDwgc3RhdGUud3NpemUpIHsKICAgICAgICAgICAgICBzdGF0ZS53aGF2ZSArPSBkaXN0OwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGUoc3RybSwgZmx1c2gpIHsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgdmFyIGlucHV0LCBvdXRwdXQ7CiAgICAgICAgdmFyIG5leHQ7CiAgICAgICAgdmFyIHB1dDsKICAgICAgICB2YXIgaGF2ZSwgbGVmdDsKICAgICAgICB2YXIgaG9sZDsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgX2luLCBfb3V0OwogICAgICAgIHZhciBjb3B5OwogICAgICAgIHZhciBmcm9tOwogICAgICAgIHZhciBmcm9tX3NvdXJjZTsKICAgICAgICB2YXIgaGVyZSA9IDA7CiAgICAgICAgdmFyIGhlcmVfYml0cywgaGVyZV9vcCwgaGVyZV92YWw7CiAgICAgICAgdmFyIGxhc3RfYml0cywgbGFzdF9vcCwgbGFzdF92YWw7CiAgICAgICAgdmFyIGxlbjsKICAgICAgICB2YXIgcmV0OwogICAgICAgIHZhciBoYnVmID0gbmV3IHV0aWxzLkJ1ZjgoNCk7CiAgICAgICAgdmFyIG9wdHM7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIG9yZGVyID0gWzE2LCAxNywgMTgsIDAsIDgsIDcsIDksIDYsIDEwLCA1LCAxMSwgNCwgMTIsIDMsIDEzLCAyLCAxNCwgMSwgMTVdOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSB8fCAhc3RybS5vdXRwdXQgfHwgIXN0cm0uaW5wdXQgJiYgc3RybS5hdmFpbF9pbiAhPT0gMCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IFRZUEUpIHsKICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFRE87CiAgICAgICAgfQogICAgICAgIHB1dCA9IHN0cm0ubmV4dF9vdXQ7CiAgICAgICAgb3V0cHV0ID0gc3RybS5vdXRwdXQ7CiAgICAgICAgbGVmdCA9IHN0cm0uYXZhaWxfb3V0OwogICAgICAgIG5leHQgPSBzdHJtLm5leHRfaW47CiAgICAgICAgaW5wdXQgPSBzdHJtLmlucHV0OwogICAgICAgIGhhdmUgPSBzdHJtLmF2YWlsX2luOwogICAgICAgIGhvbGQgPSBzdGF0ZS5ob2xkOwogICAgICAgIGJpdHMgPSBzdGF0ZS5iaXRzOwogICAgICAgIF9pbiA9IGhhdmU7CiAgICAgICAgX291dCA9IGxlZnQ7CiAgICAgICAgcmV0ID0gWl9PSzsKICAgICAgICBpbmZfbGVhdmU6CiAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgc3dpdGNoIChzdGF0ZS5tb2RlKSB7CiAgICAgICAgICAgICAgY2FzZSBIRUFEOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLndyYXAgPT09IDApIHsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRZUEVETzsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwICYgMiAmJiBob2xkID09PSAzNTYxNSkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IDA7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEZMQUdTOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmZsYWdzID0gMDsKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZG9uZSA9IGZhbHNlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKCEoc3RhdGUud3JhcCAmIDEpIHx8ICgoKGhvbGQgJiAyNTUpIDw8IDgpICsgKGhvbGQgPj4gOCkpICUgMzEpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW5jb3JyZWN0IGhlYWRlciBjaGVjayI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKChob2xkICYgMTUpICE9PSBaX0RFRkxBVEVEKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gInVua25vd24gY29tcHJlc3Npb24gbWV0aG9kIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gNDsKICAgICAgICAgICAgICAgIGJpdHMgLT0gNDsKICAgICAgICAgICAgICAgIGxlbiA9IChob2xkICYgMTUpICsgODsKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53Yml0cyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS53Yml0cyA9IGxlbjsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAobGVuID4gc3RhdGUud2JpdHMpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCB3aW5kb3cgc2l6ZSI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZG1heCA9IDEgPDwgbGVuOwogICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLmNoZWNrID0gMTsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBob2xkICYgNTEyID8gRElDVElEIDogVFlQRTsKICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIEZMQUdTOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5mbGFncyA9IGhvbGQ7CiAgICAgICAgICAgICAgICBpZiAoKHN0YXRlLmZsYWdzICYgMjU1KSAhPT0gWl9ERUZMQVRFRCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJ1bmtub3duIGNvbXByZXNzaW9uIG1ldGhvZCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTczNDQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAidW5rbm93biBoZWFkZXIgZmxhZ3Mgc2V0IjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLnRleHQgPSBob2xkID4+IDggJiAxOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRJTUU7CiAgICAgICAgICAgICAgY2FzZSBUSU1FOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLnRpbWUgPSBob2xkOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlsyXSA9IGhvbGQgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzNdID0gaG9sZCA+Pj4gMjQgJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGhidWYsIDQsIDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBPUzsKICAgICAgICAgICAgICBjYXNlIE9TOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLnhmbGFncyA9IGhvbGQgJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQub3MgPSBob2xkID4+IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1MTIpIHsKICAgICAgICAgICAgICAgICAgaGJ1ZlswXSA9IGhvbGQgJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhidWZbMV0gPSBob2xkID4+PiA4ICYgMjU1OwogICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IGNyYzMyKHN0YXRlLmNoZWNrLCBoYnVmLCAyLCAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gRVhMRU47CiAgICAgICAgICAgICAgY2FzZSBFWExFTjoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDEwMjQpIHsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgc3RhdGUubGVuZ3RoID0gaG9sZDsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmV4dHJhX2xlbiA9IGhvbGQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgICAgaGJ1ZlswXSA9IGhvbGQgJiAyNTU7CiAgICAgICAgICAgICAgICAgICAgaGJ1ZlsxXSA9IGhvbGQgPj4+IDggJiAyNTU7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZXh0cmEgPSBudWxsOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEVYVFJBOwogICAgICAgICAgICAgIGNhc2UgRVhUUkE6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiAxMDI0KSB7CiAgICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gaGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBoYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IHN0YXRlLmhlYWQuZXh0cmFfbGVuIC0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgICAgICAgaWYgKCFzdGF0ZS5oZWFkLmV4dHJhKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZXh0cmEgPSBuZXcgQXJyYXkoc3RhdGUuaGVhZC5leHRyYV9sZW4pOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RhdGUuaGVhZC5leHRyYSwgaW5wdXQsIG5leHQsIGNvcHksIGxlbik7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaW5wdXQsIGNvcHksIG5leHQpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlIC09IGNvcHk7CiAgICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCAtPSBjb3B5OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTkFNRTsKICAgICAgICAgICAgICBjYXNlIE5BTUU6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiAyMDQ4KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGNvcHkgPSAwOwogICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgbGVuID0gaW5wdXRbbmV4dCArIGNvcHkrK107CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQgJiYgbGVuICYmIHN0YXRlLmxlbmd0aCA8IDY1NTM2KSB7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLm5hbWUgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShsZW4pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfSB3aGlsZSAobGVuICYmIGNvcHkgPCBoYXZlKTsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaW5wdXQsIGNvcHksIG5leHQpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUgLT0gY29weTsKICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5uYW1lID0gbnVsbDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQ09NTUVOVDsKICAgICAgICAgICAgICBjYXNlIENPTU1FTlQ6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA0MDk2KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGNvcHkgPSAwOwogICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgbGVuID0gaW5wdXRbbmV4dCArIGNvcHkrK107CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQgJiYgbGVuICYmIHN0YXRlLmxlbmd0aCA8IDY1NTM2KSB7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmNvbW1lbnQgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShsZW4pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfSB3aGlsZSAobGVuICYmIGNvcHkgPCBoYXZlKTsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaW5wdXQsIGNvcHksIG5leHQpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUgLT0gY29weTsKICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5jb21tZW50ID0gbnVsbDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBIQ1JDOwogICAgICAgICAgICAgIGNhc2UgSENSQzoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoaG9sZCAhPT0gKHN0YXRlLmNoZWNrICYgNjU1MzUpKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaGVhZGVyIGNyYyBtaXNtYXRjaCI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmhjcmMgPSBzdGF0ZS5mbGFncyA+PiA5ICYgMTsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5kb25lID0gdHJ1ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgRElDVElEOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSB6c3dhcDMyKGhvbGQpOwogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBESUNUOwogICAgICAgICAgICAgIGNhc2UgRElDVDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oYXZlZGljdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gcHV0OwogICAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGxlZnQ7CiAgICAgICAgICAgICAgICAgIHN0cm0ubmV4dF9pbiA9IG5leHQ7CiAgICAgICAgICAgICAgICAgIHN0cm0uYXZhaWxfaW4gPSBoYXZlOwogICAgICAgICAgICAgICAgICBzdGF0ZS5ob2xkID0gaG9sZDsKICAgICAgICAgICAgICAgICAgc3RhdGUuYml0cyA9IGJpdHM7CiAgICAgICAgICAgICAgICAgIHJldHVybiBaX05FRURfRElDVDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IDE7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICBjYXNlIFRZUEU6CiAgICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfQkxPQ0sgfHwgZmx1c2ggPT09IFpfVFJFRVMpIHsKICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGNhc2UgVFlQRURPOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmxhc3QpIHsKICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgICBiaXRzIC09IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQ0hFQ0s7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzKSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxhc3QgPSBob2xkICYgMTsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAxOwogICAgICAgICAgICAgICAgYml0cyAtPSAxOwogICAgICAgICAgICAgICAgc3dpdGNoIChob2xkICYgMykgewogICAgICAgICAgICAgICAgICBjYXNlIDA6CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFNUT1JFRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgICAgICAgIGZpeGVkdGFibGVzKHN0YXRlKTsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOXzsKICAgICAgICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfVFJFRVMpIHsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAyOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSAyOwogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUQUJMRTsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAzOgogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYmxvY2sgdHlwZSI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAyOwogICAgICAgICAgICAgICAgYml0cyAtPSAyOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBTVE9SRUQ6CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gYml0cyAmIDc7CiAgICAgICAgICAgICAgICBiaXRzIC09IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoKGhvbGQgJiA2NTUzNSkgIT09IChob2xkID4+PiAxNiBeIDY1NTM1KSkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIHN0b3JlZCBibG9jayBsZW5ndGhzIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSBob2xkICYgNjU1MzU7CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENPUFlfOwogICAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX1RSRUVTKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBjYXNlIENPUFlfOgogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENPUFk7CiAgICAgICAgICAgICAgY2FzZSBDT1BZOgogICAgICAgICAgICAgICAgY29weSA9IHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgIGlmIChjb3B5KSB7CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gaGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBoYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gbGVmdCkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBsZWZ0OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KG91dHB1dCwgaW5wdXQsIG5leHQsIGNvcHksIHB1dCk7CiAgICAgICAgICAgICAgICAgIGhhdmUgLT0gY29weTsKICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBsZWZ0IC09IGNvcHk7CiAgICAgICAgICAgICAgICAgIHB1dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgVEFCTEU6CiAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE0KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm5sZW4gPSAoaG9sZCAmIDMxKSArIDI1NzsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA1OwogICAgICAgICAgICAgICAgYml0cyAtPSA1OwogICAgICAgICAgICAgICAgc3RhdGUubmRpc3QgPSAoaG9sZCAmIDMxKSArIDE7CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gNTsKICAgICAgICAgICAgICAgIGJpdHMgLT0gNTsKICAgICAgICAgICAgICAgIHN0YXRlLm5jb2RlID0gKGhvbGQgJiAxNSkgKyA0OwogICAgICAgICAgICAgICAgaG9sZCA+Pj49IDQ7CiAgICAgICAgICAgICAgICBiaXRzIC09IDQ7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubmxlbiA+IDI4NiB8fCBzdGF0ZS5uZGlzdCA+IDMwKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gInRvbyBtYW55IGxlbmd0aCBvciBkaXN0YW5jZSBzeW1ib2xzIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5oYXZlID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU5MRU5TOwogICAgICAgICAgICAgIGNhc2UgTEVOTEVOUzoKICAgICAgICAgICAgICAgIHdoaWxlIChzdGF0ZS5oYXZlIDwgc3RhdGUubmNvZGUpIHsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW29yZGVyW3N0YXRlLmhhdmUrK11dID0gaG9sZCAmIDc7CiAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAzOwogICAgICAgICAgICAgICAgICBiaXRzIC09IDM7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB3aGlsZSAoc3RhdGUuaGF2ZSA8IDE5KSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbnNbb3JkZXJbc3RhdGUuaGF2ZSsrXV0gPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubGVuY29kZSA9IHN0YXRlLmxlbmR5bjsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSA3OwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUubGVuYml0cyB9OwogICAgICAgICAgICAgICAgcmV0ID0gaW5mbGF0ZV90YWJsZShDT0RFUywgc3RhdGUubGVucywgMCwgMTksIHN0YXRlLmxlbmNvZGUsIDAsIHN0YXRlLndvcmssIG9wdHMpOwogICAgICAgICAgICAgICAgc3RhdGUubGVuYml0cyA9IG9wdHMuYml0czsKICAgICAgICAgICAgICAgIGlmIChyZXQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBjb2RlIGxlbmd0aHMgc2V0IjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5oYXZlID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBDT0RFTEVOUzsKICAgICAgICAgICAgICBjYXNlIENPREVMRU5TOgogICAgICAgICAgICAgICAgd2hpbGUgKHN0YXRlLmhhdmUgPCBzdGF0ZS5ubGVuICsgc3RhdGUubmRpc3QpIHsKICAgICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgICAgaGVyZSA9IHN0YXRlLmxlbmNvZGVbaG9sZCAmICgxIDw8IHN0YXRlLmxlbmJpdHMpIC0gMV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGhlcmVfdmFsIDwgMTYpIHsKICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbnNbc3RhdGUuaGF2ZSsrXSA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIGlmIChoZXJlX3ZhbCA9PT0gMTYpIHsKICAgICAgICAgICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyAyOwogICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYml0IGxlbmd0aCByZXBlYXQiOwogICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IHN0YXRlLmxlbnNbc3RhdGUuaGF2ZSAtIDFdOwogICAgICAgICAgICAgICAgICAgICAgY29weSA9IDMgKyAoaG9sZCAmIDMpOwogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IDI7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IDI7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChoZXJlX3ZhbCA9PT0gMTcpIHsKICAgICAgICAgICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyAzOwogICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IDA7CiAgICAgICAgICAgICAgICAgICAgICBjb3B5ID0gMyArIChob2xkICYgNyk7CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gMzsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gMzsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgbiA9IGhlcmVfYml0cyArIDc7CiAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgICAgbGVuID0gMDsKICAgICAgICAgICAgICAgICAgICAgIGNvcHkgPSAxMSArIChob2xkICYgMTI3KTsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA3OwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSA3OwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGF2ZSArIGNvcHkgPiBzdGF0ZS5ubGVuICsgc3RhdGUubmRpc3QpIHsKICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYml0IGxlbmd0aCByZXBlYXQiOwogICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB3aGlsZSAoY29weS0tKSB7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW3N0YXRlLmhhdmUrK10gPSBsZW47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubW9kZSA9PT0gQkFEKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmxlbnNbMjU2XSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGNvZGUgLS0gbWlzc2luZyBlbmQtb2YtYmxvY2siOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSA5OwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUubGVuYml0cyB9OwogICAgICAgICAgICAgICAgcmV0ID0gaW5mbGF0ZV90YWJsZShMRU5TLCBzdGF0ZS5sZW5zLCAwLCBzdGF0ZS5ubGVuLCBzdGF0ZS5sZW5jb2RlLCAwLCBzdGF0ZS53b3JrLCBvcHRzKTsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSBvcHRzLmJpdHM7CiAgICAgICAgICAgICAgICBpZiAocmV0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgbGl0ZXJhbC9sZW5ndGhzIHNldCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZGlzdGJpdHMgPSA2OwogICAgICAgICAgICAgICAgc3RhdGUuZGlzdGNvZGUgPSBzdGF0ZS5kaXN0ZHluOwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUuZGlzdGJpdHMgfTsKICAgICAgICAgICAgICAgIHJldCA9IGluZmxhdGVfdGFibGUoRElTVFMsIHN0YXRlLmxlbnMsIHN0YXRlLm5sZW4sIHN0YXRlLm5kaXN0LCBzdGF0ZS5kaXN0Y29kZSwgMCwgc3RhdGUud29yaywgb3B0cyk7CiAgICAgICAgICAgICAgICBzdGF0ZS5kaXN0Yml0cyA9IG9wdHMuYml0czsKICAgICAgICAgICAgICAgIGlmIChyZXQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZXMgc2V0IjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOXzsKICAgICAgICAgICAgICAgIGlmIChmbHVzaCA9PT0gWl9UUkVFUykgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgY2FzZSBMRU5fOgogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTjsKICAgICAgICAgICAgICBjYXNlIExFTjoKICAgICAgICAgICAgICAgIGlmIChoYXZlID49IDYgJiYgbGVmdCA+PSAyNTgpIHsKICAgICAgICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBsZWZ0OwogICAgICAgICAgICAgICAgICBzdHJtLm5leHRfaW4gPSBuZXh0OwogICAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX2luID0gaGF2ZTsKICAgICAgICAgICAgICAgICAgc3RhdGUuaG9sZCA9IGhvbGQ7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzOwogICAgICAgICAgICAgICAgICBpbmZsYXRlX2Zhc3Qoc3RybSwgX291dCk7CiAgICAgICAgICAgICAgICAgIHB1dCA9IHN0cm0ubmV4dF9vdXQ7CiAgICAgICAgICAgICAgICAgIG91dHB1dCA9IHN0cm0ub3V0cHV0OwogICAgICAgICAgICAgICAgICBsZWZ0ID0gc3RybS5hdmFpbF9vdXQ7CiAgICAgICAgICAgICAgICAgIG5leHQgPSBzdHJtLm5leHRfaW47CiAgICAgICAgICAgICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICAgICAgICAgICAgaGF2ZSA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgICAgICAgICAgIGhvbGQgPSBzdGF0ZS5ob2xkOwogICAgICAgICAgICAgICAgICBiaXRzID0gc3RhdGUuYml0czsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IFRZUEUpIHsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gLTE7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gMDsKICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUubGVuY29kZVtob2xkICYgKDEgPDwgc3RhdGUubGVuYml0cykgLSAxXTsKICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgIGhlcmVfb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGVyZV92YWwgPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICAgIGlmIChoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChoZXJlX29wICYmIChoZXJlX29wICYgMjQwKSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBsYXN0X2JpdHMgPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgIGxhc3Rfb3AgPSBoZXJlX29wOwogICAgICAgICAgICAgICAgICBsYXN0X3ZhbCA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUubGVuY29kZVtsYXN0X3ZhbCArICgoaG9sZCAmICgxIDw8IGxhc3RfYml0cyArIGxhc3Rfb3ApIC0gMSkgPj4gbGFzdF9iaXRzKV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChsYXN0X2JpdHMgKyBoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGxhc3RfYml0czsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgc3RhdGUuYmFjayArPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSBoZXJlX3ZhbDsKICAgICAgICAgICAgICAgIGlmIChoZXJlX29wID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMSVQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKGhlcmVfb3AgJiAzMikgewogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gLTE7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChoZXJlX29wICYgNjQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBsaXRlcmFsL2xlbmd0aCBjb2RlIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5leHRyYSA9IGhlcmVfb3AgJiAxNTsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU5FWFQ7CiAgICAgICAgICAgICAgY2FzZSBMRU5FWFQ6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZXh0cmEpIHsKICAgICAgICAgICAgICAgICAgbiA9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCArPSBob2xkICYgKDEgPDwgc3RhdGUuZXh0cmEpIC0gMTsKICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBiaXRzIC09IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrICs9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUud2FzID0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IERJU1Q7CiAgICAgICAgICAgICAgY2FzZSBESVNUOgogICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgIGhlcmUgPSBzdGF0ZS5kaXN0Y29kZVtob2xkICYgKDEgPDwgc3RhdGUuZGlzdGJpdHMpIC0gMV07CiAgICAgICAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICBoZXJlX29wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICBpZiAoaGVyZV9iaXRzIDw9IGJpdHMpIHsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoKGhlcmVfb3AgJiAyNDApID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGxhc3RfYml0cyA9IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgbGFzdF9vcCA9IGhlcmVfb3A7CiAgICAgICAgICAgICAgICAgIGxhc3RfdmFsID0gaGVyZV92YWw7CiAgICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICAgIGhlcmUgPSBzdGF0ZS5kaXN0Y29kZVtsYXN0X3ZhbCArICgoaG9sZCAmICgxIDw8IGxhc3RfYml0cyArIGxhc3Rfb3ApIC0gMSkgPj4gbGFzdF9iaXRzKV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChsYXN0X2JpdHMgKyBoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGxhc3RfYml0czsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgc3RhdGUuYmFjayArPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBpZiAoaGVyZV9vcCAmIDY0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgY29kZSI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUub2Zmc2V0ID0gaGVyZV92YWw7CiAgICAgICAgICAgICAgICBzdGF0ZS5leHRyYSA9IGhlcmVfb3AgJiAxNTsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBESVNURVhUOwogICAgICAgICAgICAgIGNhc2UgRElTVEVYVDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5leHRyYSkgewogICAgICAgICAgICAgICAgICBuID0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgbikgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgc3RhdGUub2Zmc2V0ICs9IGhvbGQgJiAoMSA8PCBzdGF0ZS5leHRyYSkgLSAxOwogICAgICAgICAgICAgICAgICBob2xkID4+Pj0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIGJpdHMgLT0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUub2Zmc2V0ID4gc3RhdGUuZG1heCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IE1BVENIOwogICAgICAgICAgICAgIGNhc2UgTUFUQ0g6CiAgICAgICAgICAgICAgICBpZiAobGVmdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBjb3B5ID0gX291dCAtIGxlZnQ7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUub2Zmc2V0ID4gY29weSkgewogICAgICAgICAgICAgICAgICBjb3B5ID0gc3RhdGUub2Zmc2V0IC0gY29weTsKICAgICAgICAgICAgICAgICAgaWYgKGNvcHkgPiBzdGF0ZS53aGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5zYW5lKSB7CiAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gc3RhdGUud25leHQpIHsKICAgICAgICAgICAgICAgICAgICBjb3B5IC09IHN0YXRlLnduZXh0OwogICAgICAgICAgICAgICAgICAgIGZyb20gPSBzdGF0ZS53c2l6ZSAtIGNvcHk7CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgZnJvbSA9IHN0YXRlLnduZXh0IC0gY29weTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoY29weSA+IHN0YXRlLmxlbmd0aCkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBzdGF0ZS53aW5kb3c7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgZnJvbSA9IHB1dCAtIHN0YXRlLm9mZnNldDsKICAgICAgICAgICAgICAgICAgY29weSA9IHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gbGVmdCkgewogICAgICAgICAgICAgICAgICBjb3B5ID0gbGVmdDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGxlZnQgLT0gY29weTsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCAtPSBjb3B5OwogICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICBvdXRwdXRbcHV0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tY29weSk7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIExJVDoKICAgICAgICAgICAgICAgIGlmIChsZWZ0ID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIG91dHB1dFtwdXQrK10gPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICBsZWZ0LS07CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBDSEVDSzoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCB8PSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIF9vdXQgLT0gbGVmdDsKICAgICAgICAgICAgICAgICAgc3RybS50b3RhbF9vdXQgKz0gX291dDsKICAgICAgICAgICAgICAgICAgc3RhdGUudG90YWwgKz0gX291dDsKICAgICAgICAgICAgICAgICAgaWYgKF9vdXQpIHsKICAgICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSBzdGF0ZS5mbGFncyA/IGNyYzMyKHN0YXRlLmNoZWNrLCBvdXRwdXQsIF9vdXQsIHB1dCAtIF9vdXQpIDogYWRsZXIzMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBwdXQgLSBfb3V0KTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBfb3V0ID0gbGVmdDsKICAgICAgICAgICAgICAgICAgaWYgKChzdGF0ZS5mbGFncyA/IGhvbGQgOiB6c3dhcDMyKGhvbGQpKSAhPT0gc3RhdGUuY2hlY2spIHsKICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbmNvcnJlY3QgZGF0YSBjaGVjayI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOR1RIOwogICAgICAgICAgICAgIGNhc2UgTEVOR1RIOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLndyYXAgJiYgc3RhdGUuZmxhZ3MpIHsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGhvbGQgIT09IChzdGF0ZS50b3RhbCAmIDQyOTQ5NjcyOTUpKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW5jb3JyZWN0IGxlbmd0aCBjaGVjayI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gRE9ORTsKICAgICAgICAgICAgICBjYXNlIERPTkU6CiAgICAgICAgICAgICAgICByZXQgPSBaX1NUUkVBTV9FTkQ7CiAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgY2FzZSBCQUQ6CiAgICAgICAgICAgICAgICByZXQgPSBaX0RBVEFfRVJST1I7CiAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgY2FzZSBNRU06CiAgICAgICAgICAgICAgICByZXR1cm4gWl9NRU1fRVJST1I7CiAgICAgICAgICAgICAgY2FzZSBTWU5DOgogICAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICBzdHJtLm5leHRfb3V0ID0gcHV0OwogICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gbGVmdDsKICAgICAgICBzdHJtLm5leHRfaW4gPSBuZXh0OwogICAgICAgIHN0cm0uYXZhaWxfaW4gPSBoYXZlOwogICAgICAgIHN0YXRlLmhvbGQgPSBob2xkOwogICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzOwogICAgICAgIGlmIChzdGF0ZS53c2l6ZSB8fCBfb3V0ICE9PSBzdHJtLmF2YWlsX291dCAmJiBzdGF0ZS5tb2RlIDwgQkFEICYmIChzdGF0ZS5tb2RlIDwgQ0hFQ0sgfHwgZmx1c2ggIT09IFpfRklOSVNIKSkgewogICAgICAgICAgaWYgKHVwZGF0ZXdpbmRvdyhzdHJtLCBzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCwgX291dCAtIHN0cm0uYXZhaWxfb3V0KSkgewogICAgICAgICAgICBzdGF0ZS5tb2RlID0gTUVNOwogICAgICAgICAgICByZXR1cm4gWl9NRU1fRVJST1I7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIF9pbiAtPSBzdHJtLmF2YWlsX2luOwogICAgICAgIF9vdXQgLT0gc3RybS5hdmFpbF9vdXQ7CiAgICAgICAgc3RybS50b3RhbF9pbiArPSBfaW47CiAgICAgICAgc3RybS50b3RhbF9vdXQgKz0gX291dDsKICAgICAgICBzdGF0ZS50b3RhbCArPSBfb3V0OwogICAgICAgIGlmIChzdGF0ZS53cmFwICYmIF9vdXQpIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IHN0YXRlLmZsYWdzID8gY3JjMzIoc3RhdGUuY2hlY2ssIG91dHB1dCwgX291dCwgc3RybS5uZXh0X291dCAtIF9vdXQpIDogYWRsZXIzMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBzdHJtLm5leHRfb3V0IC0gX291dCk7CiAgICAgICAgfQogICAgICAgIHN0cm0uZGF0YV90eXBlID0gc3RhdGUuYml0cyArIChzdGF0ZS5sYXN0ID8gNjQgOiAwKSArIChzdGF0ZS5tb2RlID09PSBUWVBFID8gMTI4IDogMCkgKyAoc3RhdGUubW9kZSA9PT0gTEVOXyB8fCBzdGF0ZS5tb2RlID09PSBDT1BZXyA/IDI1NiA6IDApOwogICAgICAgIGlmICgoX2luID09PSAwICYmIF9vdXQgPT09IDAgfHwgZmx1c2ggPT09IFpfRklOSVNIKSAmJiByZXQgPT09IFpfT0spIHsKICAgICAgICAgIHJldCA9IFpfQlVGX0VSUk9SOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmV0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVFbmQoc3RybSkgewogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICB2YXIgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS53aW5kb3cpIHsKICAgICAgICAgIHN0YXRlLndpbmRvdyA9IG51bGw7CiAgICAgICAgfQogICAgICAgIHN0cm0uc3RhdGUgPSBudWxsOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVHZXRIZWFkZXIoc3RybSwgaGVhZCkgewogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmICgoc3RhdGUud3JhcCAmIDIpID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlLmhlYWQgPSBoZWFkOwogICAgICAgIGhlYWQuZG9uZSA9IGZhbHNlOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVTZXREaWN0aW9uYXJ5KHN0cm0sIGRpY3Rpb25hcnkpIHsKICAgICAgICB2YXIgZGljdExlbmd0aCA9IGRpY3Rpb25hcnkubGVuZ3RoOwogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICB2YXIgZGljdGlkOwogICAgICAgIHZhciByZXQ7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAoc3RhdGUud3JhcCAhPT0gMCAmJiBzdGF0ZS5tb2RlICE9PSBESUNUKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmIChzdGF0ZS5tb2RlID09PSBESUNUKSB7CiAgICAgICAgICBkaWN0aWQgPSAxOwogICAgICAgICAgZGljdGlkID0gYWRsZXIzMihkaWN0aWQsIGRpY3Rpb25hcnksIGRpY3RMZW5ndGgsIDApOwogICAgICAgICAgaWYgKGRpY3RpZCAhPT0gc3RhdGUuY2hlY2spIHsKICAgICAgICAgICAgcmV0dXJuIFpfREFUQV9FUlJPUjsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0ID0gdXBkYXRld2luZG93KHN0cm0sIGRpY3Rpb25hcnksIGRpY3RMZW5ndGgsIGRpY3RMZW5ndGgpOwogICAgICAgIGlmIChyZXQpIHsKICAgICAgICAgIHN0YXRlLm1vZGUgPSBNRU07CiAgICAgICAgICByZXR1cm4gWl9NRU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlLmhhdmVkaWN0ID0gMTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBleHBvcnRzMi5pbmZsYXRlUmVzZXQgPSBpbmZsYXRlUmVzZXQ7CiAgICAgIGV4cG9ydHMyLmluZmxhdGVSZXNldDIgPSBpbmZsYXRlUmVzZXQyOwogICAgICBleHBvcnRzMi5pbmZsYXRlUmVzZXRLZWVwID0gaW5mbGF0ZVJlc2V0S2VlcDsKICAgICAgZXhwb3J0czIuaW5mbGF0ZUluaXQgPSBpbmZsYXRlSW5pdDsKICAgICAgZXhwb3J0czIuaW5mbGF0ZUluaXQyID0gaW5mbGF0ZUluaXQyOwogICAgICBleHBvcnRzMi5pbmZsYXRlID0gaW5mbGF0ZTsKICAgICAgZXhwb3J0czIuaW5mbGF0ZUV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UFJFU1NJT046IDAsCiAgICAgICAgWl9CRVNUX1NQRUVEOiAxLAogICAgICAgIFpfQkVTVF9DT01QUkVTU0lPTjogOSwKICAgICAgICBaX0RFRkFVTFRfQ09NUFJFU1NJT046IC0xLAogICAgICAgIFpfRklMVEVSRUQ6IDEsCiAgICAgICAgWl9IVUZGTUFOX09OTFk6IDIsCiAgICAgICAgWl9STEU6IDMsCiAgICAgICAgWl9GSVhFRDogNCwKICAgICAgICBaX0RFRkFVTFRfU1RSQVRFR1k6IDAsCiAgICAgICAgWl9CSU5BUlk6IDAsCiAgICAgICAgWl9URVhUOiAxLAogICAgICAgIFpfVU5LTk9XTjogMiwKICAgICAgICBaX0RFRkxBVEVEOiA4CiAgICAgIH07CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9nemhlYWRlci5qcwogIHZhciByZXF1aXJlX2d6aGVhZGVyID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2d6aGVhZGVyLmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgZnVuY3Rpb24gR1poZWFkZXIoKSB7CiAgICAgICAgdGhpcy50ZXh0ID0gMDsKICAgICAgICB0aGlzLnRpbWUgPSAwOwogICAgICAgIHRoaXMueGZsYWdzID0gMDsKICAgICAgICB0aGlzLm9zID0gMDsKICAgICAgICB0aGlzLmV4dHJhID0gbnVsbDsKICAgICAgICB0aGlzLmV4dHJhX2xlbiA9IDA7CiAgICAgICAgdGhpcy5uYW1lID0gIiI7CiAgICAgICAgdGhpcy5jb21tZW50ID0gIiI7CiAgICAgICAgdGhpcy5oY3JjID0gMDsKICAgICAgICB0aGlzLmRvbm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ICAgdG86ICIiCiAgICAgICAgfSwgb3B0aW9ucyB8fCB7fSk7CiAgICAgICAgdmFyIG9wdCA9IHRoaXMub3B0aW9uczsKICAgICAgICBpZiAob3B0LnJhdyAmJiBvcHQud2luZG93Qml0cyA+PSAwICYmIG9wdC53aW5kb3dCaXRzIDwgMTYpIHsKICAgICAgICAgIG9wdC53aW5kb3dCaXRzID0gLW9wdC53aW5kb3dCaXRzOwogICAgICAgICAgaWYgKG9wdC53aW5kb3dCaXRzID09PSAwKSB7CiAgICAgICAgICAgIG9wdC53aW5kb3dCaXRzID0gLTE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAob3B0LndpbmRvd0JpdHMgPj0gMCAmJiBvcHQud2luZG93Qml0cyA8IDE2ICYmICEob3B0aW9ucyAmJiBvcHRpb25zLndpbmRvd0JpdHMpKSB7CiAgICAgICAgICBvcHQud2luZG93Qml0cyArPSAzMjsKICAgICAgICB9CiAgICAgICAgaWYgKG9wdC53aW5kb3dCaXRzID4gMTUgJiYgb3B0LndpbmRvd0JpdHMgPCA0OCkgewogICAgICAgICAgaWYgKChvcHQud2luZG93Qml0cyAmIDE1KSA9PT0gMCkgewogICAgICAgICAgICBvcHQud2luZG93Qml0cyB8PSAxNTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdGhpcy5lcnIgPSAwOwogICAgICAgIHRoaXMubXNnID0gIiI7CiAgICAgICAgdGhpcy5lbmRlZCA9IGZhbHNlOwogICAgICAgIHRoaXMuY2h1bmtzID0gW107CiAgICAgICAgdGhpcy5zdHJtID0gbmV3IFpTdHJlYW0oKTsKICAgICAgICB0aGlzLnN0cm0uYXZhaWxfb3V0ID0gMDsKICAgICAgICB2YXIgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGVJbml0Mih0aGlzLnN0cm0sIG9wdC53aW5kb3dCaXRzKTsKICAgICAgICBpZiAoc3RhdHVzICE9PSBjLlpfT0spIHsKICAgICAgICAgIHRocm93IG5ldyBF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cnk7CiAgICAgICAgdmFyIHN0YXR1cywgX21vZGU7CiAgICAgICAgdmFyIG5leHRfb3V0X3V0ZjgsIHRhaWwsIHV0ZjhzdHI7CiAgICAgICAgdmFyIGFsbG93QnVmRXJyb3IgPSBmYWxzZTsKICAgICAgICBpZiAodGhpcy5lbmRlZCkgewogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgICBfbW9kZSA9IG1vZGUgPT09IH5+bW9kZSA/IG1vZGUgOiBtb2RlID09PSB0cnVlID8gYy5aX0ZJTklTSCA6IGMuWl9OT19GTFVTSDsKICAgICAgICBpZiAodHlwZW9mIGRhdGEgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICBzdHJtLmlucHV0ID0gc3RyaW5ncy5iaW5zdHJpbmcyYnVmKGRhdGEpOwogICAgICAgIH0gZWxzZSBpZiAodG9TdHJpbmcuY2FsbChkYXRhKSA9PT0gIltvYmplY3QgQXJyYXlCdWZmZXJdIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IG5ldyBVaW50OEFycmF5KGRhdGEpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzdHJtLmlucHV0ID0gZGF0YTsKICAgICAgICB9CiAgICAgICAgc3RybS5uZXh0X2luID0gMDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gc3RybS5pbnB1dC5sZW5ndGg7CiAgICAgICAgZG8gewogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHN0cm0ub3V0cHV0ID0gbmV3IHV0aWxzLkJ1ZjgoY2h1bmtTaXplKTsKICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IDA7CiAgICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gY2h1bmtTaXplOwogICAgICAgICAgfQogICAgICAgICAgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGUoc3RybSwgYy5aX05PX0ZMVVNIKTsKICAgICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9ORUVEX0RJQ1QgJiYgZGljdGlvbmFyeSkgewogICAgICAgICAgICBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZVNldERpY3Rpb25hcnkodGhpcy5zdHJtLCBkaWN0aW9uYXJ5KTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9CVUZfRVJST1IgJiYgYWxsb3dCdWZFcnJvciA9PT0gdHJ1ZSkgewogICAgICAgICAgICBzdGF0dXMgPSBjLlpfT0s7CiAgICAgICAgICAgIGFsbG93QnVmRXJyb3IgPSBmYWxzZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdGF0dXMgIT09IGMuWl9TVFJFQU1fRU5EICYmIHN0YXR1cyAhPT0gYy5aX09LKSB7CiAgICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgICAgdGhpcy5lbmRlZCA9IHRydWU7CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdHJtLm5leHRfb3V0KSB7CiAgICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCB8fCBzdGF0dXMgPT09IGMuWl9TVFJFQU1fRU5EIHx8IHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgKF9tb2RlID09PSBjLlpfRklOSVNIIHx8IF9tb2RlID09PSBjLlpfU1lOQ19GTFVTSCkpIHsKICAgICAgICAgICAgICBpZiAodGhpcy5vcHRpb25zLnRvID09PSAic3RyaW5nIikgewogICAgICAgICAgICAgICAgbmV4dF9vdXRfdXRmOCA9IHN0cmluZ3MudXRmOGJvcmRlcihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCk7CiAgICAgICAgICAgICAgICB0YWlsID0gc3RybS5uZXh0X291dCAtIG5leHRfb3V0X3V0Zjg7CiAgICAgICAgICAgICAgICB1dGY4c3RyID0gc3RyaW5ncy5idWYyc3RyaW5nKHN0cm0ub3V0cHV0LCBuZXh0X291dF91dGY4KTsKICAgICAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSB0YWlsOwogICAgICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBjaHVua1NpemUgLSB0YWlsOwogICAgICAgICAgICAgICAgaWYgKHRhaWwpIHsKICAgICAgICAgICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RybS5vdXRwdXQsIHN0cm0ub3V0cHV0LCBuZXh0X291dF91dGY4LCB0YWlsLCAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0ZjhzdHIpOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0aGlzLm9uRGF0YSh1dGlscy5zaHJpbmtCdWYoc3RybS5vdXRwdXQsIHN0cm0ubmV4dF9vdXQpKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdHJtLmF2YWlsX2luID09PSAwICYmIHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIGFsbG93QnVmRXJyb3IgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKChzdHJtLmF2YWlsX2luID4gMCB8fCBzdHJtLmF2YWlsX291dCA9PT0gMCkgJiYgc3RhdHVzICE9PSBjLlpfU1RSRUFNX0VORCk7CiAgICAgICAgaWYgKHN0YXR1cyA9PT0gYy5aX1NUUkVBTV9FTkQpIHsKICAgICAgICAgIF9tb2RlID0gYy5aX0ZJTklTSDsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBjLlpfRklOSVNIKSB7CiAgICAgICAgICBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZUVuZCh0aGlzLnN0cm0pOwogICAgICAgICAgdGhpcy5vbkVuZChzdGF0dXMpOwogICAgICAgICAgdGhpcy5lbmRlZCA9IHRydWU7CiAgICAgICAgICByZXR1cm4gc3RhdHVzID09PSBjLlpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChfbW9kZSA9PT0gYy5aX1NZTkNfRkxVU0gpIHsKICAgICAgICAgIHRoaXMub25FbmQoYy5aX09LKTsKICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gMDsKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgfTsKICAgICAgSW5mbGF0ZTIucHJvdG90eXBlLm9uRGF0YSA9IGZ1bmN0aW9uKGNodW5rKSB7CiAgICAgICAgdGhpcy5jaHVua3MucHVzaChjaHVuayk7CiAgICAgIH07CiAgICAgIEluZmxhdGUyLnByb3RvdHlwZS5vbkVuZCA9IGZ1bmN0aW9uKHN0YXR1cykgewogICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9PSykgewogICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgdGhpcy5yZXN1bHQgPSB0aGlzLmNodW5rcy5qb2luKCIiKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdXRpbHMuZmxhdHRlbkNodW5rcyh0aGlzLmNodW5rcyk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHRoaXMuY2h1bmtzID0gW107CiAgICAgICAgdGhpcy5lcnIgPSBzdGF0dXM7CiAgICAgICAgdGhpcy5tc2cgPSB0aGlzLnN0cm0ubXNnOwogICAgICB9OwogICAgICBmdW5jdGlvbiBpbmZsYXRlKGlucHV0LCBvcHRpb25zKSB7CiAgICAgICAgdmFyIGluZmxhdG9yID0gbmV3IEluZmxhdGUyKG9wdGlvbnMpOwogICAgICAgIGluZmxhdG9yLnB1c2goaW5wdXQsIHRydWUpOwogICAgICAgIGlmIChpbmZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IGluZmxhdG9yLm1zZyB8fCBtc2dbaW5mbGF0b3IuZXJy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uZXhwb3J0cyA9IHBha287CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9sb25nQDQuMC4wL25vZGVfbW9kdWxlcy9sb25nL3NyYy9sb25nLmpzCiAgdmFyIHJlcXVpcmVfbG9uZyA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9sb25nQDQuMC4wL25vZGVfbW9kdWxlcy9sb25nL3NyYy9sb25nLmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgIG1vZHVsZTIuZXhwb3J0cyA9IExvbmc0OwogICAgICB2YXIgd2FzbSA9IG51bGw7CiAgICAgIHRyeSB7CiAgICAgICAgd2FzbSA9IG5ldyBXZWJBc3NlbWJseS5JbnN0YW5jZShuZXcgV2ViQXNzZW1ibHkuTW9kdWxlKG5ldyBVaW50OEFycmF5KFsKICAgICAgICAgIDAsCiAgICAgICAgICA5NywKICAgICAgICAgIDExNSwKICAgICAgICAgIDEwOSwKICAgICAgICAgIDEsCiAgICAgICAgICAwLAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAxLAogICAgICAgICAgMTMsCiAgICAgICAgICAyLAogICAgICAgICAgOTYsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNywKICAgICAgICAgIDk2LAogICAgICAgICAgNCwKICAgICAgICAgIDEyNywKICAgICAgICAgIDEyNywKICAgICAgICAgIDEyNywKICAgICAgICAgIDEyNywKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAzLAogICAgICAgICAgNywKICAgICAgICAgIDYsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICA2LAogICAgICAgICAgNiwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxLAogICAgICAgICAgNjUsCiAgICAgICAgICAwLAogICAgICAgICAgMTEsCiAgICAgICAgICA3LAogICAgICAgICAgNTAsCiAgICAgICAgICA2LAogICAgICAgICAgMywKICAgICAgICAgIDEwOSwKICAgICAgICAgIDExNywKICAgICAgICAgIDEwOCwKICAgICAgICAgIDAsCiAgICAgICAgICAxLAogICAgICAgICAgNSwKICAgICAgICAgIDEwMCwKICAgICAgICAgIDEwNSwKICAgICAgICAgIDExOCwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE1LAogICAgICAgICAgMCwKICAgICAgICAgIDIsCiAgICAgICAgICA1LAogICAgICAgICAgMTAwLAogICAgICAgICAgMTA1LAogICAgICAgICAgMTE4LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMTcsCiAgICAgICAgICAwLAogICAgICAgICAgMywKICAgICAgICAgIDUsCiAgICAgICAgICAxMTQsCiAgICAgICAgICAxMDEsCiAgICAgICAgICAxMDksCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNSwKICAgICAgICAgIDAsCiAgICAgICAgICA0LAogICAgICAgICAgNSwKICAgICAgICAgIDExNCwKICAgICAgICAgIDEwMSwKICAgICAgICAgIDEwOSwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE3LAogICAgICAgICAgMCwKICAgICAgICAgIDUsCiAgICAgICAgICA4LAogICAgICAgICAgMTAzLAogICAgICAgICAgMTAxLAogICAgICAgICAgMTE2LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMDQsCiAgICAgICAgICAxMDUsCiAgICAgICAgICAxMDMsCiAgICAgICAgICAxMDQsCiAgICAgICAgICAwLAogICAgICAgICAgMCwKICAgICAgICAgIDEwLAogICAgICAgICAgMTkxLAogICAgICAgICAgMSwKICAgICAgICAgIDYsCiAgICAgICAgICA0LAogICAgICAgICAgMCwKICAgICAgICAgIDM1LAogICAgICAgICAgMCwKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI2LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI3LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI4LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI5LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTMwLAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExCiAgICAgICAgXSkpLCB7fSkuZXhwb3J0czsKICAgICAgfSBjYXRjaCAoZSkgewogICAgICB9CiAgICAgIGZ1bmN0aW9uIExvbmc0KGxvdywgaGlnaCwgdW5zaWduZWQpIHsKICAgICAgICB0aGlzLmxvdyA9IGxvdyB8IDA7CiAgICAgICAgdGhpcy5oaWdoID0gaGlnaCB8IDA7CiAgICAgICAgdGhpcy51bnNpZ25lZCA9ICEhdW5zaWduZWQ7CiAgICAgIH0KICAgICAgTG9uZzQucHJvdG90eXBlLl9faXNMb25nX187CiAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShMb25nNC5wcm90b3R5cGUsICJfX2lzTG9uZ19fIiwgeyB2YWx1ZTogdHJ1ZSB9KTsKICAgICAgZnVuY3Rpb24gaXNMb25nKG9iaikgewogICAgICAgIHJldHVybiAob2JqICYmIG9ialsiX19pc0xvbmdfXyJdKSA9PT0gdHJ1ZTsKICAgICAgfQogICAgICBMb25nNC5pc0xvbmcgPSBpc0xvbmc7CiAgICAgIHZhciBJTlRfQ0FDSEUgPSB7fTsKICAgICAgdmFyIFVJTlRfQ0FDSEUgPSB7fTsKICAgICAgZnVuY3Rpb24gZnJvbUludCh2YWx1ZSwgdW5zaWduZWQpIHsKICAgICAgICB2YXIgb2JqLCBjYWNoZWRPYmosIGNhY2hlOwogICAgICAgIGlmICh1bnNpZ25lZCkgewogICAgICAgICAgdmFsdWUgPj4+PSAwOwogICAgICAgICAgaWYgKGNhY2hlID0gMCA8PSB2YWx1ZSAmJiB2YWx1ZSA8IDI1NikgewogICAgICAgICAgICBjYWNoZWRPYmogPSBVSU5UX0NBQ0hFW3ZhbHVlXTsKICAgICAgICAgICAgaWYgKGNhY2hlZE9iaikKICAgICAgICAgICAgICByZXR1cm4gY2FjaGVkT2JqOwogICAgICAgICAgfQogICAgICAgICAgb2JqID0gZnJvbUJpdHModmFsdWUsICh2YWx1ZSB8IDApIDwgMCA/IC0xIDogMCwgdHJ1ZSk7CiAgICAgICAgICBpZiAoY2FjaGUpCiAgICAgICAgICAgIFVJTlRfQ0FDSEVbdmFsdWVdID0gb2JqOwogICAgICAgICAgcmV0dXJuIG9iajsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdmFsdWUgfD0gMDsKICAgICAgICAgIGlmIChjYWNoZSA9IC0xMjggPD0gdmFsdWUgJiYgdmFsdWUgPCAxMjgpIHsKICAgICAgICAgICAgY2FjaGVkT2JqID0gSU5UX0NBQ0hFW3ZhbHVlXTsKICAgICAgICAgICAgaWYgKGNhY2hlZE9iaikKICAgICAgICAgICAgICByZXR1cm4gY2FjaGVkT2JqOwogICAgICAgICAgfQogICAgICAgICAgb2JqID0gZnJvbUJpdHModmFsdWUsIHZhbHVlIDwgMCA/IC0xIDogMCwgZmFsc2UpOwogICAgICAgICAgaWYgKGNhY2hlKQogICAgICAgICAgICBJTlRfQ0FDSEVbdmFsdWVdID0gb2JqOwogICAgICAgICAgcmV0dXJuIG9iajsKICAgICAgICB9CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbUludCA9IGZyb21JbnQ7CiAgICAgIGZ1bmN0aW9uIGZyb21OdW1iZXIodmFsdWUsIHVuc2lnbmVkKSB7CiAgICAgICAgaWYgKGlzTmFOKHZhbHVlKSkKICAgICAgICAgIHJldHVybiB1bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICBpZiAodW5zaWduZWQpIHsKICAgICAgICAgIGlmICh2YWx1ZSA8IDApCiAgICAgICAgICAgIHJldHVybiBVWkVSTzsKICAgICAgICAgIGlmICh2YWx1ZSA+PSBUV09fUFdSXzY0X0RCTCkKICAgICAgICAgICAgcmV0dXJuIE1BWF9VTlNJR05FRF9WQUxVRTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKHZhbHVlIDw9IC1UV09fUFdSXzYzX0RCTCkKICAgICAgICAgICAgcmV0dXJuIE1JTl9WQUxVRTsKICAgICAgICAgIGlmICh2YWx1ZSArIDEgPj0gVFdPX1BXUl82M19EQkwpCiAgICAgICAgICAgIHJldHVybiBNQVhfVkFMVUU7CiAgICAgICAgfQogICAgICAgIGlmICh2YWx1ZSA8IDApCiAgICAgICAgICByZXR1cm4gZnJvbU51bWJlcigtdmFsdWUsIHVuc2lnbmVkKS5uZWcoKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModmFsdWUgJSBUV09fUFdSXzMyX0RCTCB8IDAsIHZhbHVlIC8gVFdPX1BXUl8zMl9EQkwgfCAwLCB1bnNpZ25lZCk7CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbU51bWJlciA9IGZyb21OdW1iZXI7CiAgICAgIGZ1bmN0aW9uIGZyb21CaXRzKGxvd0JpdHMsIGhpZ2hCaXRzLCB1bnNpZ25lZCkgewogICAgICAgIHJldHVybiBuZXcgTG9uZzQobG93Qml0cywgaGlnaEJpdHMsIHVuc2lnbmVkKTsKICAgICAgfQogICAgICBMb25nNC5mcm9tQml0cyA9IGZyb21CaXRzOwogICAgICB2YXIgcG93X2RibCA9IE1hdGgucG93OwogICAgICBmdW5jdGlvbiBmcm9tU3RyaW5nKHN0ciwgdW5zaWduZWQsIHJhZGl4KSB7CiAgICAgICAgaWYgKHN0ci5sZW5ndGggPT09IDApCiAgICAgICAgICB0aHJvdyBFcnJvcigiZW1wdHkgc3RyaW5nIik7CiAgICAgICAgaWYgKHN0ciA9PT0gIk5hTiIgfHwgc3RyID09PSAiSW5maW5pdHkiIHx8IHN0ciA9PT0gIitJbmZpbml0eSIgfHwgc3RyID09PSAiLUluZmluaXR5IikKICAgICAgICAgIHJldHVybiBaRVJPOwogICAgICAgIGlmICh0eXBlb2YgdW5zaWduZWQgPT09ICJudW1iZXIiKSB7CiAgICAgICAgICByYWRpeCA9IHVuc2lnbmVkLCB1bnNpZ25lZCA9IGZhbHNlOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB1bnNpZ25lZCA9ICEhdW5zaWduZWQ7CiAgICAgICAgfQogICAgICAgIHJhZGl4ID0gcmFkaXggfHwgMTA7CiAgICAgICAgaWYgKHJhZGl4IDwgMiB8fCAzNiA8IHJhZGl4KQogICAgICAgICAgdGhyb3cgUmFuZ2VFcnJvcigicmFkaXgiKTsKICAgICAgICB2YXIgcDsKICAgICAgICBpZiAoKHAgPSBzdHIuaW5kZXhPZigiLSIpKSA+IDApCiAgICAgICAgICB0aHJvdyBFcnJvcigiaW50ZXJpb3IgaHlwaGVuIik7CiAgICAgICAgZWxzZSBpZiAocCA9PT0gMCkgewogICAgICAgICAgcmV0dXJuIGZyb21TdHJpbmcoc3RyLnN1YnN0cmluZygxKSwgdW5zaWduZWQsIHJhZGl4KS5uZWcoKTsKICAgICAgICB9CiAgICAgICAgdmFyIHJhZGl4VG9Qb3dlciA9IGZyb21OdW1iZXIocG93X2RibChyYWRpeCwgOCkpOwogICAgICAgIHZhciByZXN1bHQgPSBaRVJPOwogICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgc3RyLmxlbmd0aDsgaSArPSA4KSB7CiAgICAgICAgICB2YXIgc2l6ZSA9IE1hdGgubWluKDgsIHN0ci5sZW5ndGggLSBpKSwgdmFsdWUgPSBwYXJzZUludChzdHIuc3Vic3RyaW5nKGksIGkgKyBzaXplKSwgcmFkaXgpOwogICAgICAgICAgaWYgKHNpemUgPCA4KSB7CiAgICAgICAgICAgIHZhciBwb3dlciA9IGZyb21OdW1iZXIocG93X2RibChyYWRpeCwgc2l6ZSkpOwogICAgICAgICAgICByZXN1bHQgPSByZXN1bHQubXVsKHBvd2VyKS5hZGQoZnJvbU51bWJlcih2YWx1ZSkpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0Lm11bChyYWRpeFRvUG93ZXIpOwogICAgICAgICAgICByZXN1bHQgPSByZXN1bHQuYWRkKGZyb21OdW1iZXIodmFsdWUpKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmVzdWx0LnVuc2lnbmVkID0gdW5zaWduZWQ7CiAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgfQogICAgICBMb25nNC5mcm9tU3RyaW5nID0gZnJvbVN0cmluZzsKICAgICAgZnVuY3Rpb24gZnJvbVZhbHVlKHZhbCwgdW5zaWduZWQpIHsKICAgICAgICBpZiAodHlwZW9mIHZhbCA9PT0gIm51bWJlciIpCiAgICAgICAgICByZXR1cm4gZnJvbU51bWJlcih2YWwsIHVuc2lnbmVkKTsKICAgICAgICBpZiAodHlwZW9mIHZhbCA9PT0gInN0cmluZyIpCiAgICAgICAgICByZXR1cm4gZnJvbVN0cmlu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aXNOZWdhdGl2ZSgpKSB7CiAgICAgICAgICBpZiAodGhpcy5lcShNSU5fVkFMVUUpKSB7CiAgICAgICAgICAgIHZhciByYWRpeExvbmcgPSBmcm9tTnVtYmVyKHJhZGl4KSwgZGl2ID0gdGhpcy5kaXYocmFkaXhMb25nKSwgcmVtMSA9IGRpdi5tdWwocmFkaXhMb25nKS5zdWIodGhpcyk7CiAgICAgICAgICAgIHJldHVybiBkaXYudG9TdHJpbmcocmFkaXgpICsgcmVtMS50b0ludCgpLnRvU3RyaW5nKHJhZGl4KTsKICAgICAgICAgIH0gZWxzZQogICAgICAgICAgICByZXR1cm4gIi0iICsgdGhpcy5uZWcoKS50b1N0cmluZyhyYWRpeCk7CiAgICAgICAgfQogICAgICAgIHZhciByYWRpeFRvUG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIDYpLCB0aGlzLnVuc2lnbmVkKSwgcmVtID0gdGhpczsKICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHZhciByZW1EaXYgPSByZW0uZGl2KHJhZGl4VG9Qb3dlciksIGludHZhbCA9IHJlbS5zdWIocmVtRGl2Lm11bChyYWRpeFRvUG93ZXIpKS50b0ludCgpID4+PiAwLCBkaWdpdHMgPSBpbnR2YWwudG9TdHJpbmcocmFkaXgpOwogICAgICAgICAgcmVtID0gcmVtRGl2OwogICAgICAgICAgaWYgKHJlbS5pc1plcm8oKSkKICAgICAgICAgICAgcmV0dXJuIGRpZ2l0cyArIHJlc3VsdDsKICAgICAgICAgIGVsc2UgewogICAgICAgICAgICB3aGlsZSAoZGlnaXRzLmxlbmd0aCA8IDYpCiAgICAgICAgICAgICAgZGlnaXRzID0gIjAiICsgZGlnaXRzOwogICAgICAgICAgICByZXN1bHQgPSAiIiArIGRpZ2l0cyArIHJlc3VsdDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5c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ZXR1cm4gdGhpcy5oaWdoID09PSAwICYmIHRoaXMubG93ID09PSAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmVxeiA9IExvbmdQcm90b3R5cGUuaXNaZXJvOwogICAgICBMb25nUHJvdG90eXBlLmlzTmVnYXRpdmUgPSBmdW5jdGlvbiBpc05lZ2F0aXZlKCkgewogICAgICAgIHJldHVybiAhdGhpcy51bnNpZ25lZCAmJiB0aGlzLmhpZ2ggPCAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzUG9zaXRpdmUgPSBmdW5jdGlvbiBpc1Bvc2l0aXZlKCkgewogICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkIHx8IHRoaXMuaGlnaCA+PSAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzT2RkID0gZnVuY3Rpb24gaXNPZGQoKSB7CiAgICAgICAgcmV0dXJuICh0aGlzLmxvdyAmIDEpID09PSAxOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzRXZlbiA9IGZ1bmN0aW9uIGlzRXZlbigpIHsKICAgICAgICByZXR1cm4gKHRoaXMubG93ICYgMSkgPT09IDA7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZXF1YWxzID0gZnVuY3Rpb24gZXF1YWxzKG90aGVyKSB7CiAgICAgICAgaWYgKCFpc0xvbmcob3RoZXIpKQogICAgICAgICAgb3RoZXIgPSBmcm9tVmFsdWUob3RoZXIpOwogICAgICAgIGlmICh0aGlzLnVuc2lnbmVkICE9PSBvdGhlci51bnNpZ25lZCAmJiB0aGlzLmhpZ2ggPj4+IDMxID09PSAxICYmIG90aGVyLmhpZ2ggPj4+IDMxID09PSAxKQogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIHJldHVybiB0aGlzLmhpZ2ggPT09IG90aGVyLmhpZ2ggJiYgdGhpcy5sb3cgPT09IG90aGVyLmxvdzsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZ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iA+Pj4gMTY7CiAgICAgICAgYzMyICY9IDY1NTM1OwogICAgICAgIGM0OCArPSBhNDggKyBiNDg7CiAgICAgICAgYzQ4ICY9IDY1NTM1OwogICAgICAgIHJldHVybiBmcm9tQml0cyhjMTYgPDwgMTYgfCBjMDAsIGM0OCA8PCAxNiB8IGMzMiwgdGhpcy51bnNpZ25lZCk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuc3VidHJhY3QgPSBmdW5jdGlvbiBzdWJ0cmFjdChzdWJ0cmFoZW5kKSB7CiAgICAgICAgaWYgKCFpc0xvbmcoc3VidHJhaGVuZCkpCiAgICAgICAgICBzdWJ0cmFoZW5kID0gZnJvbVZhbHVlKHN1YnRyYWhlbmQpOwogICAgICAgIHJldHVybiB0aGlzLmFkZChzdWJ0cmFoZW5kLm5lZygpKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zdWIgPSBMb25nUHJvdG90eXBlLnN1YnRyYWN0OwogICAgICBMb25nUHJvdG90eXBlLm11bHRpcGx5ID0gZnVuY3Rpb24gbXVsdGlwbHkobXVsdGlwbGllcikgewogICAgICAgIGlmICh0aGlzLmlzWmVybygpKQogICAgICAgICAgcmV0dXJuIFpFUk87CiAgICAgICAgaWYgKCFpc0xvbmcobXVsdGlwbGllcikpCiAgICAgICAgICBtdWx0aXBsaWVyID0gZnJvbVZhbHVlKG11bHRpcGxpZXIpOwogICAgICAgIGlmICh3YXNtKSB7CiAgICAgICAgICB2YXIgbG93ID0gd2FzbS5tdWwodGhpcy5sb3csIHRoaXMuaGlnaCwgbXVsdGlwbGllci5sb3csIG11bHRpcGxpZXIuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAobXVsdGlwbGllci5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiBaRVJPOwogICAgICAgIGlmICh0aGlzLmVx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AgICAgICAgaWYgKCFpc0xvbmcoZGl2aXNvcikpCiAgICAgICAgICBkaXZpc29yID0gZnJvbVZhbHVlKGRpdmlzb3IpOwogICAgICAgIGlmIChkaXZpc29yLmlzWmVybygpKQogICAgICAgICAgdGhyb3cgRXJyb3IoImRpdmlzaW9uIGJ5IHplcm8iKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgaWYgKCF0aGlzLnVuc2lnbmVkICYmIHRoaXMuaGlnaCA9PT0gLTIxNDc0ODM2NDggJiYgZGl2aXNvci5sb3cgPT09IC0xICYmIGRpdmlzb3IuaGlnaCA9PT0gLTEpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgICB9CiAgICAgICAgICB2YXIgbG93ID0gKHRoaXMudW5zaWduZWQgPyB3YXNtLmRpdl91IDogd2FzbS5kaXZfcykodGhpcy5sb3csIHRoaXMuaGlnaCwgZGl2aXNvci5sb3csIGRpdmlzb3IuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkID8gVVpFUk8gOiBaRVJPOwogICAgICAgIHZhciBhcHByb3gsIHJlbSwgcmVzOwogICAgICAgIGlmICghdGhpcy51bnNpZ25lZCkgewogICAgICAgICAgaWYgKHRoaXMuZXEoTUlOX1ZBTFVFKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5lcShPTkUpIHx8IGRpdmlzb3IuZXEoTkVHX09ORSkpCiAgICAgICAgICAgICAgcmV0dXJuIE1JTl9WQUxVRTsKICAgICAgICAgICAgZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICAgIHJldHVybiBPTkU7CiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgIHZhciBoYWxmVGhpcyA9IHRoaXMuc2hyKDEpOwogICAgICAgICAgICAgIGFwcHJveCA9IGhhbGZUaGlzLmRpdihkaXZpc29yKS5zaGwoMSk7CiAgICAgICAgICAgICAgaWYgKGFwcHJveC5lcShaRVJPKSkgewogICAgICAgICAgICAgICAgcmV0dXJuIGRpdmlzb3IuaXNOZWdhdGl2ZSgpID8gT05FIDogTkVHX09ORTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmVtID0gdGhpcy5zdWIoZGl2aXNvci5tdWwoYXBwcm94KSk7CiAgICAgICAgICAgICAgICByZXMgPSBhcHByb3guYWRkKHJlbS5kaXYoZGl2aXNvcikpOwogICAgICAgICAgICAgICAgcmV0dXJuIHJlczsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICByZXR1cm4gdGhpcy51bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICAgIGlmICh0aGlzLmlzTmVnYXRpdmUoKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5pc05lZ2F0aXZlKCkpCiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVnKCkuZGl2KGRpdmlzb3IubmVnKCkpOwogICAgICAgICAgICByZXR1cm4gdGhpcy5uZWcoKS5kaXYoZGl2aXNvcikubmVnKCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGRpdmlzb3IuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgICByZXR1cm4gdGhpcy5kaXYoZGl2aXNvci5uZWcoKSkubmVnKCk7CiAgICAgICAgICByZXMgPSBaRVJPOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoIWRpdmlzb3IudW5zaWduZWQpCiAgICAgICAgICAgIGRpdmlzb3IgPSBkaXZpc29yLnRvVW5zaWduZWQoKTsKICAgICAgICAgIGlmIChkaXZpc29yLmd0KHRoaXMpKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAoZGl2aXNvci5ndCh0aGlzLnNocnUoMSkpKQogICAgICAgICAgICByZXR1cm4gVU9ORTsKICAgICAgICAgIHJlcyA9IFVaRVJPOwogICAgICAgIH0KICAgICAgICByZW0gPSB0aGlzOwogICAgICAgIHdoaWxlIChyZW0uZ3RlKGRpdmlzb3IpKSB7CiAgICAgICAgICBhcHByb3ggPSBNYXRoLm1heCgxLCBNYXRoLmZsb29yKHJlbS50b051bWJlcigpIC8gZGl2aXNvci50b051bWJlcigpKSk7CiAgICAgICAgICB2YXIgbG9nMiA9IE1hdGguY2VpbChNYXRoLmxvZyhhcHByb3gpIC8gTWF0aC5MTjIpLCBkZWx0YSA9IGxvZzIgPD0gNDggPyAxIDogcG93X2RibCgyLCBsb2cyIC0gNDgpLCBhcHByb3hSZXMgPSBmcm9tTnVtYmVyKGFwcHJveCksIGFwcHJveFJlbSA9IGFwcHJveFJlcy5tdWwoZGl2aXNvcik7CiAgICAgICAgICB3aGlsZSAoYXBwcm94UmVtLmlzTmVnYXRpdmUoKSB8fCBhcHByb3hSZW0uZ3QocmVtKSkgewogICAgICAgICAgICBhcHByb3ggLT0gZGVsdGE7CiAgICAgICAgICAgIGFwcHJveFJlcyA9IGZyb21OdW1iZXIoYXBwcm94LCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICAgICAgYXBwcm94UmVtID0gYXBwcm94UmVzLm11bChkaXZpc29yKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChhcHByb3hSZXMuaXNaZXJvKCkpCiAgICAgICAgICAgIGFwcHJveFJlcyA9IE9ORTsKICAgICAgICAgIHJlcyA9IHJlcy5hZGQoYXBwcm94UmVzKTsKICAgICAgICAgIHJlbSA9IHJlbS5zdWIoYXBwcm94UmVtKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlczsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5kaXYgPSBMb25nUHJvdG90eXBlLmRpdmlkZTsKICAgICAgTG9uZ1Byb3RvdHlwZS5tb2R1bG8gPSBmdW5jdGlvbiBtb2R1bG8oZGl2aXNvcikgewogICAgICAgIGlmICghaXNMb25nKGRpdmlzb3IpKQogICAgICAgICAgZGl2aXNvciA9IGZyb21WYWx1ZShkaXZpc29yKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgdmFyIGxvdyA9ICh0aGlzLnVuc2lnbmVkID8gd2FzbS5yZW1fdSA6IHdhc20ucmVtX3MpKHRoaXMubG93LCB0aGlzLmhpZ2gsIGRpdmlzb3IubG93LCBkaXZpc29yLmhpZ2gpOwogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGxvdywgd2FzbS5nZXRfaGlnaCgpLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXMuc3ViKHRoaXMuZGl2KGRpdmlzb3IpLm11bChkaXZpc29yKSk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUubW9kID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUucmVtID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUubm90ID0gZnVuY3Rpb24gbm90KCkgewogICAgICAgIHJldHVybiBmcm9tQml0cyh+dGhpcy5sb3csIH50aGlzLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmFuZCA9IGZ1bmN0aW9uIGFuZChvdGhlcikgewogICAgICAgIGlmICghaXNMb25nKG90aGVyKSkKICAgICAgICAgIG90aGVyID0gZnJvbVZhbHVlKG90aGVyKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3cgJiBvdGhlci5sb3csIHRoaXMuaGlnaCAmIG90aGVyLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm9yID0gZnVuY3Rpb24gb3Iob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1ZShvdGhlcik7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93IHwgb3RoZXIubG93LCB0aGlzLmhpZ2ggfCBvdGhlci5oaWdoLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS54b3IgPSBmdW5jdGlvbiB4b3Iob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1ZShvdGhlcik7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93IF4gb3RoZXIubG93LCB0aGlzLmhpZ2ggXiBvdGhlci5oaWdoLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdExlZnQgPSBmdW5jdGlvbiBzaGlmdExlZnQobnVtQml0cykgewogICAgICAgIGlmIChpc0xvbmcobnVtQml0cykpCiAgICAgICAgICBudW1CaXRzID0gbnVtQml0cy50b0ludCgpOwogICAgICAgIGlmICgobnVtQml0cyAmPSA2MykgPT09IDApCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBlbHNlIGlmIChudW1CaXRzIDwgMzIpCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3cgPDwgbnVtQml0cywgdGhpcy5oaWdoIDw8IG51bUJpdHMgfCB0aGlzLmxvdyA+Pj4gMzIgLSBudW1CaXRzLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICBlbHNlCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMoMCwgdGhpcy5sb3cgPDwgbnVtQml0cyAtIDMyLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGwgPSBMb25nUHJvdG90eXBlLnNoaWZ0TGVmdDsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0ID0gZnVuY3Rpb24gc2hpZnRSaWdodChudW1CaXRzKSB7CiAgICAgICAgaWYgKGlzTG9uZyhudW1CaXRzKSkKICAgICAgICAgIG51bUJpdHMgPSBudW1CaXRzLnRvSW50KCk7CiAgICAgICAgaWYgKChudW1CaXRzICY9IDYzKSA9PT0gMCkKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIGVsc2UgaWYgKG51bUJpdHMgPCAzMikKICAgICAgICAgIHJldHVybiBmcm9tQml0cyh0aGlzLmxvdyA+Pj4gbnVtQml0cyB8IHRoaXMuaGlnaCA8PCAzMiAtIG51bUJpdHMsIHRoaXMuaGlnaCA+PiBudW1CaXRzLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICBlbHNlCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5oaWdoID4+IG51bUJpdHMgLSAzMiwgdGhpcy5oaWdoID49IDAgPyAwIDogLTEsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnNociA9IExvbmdQcm90b3R5cGUuc2hpZnRSaWdodDsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0VW5zaWduZWQgPSBmdW5jdGlvbiBzaGlmdFJpZ2h0VW5zaWduZWQobnVtQml0cykgewogICAgICAgIGlmIChpc0xvbmcobnVtQml0cykpCiAgICAgICAgICBudW1CaXRzID0gbnVtQml0cy50b0ludCgpOwogICAgICAgIG51bUJpdHMgJj0gNjM7CiAgICAgICAgaWYgKG51bUJpdHMgPT09IDApCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBlbHNlIHsKICAgICAgICAgIHZhciBoaWdoID0gdGhpcy5oaWdoOwogICAgICAgICAgaWYgKG51bUJpdHMgPCAzMikgewogICAgICAgICAgICB2YXIgbG93ID0gdGhpcy5sb3c7CiAgICAgICAgICAgIHJldHVybiBmcm9tQ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kUoKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS50b0J5dGVzTEUgPSBmdW5jdGlvbiB0b0J5dGVzTEUoKSB7CiAgICAgICAgdmFyIGhpID0gdGhpcy5oaWdoLCBsbyA9IHRoaXMubG93OwogICAgICAgIHJldHVybiBbCiAgICAgICAgICBsbyAmIDI1NSwKICAgICAgICAgIGxvID4+PiA4ICYgMjU1LAogICAgICAgICAgbG8gPj4+IDE2ICYgMjU1LAogICAgICAgICAgbG8gPj4+IDI0LAogICAgICAgICAgaGkgJiAyNTUsCiAgICAgICAgICBoaSA+Pj4gOCAmIDI1NSwKICAgICAgICAgIGhpID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGhpID4+PiAyNAogICAgICAgIF07CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9CeXRlc0JFID0gZnVuY3Rpb24gdG9CeXRlc0JFKCkgewogICAgICAgIHZhciBoaSA9IHRoaXMuaGlnaCwgbG8gPSB0aGlzLmxvdzsKICAgICAgICByZXR1cm4gWwogICAgICAgICAgaGkgPj4+IDI0LAogICAgICAgICAgaGkgPj4+IDE2ICYgMjU1LAogICAgICAgICAgaGkgPj4+IDggJiAyNTUsCiAgICAgICAgICBoaSAmIDI1NSwKICAgICAgICAgIGxvID4+PiAyNCwKICAgICAgICAgIGxvID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGxvID4+PiA4ICYgMjU1LAogICAgICAgICAgbG8gJiAyNTUKICAgICAgICBdOwogICAgICB9OwogICAgICBMb25nNC5mcm9tQnl0ZXMgPSBmdW5jdGlvbiBmcm9tQnl0ZXMyKGJ5dGVzLCB1bnNpZ25lZCwgbGUpIHsKICAgICAgICByZXR1cm4gbGUgPyBMb25nNC5mcm9tQnl0ZXNMRShieXRlcywgdW5zaWduZWQpIDogTG9uZzQuZnJvbUJ5dGVzQkUoYnl0ZXMsIHVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZzQuZnJvbUJ5dGVzTEUgP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ciA9IGV4dGVuZC5kZXNlcmlhbGl6ZS5iaW5kKGV4dGVuZCk7CiAgICAgICAgY29uc3QgZmFsbGJhY2tTZXJpYWxpemVyID0gZXh0ZW5kLnNlcmlhbGl6ZS5iaW5kKGV4dGVuZCk7CiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIGRlc2VyaWFsaXplKG1lc3NhZ2UpIHsKICAgICAgICAgICAgcmV0dXJuIGltcGxlbWVudGF0aW9uLmRlc2VyaWFsaXplKG1lc3NhZ2UsIGZhbGxiYWNrRGVzZXJpYWxpemVyKTsKICAgICAgICAgIH0sCiAgICAgICAgICBzZXJpYWxpemUoaW5wdXQpIHsKICAgICAgICAgICAgcmV0dXJuIGltcGxlbWVudGF0aW9uLnNlcmlhbGl6ZShpbnB1dCwgZmFsbGJhY2tTZXJpYWxpemVyKTsKICAgICAgICAgIH0KICAgICAgICB9OwogICAgICB9CiAgICAgIGV4cG9ydHMyLmV4dGVuZFNlcmlhbGl6ZXIgPSBleHRlbmRTZXJpYWxpemVyOwogICAgICB2YXIgRGVmYXVsdEVycm9yU2VyaWFsaXplciA9IHsKICAgICAgICBkZXNlcmlhbGl6ZShtZXNzYWdlKSB7CiAgICAgICAgICByZXR1cm4gT2JqZWN0LmFzc2lnbihFcnJvcihtZXNzYWdlLm1lc3NhZ2UpLCB7CiAgICAgICAgICAgIG5hbWU6IG1lc3NhZ2UubmFtZSwKICAgICAgICAgICAgc3RhY2s6IG1lc3NhZ2Uuc3RhY2sKICAgICAgICAgIH0pOwogICAgICAgIH0sCiAgICAgICAgc2VyaWFsaXplKGVycm9yKSB7CiAgICAgICAgICByZXR1cm4gewogICAgICAgICAgICBfX2Vycm9yX21hcmtlcjogIiQkZXJyb3IiLAogICAgICAgICAgICBtZXNzYWdlOiBlcnJvci5tZXNzYWdlLAogICAgICAgICAgICBuYW1lOiBlcnJvci5uYW1lLAogICAgICAgICAgICBzdGFjazogZXJyb3Iuc3RhY2sKICAgICAgICAgIH07CiAgICAgICAgfQogICAgICB9OwogICAgICB2YXIgaXNTZXJpYWxpemVkRXJyb3IgPSAodGhpbmcpID0+IHRoaW5nICYmIHR5cGVvZiB0aGluZyA9PT0gIm9iamVjdCIgJiYgIl9fZXJyb3JfbWFya2VyIiBpbiB0aGluZyAmJiB0aGluZy5fX2Vycm9yX21hcmtlciA9PT0gIiQkZXJyb3IiOwogICAgICBleHBvcnRzMi5EZWZhdWx0U2VyaWFsaXplciA9IHsKICAgICAgICBkZXNlcmlhbGl6ZShtZXNzYWdlKSB7CiAgICAgICAgICBpZiAoaXNTZXJpYWxpemVkRXJyb3IobWVzc2FnZSkpIHsKICAgICAgICAgICAgcmV0dXJuIERlZmF1bHRFcnJvclNlcmlhbGl6ZXIuZGVzZXJpYWxpemUobWVzc2FnZSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByZXR1cm4gbWVzc2FnZTsKICAgICAgICAgIH0KICAgICAgICB9LAogICAgICAgIHNlcmlhbGl6ZShpbnB1dCkgewogICAgICAgICAgaWYgKGlucHV0IGluc3RhbmNlb2YgRXJyb3IpIHsKICAgICAgICAgICAgcmV0dXJuIERlZmF1bHRFcnJvclNlcmlhbGl6ZXIuc2VyaWFsaXplKGlucHV0KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHJldHVybiBpbnB1dDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH07CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS90aHJlYWRzQDEuNy4wL25vZGVfbW9kdWxlcy90aHJlYWRzL2Rpc3QvY29tbW9uLmpzCiAgdmFyIHJlcXVpcmVfY29tbW9uMiA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS90aHJlYWRzQDEuNy4wL25vZGVfbW9kdWxlcy90aHJlYWRzL2Rpc3QvY29tbW9uLmpzIihleHBvcnRzMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2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c3Vic2NyaWJlKCh2YWx1ZSkgPT4gcG9zdEpvYlJlc3VsdE1lc3NhZ2Uoam9iVUlELCBmYWxzZSwgY29tbW9uXzEuc2VyaWFsaXplKHZhbHVlKSksIChlcnJvcikgPT4gewogICAgICAgICAgICAgIHBvc3RKb2JFcnJvck1lc3NhZ2Uoam9iVUlELCBjb21tb25fMS5zZXJpYWxpemUoZXJyb3IpKTsKICAgICAgICAgICAgICBhY3RpdmVTdWJzY3JpcHRpb25zLmRlbGV0ZShqb2JVSUQpOwogICAgICAgICAgICB9LCAoKSA9PiB7CiAgICAgICAgICAgICAgcG9zdEpvYlJlc3VsdE1lc3NhZ2Uoam9iVUlELCB0cnVlKTsKICAgICAgICAgICAgICBhY3RpdmVTdWJzY3JpcHRpb25zLmRlbGV0ZShqb2JVSUQpOwogICAgICAgICAgICB9KTsKICAgICAgICAgICAgYWN0aXZlU3Vic2NyaXB0aW9ucy5zZXQoam9iVUlELCBzdWJzY3JpcHRpb24pOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBjb25zdCByZXN1bHQgPSB5aWVsZCBzeW5jUmVzdWx0OwogICAgICAgICAgICAgIHBvc3RKb2JSZXN1bHRNZXNzYWdlKGpvYlVJRCwgdHJ1ZSwgY29tbW9uXzEuc2VyaWFsaXplKHJlc3VsdCkpOwogICAgICAgICAgICB9IGNhdGNoIChlcnJvcikgewogICAgICAgICAgICAgIHBvc3RKb2JFcnJvck1lc3NhZ2Uoam9iVUlELCBjb21tb25fMS5zZXJpYWxpemUoZXJyb3IpKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGV4cG9zZTIoZXhwb3NlZCkgewogICAgICAgIGlmICghaW1wbGVtZW50YXRpb25fMS5kZWZhdWx0LmlzV29ya2VyUnVudGltZSgpKSB7CiAgICAgICAgICB0aHJvdyBFcnJvcigiZXhwb3NlKCkgY2Fs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leHBlY3RhdGlvbi5wYXJ0c1tpXSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuICJbIiArIChleHBlY3RhdGlvbi5pbnZlcnRlZCA/ICJeIiA6ICIiKSArIGVzY2FwZWRQYXJ0cyArICJdIjsKICAgICAgICAgIH0sCiAgICAgICAgICBhbnk6IGZ1bmN0aW9uKGV4cGVjdGF0aW9uKSB7CiAgICAgICAgICAgIHJldHVybiAiYW55IGNoYXJhY3RlciI7CiAgICAgICAgICB9LAogICAgICAgICAgZW5kOiBmdW5jdGlvbihleHBlY3RhdGlvbikgewogICAgICAgICAgICByZXR1cm4gImVuZCBvZiBpbnB1dCI7CiAgICAgICAgICB9LAogICAgICAgICAgb3RoZXI6IGZ1bmN0aW9uKGV4cGVjdGF0aW9uKSB7CiAgICAgICAgICAgIHJldHVybiBleHBlY3RhdGlvbi5kZXNjcmlwdGlvbjsKICAgICAgICAgIH0KICAgICAgICB9OwogICAgICAgIGZ1bmN0aW9uIGhleChjaCkgewogICAgICAgICAgcmV0dXJuIGNoLmNoYXJDb2RlQXQoMCkudG9TdHJpbmcoMTYpLnRvVXBwZXJDYXNlKCk7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIGxpdGVyYWxFc2NhcGUocykgewogICAgICAgICAgcmV0dXJuIHMucmVwbGFjZSgvXFwvZywgIlxcXFwiKS5yZXBsYWNlKC8iL2csICdcXCInKS5yZXBsYWNlKC9cMC9nLCAiXFwwIikucmVwbGFjZSgvXHQvZywgIlxcdCIpLnJlcGxhY2UoL1xuL2csICJcXG4iKS5yZXBsYWNlKC9cci9nLCAiXFxyIikucmVwbGFjZSgvW1x4MDAtXHgwRl0vZywgZnVuY3Rpb24oY2gpIHsKICAgICAgICAgICAgcmV0dXJuICJcXHgwIiArIGhleChjaCk7CiAgICAgICAgICB9KS5yZXBsYWNlKC9bXHgxMC1ceDFGXHg3Ri1ceDlGXS9nLCBmdW5jdGlvbihjaCkgewogICAgICAgICAgICByZXR1cm4gIlxceCIgKyBoZXgoY2gpOwogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIGNsYXNzRXNjYXBlKHMpIHsKICAgICAgICAgIHJldHVybiBzLnJlcGxhY2UoL1xcL2csICJcXFxcIikucmVwbGFjZSgvXF0vZywgIlxcXSIpLnJlcGxhY2UoL1xeL2csICJcXF4iKS5yZXBsYWNlKC8tL2csICJcXC0iKS5yZXBsYWNlKC9cMC9nLCAiXFwwIikucmVwbGFjZSgvXHQvZywgIlxcdCIpLnJlcGxhY2UoL1xuL2csICJcXG4iKS5yZXBsYWNlKC9cci9nLCAiXFxyIikucmVwbGFjZSgvW1x4MDAtXHgwRl0vZywgZnVuY3Rpb24oY2gpIHsKICAgICAgICAgICAgcmV0dXJuICJcXHgwIiArIGhleChjaCk7CiAgICAgICAgICB9KS5yZXBsYWNlKC9bXHgxMC1ceDFGXHg3Ri1ceDlGXS9nLCBmdW5jdGlvbihjaCkgewogICAgICAgICAgICByZXR1cm4gIlxceCIgKyBoZXgoY2gpOwogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIGRlc2NyaWJlRXhwZWN0YXRpb24oZXhwZWN0YXRpb24pIHsKICAgICAgICAgIHJldHVybiBERVNDUklCRV9FWFBFQ1RBVElPTl9GTlNbZXhwZWN0YXRpb24udHlwZV0oZXhwZWN0YXRpb24pOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBkZXNjcmliZUV4cGVjdGVkKGV4cGVjdGVkMikgewogICAgICAgICAgdmFyIGRlc2NyaXB0aW9ucyA9IG5ldyBBcnJheShleHBlY3RlZDIubGVuZ3RoKSwgaSwgajsKICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBleHBlY3RlZDIubGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgZGVzY3JpcHRpb25zW2ldID0gZGVzY3JpYmVFeHBlY3RhdGlvbihleHBlY3RlZDJbaV0pOwogICAgICAgICAgfQogICAgICAgICAgZGVzY3JpcHRpb25zLnNvcnQoKTsKICAgICAgICAgIGlmIChkZXNjcmlwdGlvbnMubGVuZ3RoID4gMCkgewogICAgICAgICAgICBmb3IgKGkgPSAxLCBqID0gMTsgaSA8IGRlc2NyaXB0aW9ucy5sZW5ndGg7IGkrKykgewogICAgICAgICAgICAgIGlmIChkZXNjcmlwdGlvbnNbaSAtIDFdICE9PSBkZXNjcmlwdGlvbnNbaV0pIHsKICAgICAgICAgICAgICAgIGRlc2NyaXB0aW9uc1tqXSA9IGRlc2NyaXB0aW9uc1tpXTsKICAgICAgICAgICAgICAgIGorKzsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZGVzY3JpcHRpb25zLmxlbmd0aCA9IGo7CiAgICAgICAgICB9CiAgICAgICAgICBzd2l0Y2ggKGRlc2NyaXB0aW9ucy5sZW5ndGgpIHsKICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgIHJldHVybiBkZXNjcmlwdGlvbnNbMF07CiAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICByZXR1cm4gZGVzY3JpcHRpb25zWzBdICsgIiBvciAiICsgZGVzY3JpcHRpb25zWzFdOwogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgIHJldHVybiBkZXNjcmlwdGlvbnMuc2xpY2UoMCwgLTEpLmpvaW4oIiwgIikgKyAiLCBvciAiICsgZGVzY3JpcHRpb25zW2Rlc2NyaXB0aW9ucy5sZW5ndGggLSAxXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gZGVzY3JpYmVGb3VuZChmb3VuZDIpIHsKICAgICAgICAgIHJldHVybiBmb3VuZDIgPyAnIicgKyBsaXRlcmFsRXNjYXBlKGZvdW5kMikgKyAnIicgOiAiZW5kIG9mIGlucHV0IjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuICJFeHBlY3RlZCAiICsgZGVzY3JpYmVFeHBlY3RlZChleHBlY3R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9IHBlZyRwb3NEZXRhaWxzQ2FjaGVbcG9zXSwgcDsKICAgICAgICAgIGlmIChkZXRhaWxzKSB7CiAgICAgICAgICAgIHJldHVybiBkZXRhaWxzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcCA9IHBvcyAtIDE7CiAgICAgICAgICAgIHdoaWxlICghcGVnJHBvc0RldGFpbHNDYWNoZVtwXSkgewogICAgICAgICAgICAgIHAtLTsKICAgICAgICAgICAgfQogICAgICAgICAgICBkZXRhaWxzID0gcGVnJHBvc0RldGFpbHNDYWNoZVtwXTsKICAgICAgICAgICAgZGV0YWlscyA9IHsKICAgICAgICAgICAgICBsaW5lOiBkZXRhaWxzLmxpbmUsCiAgICAgICAgICAgICAgY29sdW1uOiBkZXRhaWxzLmNvbHVtbgogICAgICAgICAgICB9OwogICAgICAgICAgICB3aGlsZSAocCA8IHBvcykgewogICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHApID09PSAxMCkgewogICAgICAgICAgICAgICAgZGV0YWlscy5saW5lKys7CiAgICAgICAgICAgICAgICBkZXRhaWxzLmNvbHVtbiA9IDE7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGRldGFpbHMuY29sdW1uKys7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHArKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBwZWckcG9zRGV0YWlsc0NhY2hlW3Bvc10gPSBkZXRhaWxzOwogICAgICAgICAgICByZXR1cm4gZGV0YWlsczsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJGNvbXB1dGVMb2NhdGlvbihzdGFydFBvcywgZW5kUG9zKSB7CiAgICAgICAgICB2YXIgc3RhcnRQb3NEZXRhaWxzID0gcGVnJGNvbXB1dGVQb3NEZXRhaWxzKHN0YXJ0UG9zKSwgZW5kUG9zRGV0YWlscyA9IHBlZyRjb21wdXRlUG9zRGV0YWlscyhlbmRQb3MpOwogICAgICAgICAgcmV0dXJuIHsKICAgICAgICAgICAgc3RhcnQ6IHsKICAgICAgICAgICAgICBvZmZzZXQ6IHN0YXJ0UG9zLAogICAgICAgICAgICAgIGxpbmU6IHN0YXJ0UG9zRGV0YWlscy5saW5lLAogICAgICAgICAgICAgIGNvbHVtbjogc3RhcnRQb3NEZXRhaWxzLmNvbHVtbgogICAgICAgICAgICB9LAogICAgICAgICAgICBlbmQ6IHsKICAgICAgICAgICAgICBvZmZzZXQ6IGVuZFBvcywKICAgICAgICAgICAgICBsaW5lOiBlbmRQb3NEZXRhaWxzLmxpbmUsCiAgICAgICAgICAgICAgY29sdW1uOiBlbmRQb3NEZXRhaWxzLmNvbHVtbgogICAgICAgICAgICB9CiAgICAgICAgICB9OwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckZmFpbChleHBlY3RlZDIpIHsKICAgICAgICAgIGlmIChwZWckY3VyclBvcyA8IHBlZyRtYXhGYWlsUG9zKSB7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChwZWckY3VyclBvcyA+IHBlZyRtYXhGYWlsUG9zKSB7CiAgICAgICAgICAgIHBlZyRtYXhGYWlsUG9zID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICAgIHBlZyRtYXhGYWlsRXhwZWN0ZWQgPSBbXTsKICAgICAgICAgIH0KICAgICAgICAgIHBlZyRtYXhGYWlsRXhwZWN0ZWQucHVzaChleHBlY3RlZDIpOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckYnVpbGRTaW1wbGVFcnJvcihtZXNzYWdlLCBsb2NhdGlvbjIpIHsKICAgICAgICAgIHJldHVybiBuZXcgcGVnJFN5bnRheEVycm9yKG1lc3NhZ2UsIG51bGwsIG51bGwsIGxvY2F0aW9uMik7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRidWlsZFN0cnVjdHVyZWRFcnJvcihleHBlY3RlZDIsIGZvdW5kLCBsb2NhdGlvbjIpIHsKICAgICAgICAgIHJldHVybiBuZXcgcGVnJFN5bnRheEVycm9yKHBlZyRTeW50YXhFcnJvci5idWlsZE1lc3NhZ2UoZXhwZWN0ZWQyLCBmb3VuZCksIGV4cGVjdGVkMiwgZm91bmQsIGxvY2F0aW9uMik7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWRlY2xhcmF0aW9uKCkgewogICAgICAgICAgdmFyIHMwLCBzMSwgczIsIHMzLCBzNCwgczUsIHM2LCBzNywgczgsIHM5LCBzMTAsIHMxMSwgczEyLCBzMTM7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBwZWckcGFyc2VkZWNsYXJlVHlwZSgpOwogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlZGVjbGFyZU5hbWUoKTsKICAgICAgICAgICAgICAgIGlmIChzNCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBzNSA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgaWYgKHM1ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgczYgPSBwZWckcGFyc2Vjb21tZW50KCk7CiAgICAgICAgICAgICAgICAgICAgaWYgKHM2ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgICAgIGlmIChzNyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW5wdXQuY2hhckNvZGVBdChwZWckY3VyclBvcykgPT09IDQwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgczggPSBwZWckYzA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzOCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMxKTsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM4ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgczkgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM5ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTAgPSBwZWckcGFyc2VmaWVsZExpc3QoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMTAgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczExID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczExICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0MSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEyID0gcGVnJGMyOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEzID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEgPSBwZWckYzQoczIsIHM0LCBzNiwgczEwKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlZGVjbGFyZVR5cGUoKSB7CiAgICAgICAgICB2YXIgczA7CiAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA2KSA9PT0gcGVnJGM1KSB7CiAgICAgICAgICAgIHMwID0gcGVnJGM1OwogICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM2KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzcpIHsKICAgICAgICAgICAgICBzMCA9IHBlZyRjNzsKICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzgpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA1KSA9PT0gcGVnJGM5KSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRjOTsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMxMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWRlY2xhcmVOYW1lKCkgewogICAgICAgICAgdmFyIHMwLCBzMSwgczIsIHMzOwogICAgICAgICAgczAgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgczEgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMyID0gcGVnJHBhcnNlaW5kZXhUeXBlKCk7CiAgICAgICAgICAgICAgaWYgKHMyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzMSA9IFtzMSwgczJdOwogICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgICBzMSA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDQpID09PSBwZWckYzExKSB7CiAgICAgICAgICAgICAgICAgIHMyID0gcGVnJGMxMTsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMTIpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgczEgPSBbczEsIHMyXTsKICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgICAgICAgczEgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgczIgPSBwZWckcGFyc2VpbmRleFR5cGUoKTsKICAgICAgICAgICAgICAgICAgaWYgKHMyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjMTEpIHsKICAgICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJGMxMTsKICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDQ7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMxMik7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgczEgPSBbczEsIHMyLCBzM107CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2VpbmRleFR5cGUoKSB7CiAgICAgICAgICB2YXIgczA7CiAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA3KSA9PT0gcGVnJGMxMykgewogICAgICAgICAgICBzMCA9IHBlZyRjMTM7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDc7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzE0KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzE1KSB7CiAgICAgICAgICAgICAgczAgPSBwZWckYzE1OwogICAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDU7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMTYpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA2KSA9PT0gcGVnJGMxNykgewogICAgICAgICAgICAgICAgczAgPSBwZWckYzE3OwogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNjsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzE4KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlY29tbWVudCgpIHsKICAgICAgICAgIHZhciBzMDsKICAgICAgICAgIHMwID0gcGVnJHBhcnNlbm9uUXVvdGVkU3RyaW5nKCk7CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczAgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWZpZWxkTGlzdCgpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMywgczQsIHM1LCBzNjsKICAgICAgICAgIHMwID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgIGlmIChzMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMzID0gW107CiAgICAgICAgICAgICAgczQgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgICBzNSA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICBpZiAoczUgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlZmllbGQoKTsKICAgICAgICAgICAgICAgIGlmIChzNiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzNDsKICAgICAgICAgICAgICAgICAgczUgPSBwZWckYzE5KHMxLCBzNik7CiAgICAgICAgICAgICAgICAgIHM0ID0gczU7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHM0OwogICAgICAgICAgICAgICAgICBzNCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczQ7CiAgICAgICAgICAgICAgICBzNCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHdoaWxlIChzNCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczMucHVzaChzNCk7CiAgICAgICAgICAgICAgICBzNCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICBpZiAoczUgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgczYgPSBwZWckcGFyc2VmaWVsZCgpOwogICAgICAgICAgICAgICAgICBpZiAoczYgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzNDsKICAgICAgICAgICAgICAgICAgICBzNSA9IHBlZyRjMTkoczEsIHM2KTsKICAgICAgICAgICAgICAgICAgICBzNCA9IHM1OwogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczQ7CiAgICAgICAgICAgICAgICAgICAgczQgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHM0OwogICAgICAgICAgICAgICAgICBzNCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczQgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICBpZiAoczQgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMxID0gcGVnJGMyMChzMSwgczMpOwogICAgICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2Vjb21tZW50U3RhcnQoKSB7CiAgICAgICAgICB2YXIgczA7CiAgICAgICAgICBpZiAoaW5wdXQuY2hhckNvZGVBdChwZWckY3VyclBvcykgPT09IDM1KSB7CiAgICAgICAgICAgIHMwID0gcGVnJGMyMTsKICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMjIpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWludGVybmFsQ29tbWVudCgpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMywgczQ7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBwZWckcGFyc2Vjb21tZW50U3RhcnQoKTsKICAgICAgICAgICAgaWYgKHMyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczMgPSBwZWckcGFyc2Vub25RdW90ZWRTdHJpbmcoKTsKICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgIHMxID0gW3MxLCBzMiwgczMsIHM0XTsKICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlZmllbGQoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczMsIHM0LCBzNSwgczYsIHM3LCBzOCwgczksIHMxMCwgczExLCBzMTIsIHMxMzsKICAgICAgICAgIHMwID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkVHlwZSgpOwogICAgICAgICAgaWYgKHMxICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMyID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gNTkpIHsKICAgICAgICAgICAgICAgICAgICBzNSA9IHBlZyRjMjM7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBzNSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMyNCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzNSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgIGlmIChzNiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgczcgPSBwZWckcGFyc2Vjb21tZW50KCk7CiAgICAgICAgICAgICAgICAgICAgICBpZiAoczcgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMxID0gcGVnJGMyNShzMSwgczMsIHM3KTsKICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkVHlwZSgpOwogICAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBzMiA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gOTEpIHsKICAgICAgICAgICAgICAgICAgczMgPSBwZWckYzI2OwogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMyNyk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBzNCA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VmaWVsZFNpemUoKTsKICAgICAgICAgICAgICAgICAgICBpZiAoczUgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgaWYgKHM2ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gOTMpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRjMjg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMyOSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzNyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIHM4ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzOCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgczkgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczkgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEwID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczEwICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA1OSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczExID0gcGVnJGMyMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMjQpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczExICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczEyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxMyA9IHBlZyRwYXJzZWNvbW1lbnQoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRzYXZlZFBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxID0gcGVnJGMzMChzMSwgczUsIHM5LCBzMTMpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gczE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkVHlwZSgpOwogICAgICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0MCkgewogICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJGMwOwogICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgIGlmIChzNCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VmaWVsZFZhbHVlcygpOwogICAgICAgICAgICAgICAgICAgICAgaWYgKHM1ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoczYgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW5wdXQuY2hhckNvZGVBdChwZWckY3VyclBvcykgPT09IDQxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRjMjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHM3ID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM3ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzOCA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzOCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzOSA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM5ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEwID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMTAgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gNTkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczExID0gcGVnJGMyMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzI0KTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMTIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTMgPSBwZWckcGFyc2Vjb21tZW50KCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMSA9IHBlZyRjMzEoczEsIHM1LCBzOSwgczEzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gczE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczAgPSBwZWckcGFyc2VpbnRlcm5hbENvbW1lbnQoKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlZmllbGRWYWx1ZXMoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczMsIHM0LCBzNSwgczY7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBbXTsKICAgICAgICAgICAgczMgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0NCkgewogICAgICAgICAgICAgIHM0ID0gcGVnJGMzMjsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHM0ID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzMzKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgaWYgKHM1ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzNiA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICAgIGlmIChzNiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMzsKICAgICAgICAgICAgICAgICAgczQgPSBwZWckYzE5KHMxLCBzNik7CiAgICAgICAgICAgICAgICAgIHMzID0gczQ7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMzOwogICAgICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczM7CiAgICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczM7CiAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHdoaWxlIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMyLnB1c2goczMpOwogICAgICAgICAgICAgIHMzID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0NCkgewogICAgICAgICAgICAgICAgczQgPSBwZWckYzMyOwogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgczQgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzMzKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzNSA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgIGlmIChzNSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBzNiA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICAgICAgaWYgKHM2ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczM7CiAgICAgICAgICAgICAgICAgICAgczQgPSBwZWckYzE5KHMxLCBzNik7CiAgICAgICAgICAgICAgICAgICAgczMgPSBzNDsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMzOwogICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMzsKICAgICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMzOwogICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICBzMSA9IHBlZyRjMzQoczEsIHMyKTsKICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWZpZWxkVHlwZSgpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMzsKICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDMpID09PSBwZWckYzM1KSB7CiAgICAgICAgICAgIHMwID0gcGVnJGMzNTsKICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gMzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMzYpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjMzcpIHsKICAgICAgICAgICAgICBzMCA9IHBlZyRjMzc7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMzOCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzM5KSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRjMzk7CiAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA1OwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzQxKSB7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM0MTsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNjsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDIpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjNDMpIHsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNDM7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM0NCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzQ1KSB7CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNDU7CiAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA1OwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDYpOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzQ3KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM0NzsKICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNTsKICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDgpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjNDkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNDk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM1MCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzUxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNTE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNTIpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDcpID09PSBwZWckYzUzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM1MzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNTQpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjNTUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNTU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM1Nik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzU3KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNTc7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNTgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzU5KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM1OTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNjApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgMykgPT09IHBlZyRjNjEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNjE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM2Mik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEgPSBwZWckcGFyc2VkZWNsYXJlVHlwZSgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczMgPSBwZWckcGFyc2VkZWNsYXJlTmFtZSgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMSA9IHBlZyRjNjMoczEsIHMzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWZpZWxkU2l6ZSgpIHsKICAgICAgICAgIHZhciBzMDsKICAgICAgICAgIHMwID0gcGVnJHBhcnNlbnVtYmVyKCk7CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczAgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZW5hbWUoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczMsIHM0OwogICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgIHMxID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICBpZiAocGVnJGM2NC50ZXN0KGlucHV0LmNoYXJBdChwZWckY3VyclBvcykpKSB7CiAgICAgICAgICAgIHMyID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNjUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczMgPSBbXTsKICAgICAgICAgICAgaWYgKHBlZyRjNjYudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgIHM0ID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHM0ID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzY3KTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgd2hpbGUgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczMucHVzaChzNCk7CiAgICAgICAgICAgICAgaWYgKHBlZyRjNjYudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgICAgczQgPSBpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpOwogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgczQgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzY3KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMzICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczIgPSBbczIsIHMzXTsKICAgICAgICAgICAgICBzMSA9IHMyOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczE7CiAgICAgICAgICAgICAgczEgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBwZWckY3VyclBvcyA9IHMxOwogICAgICAgICAgICBzMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgIHMxID0gcGVnJGM2OChzMSk7CiAgICAgICAgICB9CiAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2VxdW90ZWRTdHJpbmcoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczM7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSAzNCkgewogICAgICAgICAgICBzMSA9IHBlZyRjNjk7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzcwKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMxICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMyID0gW107CiAgICAgICAgICAgIGlmIChwZWckYzcxLnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgICBzMyA9IGlucHV0LmNoYXJBdChwZWckY3VyclBvcyk7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3Mik7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHdoaWxlIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMyLnB1c2goczMpOwogICAgICAgICAgICAgIGlmIChwZWckYzcxLnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgICAgIHMzID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3Mik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gMzQpIHsKICAgICAgICAgICAgICAgIHMzID0gcGVnJGM2OTsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3MCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICBzMSA9IHBlZyRjNzMoczIpOwogICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlbm9uUXVvdGVkU3RyaW5nKCkgewogICAgICAgICAgdmFyIHMwLCBzMSwgczI7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBbXTsKICAgICAgICAgIGlmIChwZWckYzc0LnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgczIgPSBpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpOwogICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgczIgPSBwZWckRkFJTEVEOwogICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3NSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMS5wdXNoKHMyKTsKICAgICAgICAgICAgaWYgKHBlZyRjNzQudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgIHMyID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzc1KTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgczEgPSBwZWckYzc2KHMxKTsKICAgICAgICAgIH0KICAgICAgICAgIHMwID0gczE7CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZW51bWJlcigpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMzsKICAgICAgICAgIHBlZyRzaWxlbnRGYWlscysrOwogICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgIHMxID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgaWYgKHMxICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMyID0gW107CiAgICAgICAgICAgIGlmIChwZWckYzc4LnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgICBzMyA9IGlucHV0LmNoYXJBdChwZWckY3VyclBvcyk7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3OSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHdoaWxlIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczIucHVzaChzMyk7CiAgICAgICAgICAgICAgICBpZiAocGVnJGM3OC50ZXN0KGlucHV0LmNoYXJBdChwZWckY3VyclBvcykpKSB7CiAgICAgICAgICAgICAgICAgIHMzID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNzkpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICBzMSA9IHBlZyRjODAoKTsKICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICB9CiAgICAgICAgICBwZWckc2lsZW50RmFpbHMtLTsKICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzc3KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2VfKCkgewogICAgICAgICAgdmFyIHMwLCBzMTsKICAgICAgICAgIHBlZyRzaWxlbnRGYWlscysrOwogICAgICAgICAgczAgPSBbXTsKICAgICAgICAgIGlmIChwZWckYzgyLnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgczEgPSBpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpOwogICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgczEgPSBwZWckRkFJTEVEOwogICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM4Myk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMC5wdXNoKHMxKTsKICAgICAgICAgICAgaWYgKHBlZyRjODIudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgIHMxID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMxID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzgzKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHBlZyRzaWxlbnRGYWlscy0tOwogICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMxID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjODEpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIHBlZyRyZXN1bHQgPSBwZWckc3RhcnRSdWxlRnVuY3Rpb24oKTsKICAgICAgICBpZiAocGVnJHJlc3VsdCAhPT0gcGVnJEZBSUxFRCAmJiBwZWckY3VyclBvcyA9PT0gaW5wdXQubGVuZ3RoKSB7CiAgICAgICAgICByZXR1cm4gcGVnJHJlc3VsdDsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKHBlZyRyZXN1bHQgIT09IHBlZyRGQUlMRUQgJiYgcGVnJGN1cnJQb3MgPCBpbnB1dC5sZW5ndGgpIHsKICAgICAgICAgICAgcGVnJGZhaWwocGVnJGVuZEV4cGVjdGF0aW9uKCkpOwogICAgICAgIC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HJlc3BvbnNlID0gYXdhaXQgdGhpcy5mZXRjaEltcGxlbWVudGF0aW9uKGlucHV0LCB7CiAgICAgICAgICAgIC4uLmluaXQyLAogICAgICAgICAgICBjYWNoZTogInJlbG9hZCIKICAgICAgICAgIH0pOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB0aHJvdyBlOwogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gcmVzcG9uc2U7CiAgICB9CiAgICBhc3luYyByZWFkKGJ1ZmZlciwgb2Zmc2V0ID0gMCwgbGVuZ3RoLCBwb3NpdGlvbiA9IDAsIG9wdHMgPSB7fSkgewogICAgICBjb25zdCB7IGhlYWRlcnMgPSB7fSwgc2lnbmFsLCBvdmVycmlkZXMgPSB7fSB9ID0gb3B0czsKICAgICAgaWYgKGxlbmd0aCA8IEluZmluaXR5KSB7CiAgICAgICAgaGVhZGVycy5yYW5nZSA9IGBieXRlcz0ke3Bvc2l0aW9ufS0ke3Bvc2l0aW9uICsgbGVuZ3RofWA7CiAgICAgIH0gZWxzZSBpZiAobGVuZ3RoID09PSBJbmZpbml0eSAmJiBwb3NpdGlvbiAhPT0gMCkgewogICAgICAgIGhlYWRlcnMucmFuZ2UgPSBgYnl0ZXM9JHtwb3NpdGlvbn0tYDsKICAgICAgfQogICAgICBjb25zdCBhcmdzID0gewogICAgICAgIC4uLnRoaXMuYmFzZU92ZXJyaWRlcywKICAgICAgICAuLi5vdmVycmlkZXMsCiAgICAgICAgaGVhZGVyczogewogICAgICAgICAgLi4uaGVhZGVycywKICAgICAgICAgIC4uLm92ZXJyaWRlcy5oZWFkZXJzLAogICAgICAgICAgLi4udGhpcy5iYXNlT3ZlcnJpZGVzLmhlYWRlcnMKICAgICAgICB9LAogICAgICAgIG1ldGhvZDogIkdFVCIsCiAgICAgICAgcmVkaXJlY3Q6ICJmb2xsb3ciLAogICAgICAgIG1vZGU6ICJjb3JzIiwKICAgICAgICBzaWduYWwKICAgICAgfTsKICAgICAgY29uc3QgcmVzcG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cgZTsKICAgIH0KICB9CiAgYXN5bmMgZnVuY3Rpb24gdW56aXBDaHVua1NsaWNlKGlucHV0RGF0YSwgY2h1bmspIHsKICAgIHRyeSB7CiAgICAgIGxldCBzdHJtOwogICAgICBjb25zdCB7IG1pbnYsIG1heHYgfSA9IGNodW5rOwogICAgICBsZXQgY3BvcyA9IG1pbnYuYmxvY2tQb3NpdGlvbjsKICAgICAgbGV0IGRwb3MgPSBtaW52LmRhdGFQb3NpdGlvbjsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGNvbnN0IGNwb3NpdGlvbnMgPSBbXTsKICAgICAgY29uc3QgZHBvc2l0aW9ucyA9IFtdOwogICAgICBsZXQgdG90YWxTaXplID0gMDsKICAgICAgbGV0IGkgPSAwOwogICAgICBkbyB7CiAgICAgICAgY29uc3QgcmVtYWluaW5nSW5wdXQgPSBpbnB1dERhdGEuc3ViYXJyYXkoY3BvcyAtIG1pbnYuYmxvY2tQb3NpdGlvbik7CiAgICAgICAgY29uc3QgaW5mbGF0b3IgPSBuZXcgaW1wb3J0X3Bha28uSW5mbGF0ZSgpOwogICAgICAgICh7IHN0cm0gfSA9IGluZmxhdG9yKTsKICAgICAgICBpbmZsYXRvci5wdXNoKHJlbWFpbmluZ0lucHV0LCBpbXBvcnRfcGFrby5aX1NZTkNfRkxVU0gpOwogICAgICAgIGlmIChpbmZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IG5ldyBFcnJvcihpbmZsYXRvci5tc2cpOwogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIyID0gaW5mbGF0b3IucmVzdWx0OwogICAgICAgIGNodW5rcy5wdXNoKGJ1ZmZlcjIpOwogICAgICAgIGxldCBsZW4gPSBidWZmZXIyLmxlbmd0aDsKICAgICAgICBjcG9zaXRpb25zLnB1c2goY3Bvcyk7CiAgICAgICAgZHBvc2l0aW9ucy5wdXNoKGRwb3MpOwogICAgICAgIGlmIChjaHVua3MubGVuZ3RoID09PSAxICYmIG1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KICAgICAgICByZXR1cm4gZGlmOwogICAgICB9IGVsc2UgewogICAgICAgIHJldHVybiBjMC5taW52LmRhdGFQb3NpdGlvbiAtIGMxLm1pbnYuZGF0YVBvc2l0aW9uOwogICAgICB9CiAgICB9KTsKICAgIGNodW5rcy5mb3JFYWNoKChjaHVuaykgPT4gewogICAgICBpZiAoIWxvd2VzdCB8fCBjaHVuay5tYXh2LmNvbXBhcmVUbyhsb3dlc3QpID4gMCkgewogICAgICAgIGlmIChsYXN0Q2h1bmsgPT09IG51bGwpIHsKICAgICAgICAgIG1lcmdlZENodW5rcy5wdXNoKGNodW5rKTsKICAgICAgICAgIGxhc3RDaHVuayA9IGNodW5rOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoY2FuTWVyZ2VCbG9ja3MobGFzdENodW5rLCBjaHVuaykpIHsKICAgICAgICAgICAgaWYgKGNodW5rLm1heHYuY29tcGFyZVRvKGxhc3RDaHVuay5tYXh2KSA+IDApIHsKICAgICAgICAgICAgICBsYXN0Q2h1bmsubWF4diA9IGNodW5rLm1heHY7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG1lcmdlZENodW5rcy5wdXNoKGNodW5rKTsKICAgICAgICAgICAgbGFzdENodW5rID0gY2h1bms7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICB9KTsKICAgIHJldHVybiBtZXJnZWRDaHVua3M7CiAgfQoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vQGdtb2QrdGFiaXhAMS41LjExL25vZGVfbW9kdWxlcy9AZ21vZC90YWJpeC9lc20vdGJpLmpzCiAgaW5pdF9idWZmZXJfc2hpbSgpOwogIHZhciBpbXBvcnRfbG9uZzIgPSBfX3RvTW9kdWxlKHJlcXVpcmVfbG9uZygpKTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL0BnbW9kK3RhYml4QDEuNS4xMS9ub2RlX21vZHVsZXMvQGdtb2QvdGFiaXg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V0OwogICAgICB9CiAgICB9CiAgICBhc3luYyBwYXJzZShvcHRzID0ge30pIHsKICAgICAgaWYgKCF0aGlzLnBhcnNlUCkgewogICAgICAgIHRoaXMucGFyc2VQID0gdGhpcy5fcGFyc2Uob3B0cykuY2F0Y2goKGUpID0+IHsKICAgICAgICAgIHRoaXMucGFyc2VQID0gdm9pZCAwOwogICAgICAgICAgdGhyb3cgZTsKICAgICAgICB9KTsKICAgICAgfQogICAgICByZXR1cm4gdGhpcy5wYXJzZVA7CiAgICB9CiAgICBhc3luYyBoYXNSZWZTZXEoc2VxSWQsIG9wdHMgPSB7fSkgewogICAgICByZXR1cm4gISEoKGF3YWl0IHRoaXMucGFyc2Uob3B0cykpLmluZGljZXNbc2VxSWRdIHx8IHt9KS5iaW5JbmRleDsKICAgIH0KICB9OwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vQGdtb2QrdGFiaXhAMS41LjExL25vZGVfbW9kdWxlcy9AZ21vZC90YWJpeC9lc20vdGJpLmpzCiAgdmFyIFRCSV9NQUdJQyA9IDIxNTc4MzI0OwogIHZhciBUQURfTElEWF9TSElGVCA9IDE0OwogIGZ1bmN0aW9uIHJlZzJiaW5zKGJlZywgZW5kKSB7CiAgICBiZWcgKz0gMTsKICAgIGVuZCAtPSAxOwogICAgcmV0dXJuIFsKICAgICAgWzAsIDBdLAogICAgICBbMSArIChiZWcgPj4gMjYpLCAxICsgKGVuZCA+PiAyNildLAogICAgICBbOSArIChiZWcgPj4gMjMpLCA5ICsgKGVuZCA+PiAyMyldLAogICAgICBbNzMgKyAoYmVnID4+IDIwKSwgNzMgKyAoZW5kID4+IDIwKV0sCiAgICAgIFs1ODUgKyAoYmVnID4+IDE3KSwgNTg1ICsgKGVuZCA+PiAxNyldLAogICAgICBbNDY4MSArIChiZWcgPj4gMTQpLCA0NjgxICsgKGVuZCA+PiAxNCldCiAgICBdOwogIH0KICB2YXIgVGFiaXhJbmRleCA9IGNsYXNzIGV4dGVuZHMgSW5kZXhGaWxlIHsKICAgIGFzeW5jIGxpbmVDb3VudChyZWZOYW1lLCBvcHRzID0ge30pIHsKICAgICAgY29uc3QgaW5kZXhEYXRhID0gYXdhaXQgdGhpcy5wYXJzZShvcHRzKTsKICAgICAgaWYgKCFpbmRleERhdGEpIHsKICAgICAgICByZXR1cm4gLTE7CiAgICAgIH0KICAgICAgY29uc3QgcmVmSWQgPSBpbmRleERhdGEucmVmTmFtZVRvSWRbcmVmTmFtZV07CiAgICAgIGNvbnN0IGlkeCA9IGluZGV4RGF0YS5pbmRpY2VzW3JlZklkXTsKICAgICAgaWYgKCFpZHgpIHsKICAgICAgICByZXR1cm4gLTE7CiAgICAgIH0KICAgICAgY29uc3QgeyBzdGF0cyB9ID0gaW5kZXhEYXRhLmluZGljZXNbcmVmSWRdOwogICAgICBpZiAoc3RhdHMpIHsKICAgICAgICByZXR1cm4gc3RhdHMubGluZUNvdW50OwogICAgICB9CiAgICAgIHJldHVybiAtMTsKICAgIH0KICAgIGFzeW5jIF9wYXJzZShvcHRzID0ge30pIHsKICAgICAgY29uc3QgYnVmID0gYXdhaXQgdGhpcy5maWxlaGFuZGxlLnJlYWRGaWxlKG9wdHMpOwogICAgICBjb25zdCBieXRlcyA9IGF3YWl0IHVuemlwKGJ1Zik7CiAgICAgIGNoZWNrQWJvcnRTaWduYWwob3B0cy5zaWduYWwpOwogICAgICBpZiAoYnl0ZXMucmVhZFVJbnQzMkxFKDApICE9PSBUQklfTUFHSUMpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoIk5vdCBhIFRCSSBmaWxlIik7CiAgICAgIH0KICAgICAgY29uc3QgcmVmQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRSg0KTsKICAgICAgY29uc3QgZm9ybWF0RmxhZ3MgPSBieXRlcy5yZWFkSW50MzJMRSg4KTsKICAgICAgY29uc3QgY29vcmRpbmF0ZVR5cGUgPSBmb3JtYXRGbGFncyAmIDY1NTM2ID8gInplcm8tYmFzZWQtaGFsZi1vcGVu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zmc2V0ICs9IDE2ICogY2h1bmtDb3VudDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGNvbnN0IGNodW5rQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgICAgICBjb25zdCBjaHVua3MgPSBuZXcgQXJyYXkoY2h1bmtDb3VudCk7CiAgICAgICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgY2h1bmtDb3VudDsgayArPSAxKSB7CiAgICAgICAgICAgICAgY29uc3QgdSA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCk7CiAgICAgICAgICAgICAgY29uc3QgdiA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCArIDgpOwogICAgICAgICAgICAgIGN1cnJPZmZzZXQgKz0gMTY7CiAgICAgICAgICAgICAgZmlyc3REYXRhTGluZSA9IHRoaXMuX2ZpbmRGaXJzdERhdGEoZmlyc3REYXRhTGluZSwgdSk7CiAgICAgICAgICAgICAgY2h1bmtzW2tdID0gbmV3IENodW5rKHUsIHYsIGJpbik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYmluSW5kZXhbYmluXSA9IGNodW5rczsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY29uc3QgbGluZWFyQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICBjdXJyT2Zmc2V0ICs9IDQ7CiAgICAgICAgY29uc3QgbGluZWFySW5kZXggPSBuZXcgQXJyYXkobGluZWFyQ291bnQpOwogICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgbGluZWFyQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgbGluZWFySW5kZXhba10gPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgY3Vyck9mZnNldCArPSA4OwogICAgICAgICAgZmlyc3REYXRhTGluZSA9IHRoaXMuX2ZpbmRGaXJzdERhdGEoZmlyc3REYXRhTGluZSwgbGluZWFySW5kZXhba10pOwogICAgICAgIH0KICAgICAgICByZXR1cm4geyBiaW5JbmRleCwgbGluZWFySW5kZXgsIHN0YXRzIH07CiAgICAgIH0pOwogICAgICByZXR1cm4gewogICAgICAgIGluZGljZXMsCiAgICAgICAgbWV0YUNoYXIsCiAgICAgICAgbWF4QmluTnVtYmVyLAogICAgICAgIG1heFJlZkxlbmd0aCwKICAgICAgICBza2lwTGluZXMsCiAgICAgICAgZmlyc3REYXRhTGluZSwKICAgICAgICBjb2x1bW5OdW1iZXJzLAogICAgICAgIGNvb3JkaW5hdGVUeXBlLAogICAgICAgIGZvcm1hdCwKICAgICAgICByZWZJZFRvTmFtZSwKICAgICAgICByZWZOYW1lVG9JZCwKICAgICAgICBtYXhCbG9ja1NpemU6IDEgPDwgMTYKICAgICAgfTsKICAgIH0KICAgIHBhcnNlUHNldWRvQmluKGJ5dGVzLCBvZmZzZXQpIHsKICAgICAgY29uc3QgbGluZUNvdW50ID0gbG9uZ1RvTnVtYmVyKGltcG9ydF9sb25nMi5kZWZhdWx0LmZyb21CeXRlc0xFKGJ5dGVzLnNsaWNlKG9mZnNldCArIDE2LCBvZmZzZXQgKyAyNCksIHRydWUpKTsKICAgICAgcmV0dXJuIHsgbGluZUNvdW50IH07CiAgICB9CiAgICBfcGFyc2VOYW1lQnl0ZXMobmFtZXNCeXRlcykgewogICAgICBsZXQgY3VyclJlZklkID0gMDsKICAgICAgbGV0IGN1cnJOYW1lU3RhcnQgPSAwOwogICAgICBjb25zdCByZWZJZFRvTmFtZSA9IFtdOwogICAgICBjb25zdCByZWZOYW1lVG9JZCA9IHt9OwogICAgICBmb3IgKGxldCBpID0gMDsgaSA8IG5hbWVzQnl0ZXMubGVuZ3RoOyBpICs9IDEpIHsKICAgICAgICBpZiAoIW5hbWVzQnl0ZXNbaV0pIHsKICAgICAgICAgIGlmIChjdXJyTmFtZVN0YXJ0IDwgaSkgewogICAgICAgICAgICBsZXQgcmVmTmFtZSA9IG5hbWVzQnl0ZXMudG9TdHJpbmcoInV0ZjgiLCBjdXJyTmFtZVN0YXJ0LCBpKTsKICAgICAgICAgICAgcmVmTmFtZSA9IHRoaXMucmVuYW1lUmVmU2VxKHJlZk5hbWUpOwogICAgICAgICAgICByZWZJZFRvTmFtZVtjdXJyUmVmSWRdID0gcmVmTmFtZTsKICAgICAgICAgICAgcmVmTmFtZVRvSWRbcmVmTmFtZV0gPSBjdXJyUmVmSWQ7CiAgICAgICAgICB9CiAgICAgICAgICBjdXJyTmFtZVN0YXJ0ID0gaSArIDE7CiAgICAgICAgICBjdXJyUmVmSWQgKz0gMTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIHsgcmVmTmFtZVRvSWQsIHJlZklkVG9OYW1lIH07CiAgICB9CiAgICBhc3luYyBibG9ja3NGb3JSYW5nZShyZWZOYW1lLCBtaW4sIG1heCwgb3B0cyA9IHt9KSB7CiAgICAgIGlmIChtaW4gPCAwKSB7CiAgICAgICAgbWluID0gMDsKICAgICAgfQogICAgICBjb25zdCBpbmRleERhdGEgPSBhd2FpdCB0aGlzLnBhcnNlKG9wdHMpOwogICAgICBpZiAoIWluZGV4RGF0YSkgewogICAgICAgIHJldHVybiBbXTsKICAgICAgfQogICAgICBjb25zdCByZWZJZCA9IGluZGV4RGF0YS5yZWZOYW1lVG9JZFtyZWZOYW1lXTsKICAgICAgY29uc3QgYmEgPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmICghYmEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3QgbWluT2Zmc2V0ID0gYmEubGluZWFySW5kZXgubGVuZ3RoID8gYmEubGluZWFySW5kZXhbbWluID4+IFRBRF9MSURYX1NISUZUID49IGJhLmxpbmVhckluZGV4Lmxlbmd0aCA/IGJhLmxpbmVhckluZGV4Lmxlbmd0aCAtIDEgOiBtaW4gPj4gVEFEX0xJRFhfU0hJRlRdIDogbmV3IFZpcnR1YWxPZmZzZXQoMCwgMCk7CiAgICAgIGlmICghbWluT2Zmc2V0KSB7CiAgICAgICAgY29uc29sZS53YXJuKCJxdWVyeWluZyBvdXRzaWRlIG9mIHBvc3NpYmxlIHRhYml4IHJhbmdlIik7CiAgICAgIH0KICAgICAgY29uc3Qgb3ZlcmxhcHBpbmdCaW5zID0gcmVnMmJpbnMobWluLCBtYXgpOwogICAgICBjb25zdCBjaHVua3MgPSBbXTsKICAgICAgZm9yIChjb25zdCBbc3RhcnQsIGVuZF0gb2Ygb3ZlcmxhcHBpbmdCaW5zKSB7CiAgICAgICAgZm9yIChsZXQgYmluID0gc3RhcnQ7IGJpbiA8PSBlbmQ7IGJpbisrKSB7CiAgICAgICAgICBpZiAoYmEuYmluSW5kZXhbYmluXSkgewogICAgICAgICAgICBjb25zdCBiaW5DaHVua3MgPSBiYS5iaW5JbmRleFtiaW5dOwogICAgICAgICAgICBmb3IgKGxldCBjID0gMDsgYyA8IGJpbkNodW5rcy5sZW5ndGg7ICsrYykgewogICAgICAgICAgICAgIGNodW5rcy5wdXNoKG5ldyBDaHVuayhiaW5DaHVua3NbY10ubWludiwgYmluQ2h1bmtzW2NdLm1heHYsIGJpbikpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGNvbnN0IG5pbnR2ID0gYmEubGluZWFySW5kZXgubGVuZ3RoOwogICAgICBsZXQgbG93ZXN0ID0gbnVsbDsKICAgICAgY29uc3QgbWluTGluID0gTWF0aC5taW4obWluID4+IDE0LCBuaW50diAtIDEpOwogICAgICBjb25zdCBtYXhMaW4gPSBNYXRoLm1pbihtYXggPj4gMTQsIG5pbnR2IC0gMSk7CiAgICAgIGZvciAobGV0IGkgPSBtaW5MaW47IGkgPD0gbWF4TGluOyArK2kpIHsKICAgICAgICBjb25zdCB2cCA9IGJhLmxpbmVhckluZGV4W2ldOwogICAgICAgIGlmICh2cCkgewogIC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JPZmZzZXQpOwogICAgICAgICAgaWYgKGJpbiA+IHRoaXMubWF4QmluTnVtYmVyKSB7CiAgICAgICAgICAgIHN0YXRzID0gdGhpcy5wYXJzZVBzZXVkb0JpbihieXRlcywgY3Vyck9mZnNldCArIDQpOwogICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDQgKyA4ICsgNCArIDE2ICsgMTY7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjb25zdCBsb2Zmc2V0ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0ICsgNCk7CiAgICAgICAgICAgIGZpcnN0RGF0YUxpbmUgPSB0aGlzLl9maW5kRmlyc3REYXRhKGZpcnN0RGF0YUxpbmUsIGxvZmZzZXQpOwogICAgICAgICAgICBjb25zdCBjaHVua0NvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCArIDEyKTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgY29uc3QgY2h1bmtzID0gbmV3IEFycmF5KGNodW5rQ291bnQpOwogICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGNodW5rQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgICAgIGNvbnN0IHUgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgICAgIGNvbnN0IHYgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQgKyA4KTsKICAgICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDE2OwogICAgICAgICAgICAgIGNodW5rc1trXSA9IG5ldyBDaHVuayh1LCB2LCBiaW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJpbkluZGV4W2Jpbl0gPSBjaHVua3M7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiB7IGJpbkluZGV4LCBzdGF0cyB9OwogICAgICB9KTsKICAgICAgcmV0dXJuIHsKICAgICAgICAuLi5hdXgsCiAgICAgICAgY3NpOiB0cnVlLAogICAgICAgIHJlZkNvdW50LAogICAgICAgIG1heEJsb2NrU2l6ZTogMSA8PCAxNiwKICAgICAgICBmaXJzdERhdGFMaW5lLAogICAgICAgIGNzaVZlcnNpb24sCiAgICAgICAgaW5kaWNlcywKICAgICAgICBkZXB0aDogdGhpcy5kZXB0aCwKICAgICAgICBtYXhCaW5OdW1iZXI6IHRoaXMubWF4QmluTnVtYmVyLAogICAgICAgIG1heFJlZkxlbmd0aAogICAgICB9OwogICAgfQogICAgcGFyc2VQc2V1ZG9CaW4oYnl0ZXMsIG9mZnNldCkgewogICAgICBjb25zdCBsaW5lQ291bnQgPSBsb25nVG9OdW1iZXIoaW1wb3J0X2xvbmczLmRlZmF1bHQuZnJvbUJ5dGVzTEUoYnl0ZXMuc2xpY2Uob2Zmc2V0ICsgMjgsIG9mZnNldCArIDM2KSwgdHJ1ZSkpOwogICAgICByZXR1cm4geyBsaW5lQ291bnQgfTsKICAgIH0KICAgIGFzeW5jIGJsb2Nrc0ZvclJhbmdlKHJlZk5hbWUsIG1pbiwgbWF4LCBvcHRzID0ge30pIHsKICAgICAgaWYgKG1pbiA8IDApIHsKICAgICAgICBtaW4gPSAwOwogICAgICB9CiAgICAgIGNvbnN0IGluZGV4RGF0YSA9IGF3YWl0IHRoaXMucGFyc2Uob3B0cyk7CiAgICAgIGlmICghaW5kZXhEYXRhKSB7CiAgICAgICAgcmV0dXJuIFtdOwogICAgICB9CiAgICAgIGNvbnN0IHJlZklkID0gaW5kZXhEYXRhLnJlZk5hbWVUb0lkW3JlZk5hbWVdOwogICAgICBjb25zdCBiYSA9IGluZGV4RGF0YS5pbmRpY2VzW3JlZklkXTsKICAgICAgaWYgKCFiYSkgewogICAgICAgIHJldHVybiBbXTsKICAgICAgfQogICAgICBjb25zdCBvdmVybGFwcGluZ0JpbnMgPSB0aGlzLnJlZzJiaW5zKG1pbiwgbWF4KTsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGZvciAoY29uc3QgW3N0YXJ0LCBlbmRdIG9mIG92ZXJsYXBwaW5nQmlucykgewogICAgICAgIGZvciAobGV0IGJpbiA9IHN0YXJ0OyBiaW4gPD0gZW5kOyBiaW4rKykgewogICAgICAgICAgaWYgKGJhLmJpbkluZGV4W2Jpbl0pIHsKICAgICAgICAgICAgY29uc3QgYmluQ2h1bmtzID0gYmEuYmluSW5kZXhbYmluXTsKICAgICAgICAgICAgZm9yIChsZXQgYyA9IDA7IGMgPCBiaW5DaHVua3MubGVuZ3RoOyArK2MpIHsKICAgICAgICAgICAgICBjaHVua3MucHVzaChuZXcgQ2h1bmsoYmluQ2h1bmtzW2NdLm1pbnYsIGJpbkNodW5rc1tjXS5tYXh2LCBiaW4pKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gb3B0aW1pemVDaHVua3MoY2h1bmtzLCBuZXcgVmlydHVhbE9mZnNldCgwLCAwKSk7CiAgICB9CiAgICByZWcyYmlucyhiZWcsIGVuZCkgewogICAgICBiZWcgLT0gMTsKICAgICAgaWYgKGJlZyA8IDEpIHsKICAgICAgICBiZWcgPSAxOwogICAgICB9CiAgICAgIGlmIChlbmQgPiAyICoqIDUwKSB7CiAgICAgICAgZW5kID0gMiAqKiAzNDsKICAgICAgfQogICAgICBlbmQgLT0gMTsKICAgICAgbGV0IGwgPSAwOwogICAgICBsZXQgdCA9IDA7CiAgICAgIGxldCBzID0gdGhpcy5taW5TaGlmdCArIHRoaXMuZGVwdGggKiAzOwogICAgICBjb25zdCBiaW5zID0gW107CiAgICAgIGZvciAoOyBsIDw9IHRoaXMuZGVwdGg7IHMgLT0gMywgdCArPSBsc2hpZnQoMSwgbCAqIDMpLCBsICs9IDEpIHsKICAgICAgICBjb25zdCBiID0gdCArIHJzaGlmdChiZWcsIHMpOwogICAgICAgIGNvbnN0IGUgPSB0ICsgcnNoaWZ0KGVuZCwgcyk7CiAgICAgICAgaWYgKGUg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ja1N0YXJ0KTsKICAgICAgICAgIGlmIChuID09PSAtMSkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIGNvbnN0IGIgPSBidWZmZXIuc2xpY2UoYmxvY2tTdGFydCwgbik7CiAgICAgICAgICBjb25zdCBsaW5lID0gKGRlY29kZXIgPT09IG51bGwgfHwgZGVjb2RlciA9PT0gdm9pZCAwID8gdm9pZCAwIDogZGVjb2Rlci5kZWNvZGUoYikpIHx8IGIudG9TdHJpbmcoKTsKICAgICAgICAgIGlmIChkcG9zaXRpb25zKSB7CiAgICAgICAgICAgIHdoaWxlIChibG9ja1N0YXJ0ICsgYy5taW52LmRhdGFQb3NpdGlvbiA+PSBkcG9zaXRpb25zW3BvcysrXSkgewogICAgICAgICAgICB9CiAgICAgICAgICAgIHBvcy0tOwogICAgICAgICAgfQogICAgICAgICAgY29uc3QgeyBzdGFydENvb3JkaW5hdGUsIG92ZXJsYXBzIH0gPSB0aGlzLmNoZWNrTGluZShtZXRhZGF0YSwgcmVmTmFtZSwgc3RhcnQsIGVuZCwgbGluZSk7CiAgICAgICAgICBpZiAocHJldmlvdXNTdGFydENvb3JkaW5hdGUgIT09IHZvaWQgMCAmJiBzdGFydENvb3JkaW5hdGUgIT09IHZvaWQgMCAmJiBwcmV2aW91c1N0YXJ0Q29vcmRpbmF0ZSA+IHN0YXJ0Q29vcmRpbmF0ZSkgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoYExpbmVzIG5vdCBzb3J0ZWQgYnkgc3RhcnQgY29vcmRpbmF0ZSAoJHtwcmV2aW91c1N0YXJ0Q29vcmRpbmF0ZX0gPiAke3N0YXJ0Q29vcmRpbmF0ZX0pLCB0aGlzIGZpbGUgaXMgbm90IHVzYWJsZSB3aXRoIFRhYml4LmApOwogICAgICAgICAgfQogICAgICAgICAgcHJldmlvdXNTdGFydENvb3JkaW5hdGUgPSBzdGFydENvb3JkaW5hdGU7CiAgICAgICAgICBpZiAob3ZlcmxhcH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3JkaW5hdGUgPSAtSW5maW5pdHk7CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGluZS5sZW5ndGggKyAxOyBpICs9IDEpIHsKICAgICAgICBpZiAobGluZVtpXSA9PT0gIgkiIHx8IGkgPT09IGxpbmUubGVuZ3RoKSB7CiAgICAgICAgICBpZiAoY3VycmVudENvbHVtbk51bWJlciA9PT0gcmVmKSB7CiAgICAgICAgICAgIGlmICh0aGlzLnJlbmFtZVJlZlNlcShsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSkpICE9PSByZWdpb25SZWZOYW1lKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHsgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoY3VycmVudENvbHVtbk51bWJlciA9PT0gc3RhcnQpIHsKICAgICAgICAgICAgc3RhcnRDb29yZGluYXRlID0gcGFyc2VJbnQobGluZS5zbGljZShjdXJyZW50Q29sdW1uU3RhcnQsIGkpLCAxMCk7CiAgICAgICAgICAgIGlmIChjb29yZGluYXRlVHlwZSA9PT0gIjEtYmFzZWQtY2xvc2VkIikgewogICAgICAgICAgICAgIHN0YXJ0Q29vcmRpbmF0ZSAtPSAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzdGFydENvb3JkaW5hdGUgPj0gcmVnaW9uRW5kKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHsgc3RhcnRDb29yZGluYXRlLCBvdmVybGFwczogZmFsc2UgfTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoZW5kID09PSAwIHx8IGVuZCA9PT0gc3RhcnQpIHsKICAgICAgICAgICAgICBpZiAoc3RhcnRDb29yZGluYXRlICsgMSA8PSByZWdpb25TdGFydCkgewogICAgICAgICAgICAgICAgcmV0dXJuIHsgc3RhcnRDb29yZGluYXRlLCBvdmVybGFwczogZmFsc2UgfTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoZm9ybWF0ID09PSAiVkNGIiAmJiBjdXJyZW50Q29sdW1uTnVtYmVyID09PSA0KSB7CiAgICAgICAgICAgIHJlZlNlcSA9IGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKTsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VycmVudENvbHVtbk51bWJlciA9PT0gZW5kKSB7CiAgICAgICAgICAgIGxldCBlbmRDb29yZGluYXRlOwogICAgICAgICAgICBpZiAoZm9ybWF0ID09PSAiVkNGIikgewogICAgICAgICAgICAgIGVuZENvb3JkaW5hdGUgPSB0aGlzLl9nZXRWY2ZFbmQoc3RhcnRDb29yZGluYXRlLCByZWZTZXEsIGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKSk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgZW5kQ29vcmRpbmF0ZSA9IHBhcnNlSW50KGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKSwgMTApOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChlbmRDb29yZGluYXRlIDw9IHJlZ2lvblN0YXJ0KSB7CiAgICAgICAgICAgICAgcmV0dXJuIHsgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGN1cnJlbnRDb2x1bW5TdGFydCA9IGkgKyAxOwogICAgICAgICAgY3VycmVudENvbHVtbk51bWJlciArPSAxOwogICAgICAgICAgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPiBtYXhDb2x1bW4pIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIHJldHVybiB7IHN0YXJ0Q29vcmRpbmF0ZSwgb3ZlcmxhcHM6IHRydWUgfTsKICAgIH0KICAgIF9nZXRWY2ZFbmQoc3RhcnRDb29yZGluYXRlLCByZWZTZXEsIGluZm8pIHsKICAgICAgbGV0IGVuZENvb3JkaW5hdGUgPSBzdGFydENvb3JkaW5hdGUgKyByZWZTZXEubGVuZ3RoOwogICAgICBjb25zdCBpc1RSQSA9IGluZm8uaW5kZXhPZigiU1ZUWVBFPVRSQSIpICE9PSAtMTsKICAgICAgaWYgKGluZm9bMF0gIT09ICIuIiAmJiAhaXNUUkEpIHsKICAgICAgICBsZXQgcHJldkNoYXIgPSAiOyI7CiAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCBpbmZvLmxlbmd0aDsgaiArPSAxKSB7CiAgICAgICAgICBpZiAocHJldkNoYXIgPT09ICI7IiAmJiBpbmZvLnNsaWNlKGosIGogKyA0KSA9PT0gIkVORD0iKSB7CiAgICAgICAgICAgIGxldCB2YWx1ZUVuZCA9IGluZm8uaW5kZXhPZigiOyIsIGopOwogICAgICAgICAgICBpZiAodmFsdWVFbmQgPT09IC0xKSB7CiAgICAgICAgICAgICAgdmFsdWVFbmQgPSBpbmZvLmxlbmd0aDsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbmRDb29yZGluYXRlID0gcGFyc2VJbnQoaW5mby5zbGljZShqICsgNCwgdmFsdWVFbmQpLCAxMCk7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgcHJldkNoYXIgPSBpbmZvW2pdOwogICAgICAgIH0KICAgICAgfSBlbHNlIGlmIChpc1RSQSkgewogICAgICAgIHJldHVybiBzdGFydENvb3JkaW5hdGUgKyAxOwogICAgICB9CiAgICAgIHJldHVybiBlbmRDb29yZGluYXRlOwogICAgfQogICAgYXN5bmMgbGluZUNvdW50KHJlZk5hbWUsIG9wdHMgPSB7fSkgewogICAgICByZXR1cm4gdGhpcy5pbmRleC5saW5lQ291bnQocmVmTmFtZSwgb3B0cyk7CiAgICB9CiAgICBhc3luYyBfcmVhZFJlZ2lvbihwb3MsIHNpemUsIG9wdHMgPSB7fSkgewogICAgICBjb25zdCBiID0gaW1wb3J0X2J1Z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ArIGhpID4+PiAxOwogICAgICAgIGlmIChjb21wYXJlKGFbbWlkXSwgeCkgPCAwKQogICAgICAgICAgbG8gPSBtaWQgKyAxOwogICAgICAgIGVsc2UKICAgICAgICAgIGhpID0gbWlkOwogICAgICB9CiAgICAgIHJldHVybiBsbzsKICAgIH0KICAgIGZ1bmN0aW9uIHJpZ2h0KGEsIHgsIGxvLCBoaSkgewogICAgICBpZiAobG8gPT0gbnVsbCkKICAgICAgICBsbyA9IDA7CiAgICAgIGlmIChoaSA9PSBudWxsKQogICAgICAgIGhpID0gYS5sZW5ndGg7CiAgICAgIHdoaWxlIChsbyA8IGhpKSB7CiAgICAgICAgY29uc3QgbWlkID0gbG8gKyBoaSA+Pj4gMTsKICAgICAgICBpZiAoY29tcGFyZShhW21pZF0sIHgpID4gMCkKICAgICAgICAgIGhpID0gbWlkOwogICAgICAgIGVsc2UKICAgICAgICAgIGxvID0gbWlkICsgMTsKICAgICAgfQogICAgICByZXR1cm4gbG87CiAgICB9CiAgICBmdW5jdGlvbiBjZW50ZXIoYSwgeCwgbG8sIGhpKSB7CiAgICAgIGlmIChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgY29uc3QgaSA9IGxlZnQoYSwgeCwgbG8sIGhpIC0gMSk7CiAgICAgIHJldHVybiBpID4gbG8gJiYgZGVsdGEoYVtpIC0gMV0sIHgpID4gLWRlbHRhKGFbaV0sIHgpID8gaSAtIDEgOiBpOwogICAgfQogICAgcmV0dXJuIHsgbGVmdCwgY2VudGVyLCByaWdodCB9OwogIH0KICBmdW5jdGlvbiBhc2NlbmRpbmdDb21wYXJhdG9yKGYpIHsKICAgIHJldHVybiAoZCwgeCkgPT4gYXNjZW5kaW5nX2RlZmF1bHQoZihkKSwgeCk7CiAgfQoKICAvLyBzcmMvZGF0YS1mZXRjaGVycy91dGlscy50cwogIHZhciBEYXRhU291cmNlID0gY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AgICAgICAgIGNvbnN0IGF1dG9GaWVsZCA9IGF1dG9TcWwuZmllbGRzW2ldOwogICAgICAgICAgbGV0IGNvbHVtblZhbCA9IGZpZWxkc1tpXTsKICAgICAgICAgIGNvbnN0IHsgaXNOdW1lcmljLCBpc0FycmF5OiBpc0FycmF5MiwgYXJyYXlJc051bWVyaWMsIG5hbWUgfSA9IGF1dG9GaWVsZDsKICAgICAgICAgIGlmIChjb2x1bW5WYWwgPT09IG51bGwgfHwgY29sdW1uVmFsID09PSB2b2lkIDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoY29sdW1uVmFsICE9PSAiLiIpIHsKICAgICAgICAgICAgaWYgKGlzTnVtZXJpYykgewogICAgICAgICAgICAgIGNvbnN0IG51bSA9IE51bWJlcihjb2x1bW5WYWwpOwogICAgICAgICAgICAgIGNvbHVtblZhbCA9IE51bWJlci5pc05hTihudW0pID8gY29sdW1uVmFsIDogbnVtOwogICAgICAgICAgICB9IGVsc2UgaWYgKGlzQXJyYXkyKSB7CiAgICAgICAgICAgICAgY29sdW1uVmFsID0gY29sdW1uVmFsLnNwbGl0KCIsIik7CiAgICAgICAgICAgICAgaWYgKGNvbHVtblZhbFtjb2x1bW5WYWwubGVuZ3RoIC0gMV0gPT09ICIiKSB7CiAgICAgICAgICAgICAgICBjb2x1bW5WYWwucG9wKCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChhcnJheUlzTnVtZXJpYykgewogICAgICAgICAgICAgICAgY29sdW1uVmFsID0gY29sdW1uVmFsLm1hcCgoc3RyKSA9PiBOdW1iZXIoc3RyKSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGZlYXR1cmVbbmFtZV0gPSBjb2x1bW5WYWw7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9IGVsc2UgewogICAgICAgIGNvbnN0IGZpZWxkTmFtZXMgPSBbImNocm9tIiwgImNocm9tU3R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Bhc3luYyAjY2FsY05Db2x1bW5zKCkgewogICAgICBjb25zdCBzb3VyY2UgPSBkYXRhU291cmNlcy5nZXQodGhpcy4jdWlkKTsKICAgICAgY29uc3QgeyBjaHJvbUxlbmd0aHMsIGN1bVBvc2l0aW9ucyB9ID0gc291cmNlLmNocm9tSW5mbzsKICAgICAgbGV0IG5fY29scyA9IDA7CiAgICAgIGZvciAoY29uc3QgY3VtUG9zIG9mIGN1bVBvc2l0aW9ucykgewogICAgICAgIGNvbnN0IGNocm9tTmFtZSA9IGN1bVBvcy5jaHI7CiAgICAgICAgY29uc3QgY2hyb21TdGFydCA9IGN1bVBvcy5wb3M7CiAgICAgICAgY29uc3QgY2hyb21FbmQgPSBjdW1Qb3MucG9zICsgY2hyb21MZW5ndGhzW2Nocm9tTmFtZV07CiAgICAgICAgbl9jb2xzID0gYXdhaXQgbmV3IFByb21pc2UoKHJlc29sdmUpID0+IHsKICAgICAgICAgIHNvdXJjZS5maWxlLnRiaS5nZXRMaW5lcyhjaHJvbU5hbWUsIGNocm9tU3RhcnQsIGNocm9tRW5kLCAobGluZSkgPT4gewogICAgICAgICAgICByZXNvbHZlKGxpbmUuc3BsaXQoIgkiKS5sZW5ndGgpOwogICAgICAgICAgfSk7CiAgICAgICAgfSk7CiAgICAgICAgaWYgKG5fY29scyA+IDApCiAgICAgICAgICBicmVhazsKICAgICAgfQogICAgICByZXR1cm4gbl9jb2xzOwogICAgfQogICAgYXN5bmMgZ2V0VGlsZURhdGEobWluWCwgbWF4WCkgewogICAgICBjb25zdCBzb3VyY2UgPSBkYXRhU291cmNlcy5nZXQodGhpcy4jdWlkKTsKICAgICAgY29uc3QgcGFyc2VyMiA9IGF3YWl0IHRoaXMuZ2V0UGFyc2VyKCk7CiAgICAgIGxldCBjdXJNaW5YID0gbWluWDsKICAgICAgY29uc3QgeyBjaHJvbUxlbmd0aHMsIGN1bVBvc2l0aW9ucyB9ID0gc291cmNlLmNocm9tSW5mbzsKICAgICAgY29uc3QgYWxsVGlsZXMgPSBbXTsKICAgICAgZm9yIChjb25zdCBjdW1Qb3Mgb2YgY3VtUG9zaXRpb25zKSB7CiAgICAgICAgY29uc3QgY2hyb21OYW1lID0gY3VtUG9zLmNocjsKICAgICAgICBjb25zdCBjaHJvbVN0YXJ0ID0gY3VtUG9zLnBvczsKICAgICAgICBjb25zdCBjaHJvbUVuZCA9IGN1bVBvcy5wb3MgKyBjaHJvbUxlbmd0aHNbY2hyb21OYW1lXTsKICAgICAgICBsZXQgc3RhcnRQb3MsIGVuZFBvczsKICAgICAgICBpZiAoY2hyb21TdGFydCA+IGN1ck1pblggfHwgY3VyTWluWCA+PSBjaHJvbUVuZCkgewogICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIGNvbnN0IHRpbGVzUHJvbWlzZSA9IG5ldyBQcm9taXNlKChyZXNvbHZlKSA9PiB7CiAgICAgICAgICBjb25zdCB0aWxlcyA9IFtdOwogICAgICAgICAgY29uc3QgbGluZUNhbGxiYWNrID0gKGxpbmUpID0+IHsKICAgICAgICAgICAgY29uc3QgYmVkVGlsZSA9IHBhcnNlcjIucGFyc2VMaW5lKGxpbmUsIGNocm9tU3RhcnQpOwogICAgICAgICAgICB0aWxlcy5wdXNoKGJlZFRpbGUpOwogICAgICAgICAgfTsKICAgICAgICAgIGlmIChtYXhYID4gY2hyb21FbmQpIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBjdXJNaW5YIC0gY2hyb21TdGFydDsKICAgICAgICAgICAgZW5kUG9zID0gY2hyb21FbmQgLSBjaHJvbVN0YXJ0OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBNYXRoLmZsb29yKGN1ck1pblggLSBjaHJvbVN0YXJ0KTsKICAgICAgICAgICAgZW5kUG9zID0gTWF0aC5jZWlsKG1heFggLSBjaHJvbVN0YXJ0KTsKICAgICAgICAgIH0KICAgICAgICAgIHNvdXJjZS5maWxlLnRiaS5nZXRMaW5lcyhjaHJvbU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FydHNbMF0sIDEwKTsKICAgICAgY29uc3QgeCA9IHBhcnNlSW50KHBhcnRzWzFdLCAxMCk7CiAgICAgIGlmIChOdW1iZXIuaXNOYU4oeCkgfHwgTnVtYmVyLmlzTmFOKHopKSB7CiAgICAgICAgY29uc29sZS53YXJuKCJJbnZhbGlkIHRpbGUgem9vbSBvciBwb3NpdGlvbjoiLCB6LCB4KTsKICAgICAgICBjb250aW51ZTsKICAgICAgfQogICAgICB2YWxpZFRpbGVJZHMucHVzaCh0aWxlSWQpOwogICAgICB0aWxlUHJvbWlzZXMucHVzaCh0aWxlKHVpZCwgeiwgeCkpOwogICAgfQogICAgcmV0dXJuIFByb21pc2UuYWxsKHRpbGVQcm9taXNlcykudGhlbigodmFsdWVzMikgPT4gewogICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHZhbHVlczIubGVuZ3RoOyBpKyspIHsKICAgICAgICBjb25zdCB2YWxpZFRpbGVJZCA9IHZhbGlkVGlsZUlkc1tpXTsKICAgICAgICB0aWxlc1t2YWxpZFRpbGVJZF0gPSB7IHRpbGVQb3NpdGlvbklkOiB2YWxpZFRpbGVJZCB9OwogICAgICB9CiAgICAgIHJldHVybiB0aWxlczsKICAgIH0pOwogIH07CiAgdmFyIGdldFRhYnVsYXJEYXRhID0gKHVpZCwgdGlsZUlkcykgPT4gewogICAgY29uc3QgZGF0YSA9IFtdOwogICAgdGlsZUlkcy5mb3JFYWNoKCh0aWxlSWQpID0+IHsKICAgICAgY29uc3QgcGFydHMgPSB0aWxlSWQuc3BsaXQoIi4iKTsKICAgICAgY29uc3QgeiA9IHBhcnNlSW50KHBhcnRzWzBdLCAxMCk7CiAgICAgIGNvbnN0IHggPSBwYXJzZUludChwYXJ0c1sxXSwgMTApOwogICAgICBjb25zdCB0aWxlVmFsdWUgPSB0aWxlVmFsdWVzW2Ake3VpZH0uJHt6fS4ke3h9YF07CiAgICAgIGlmICghdGlsZVZhbHVlKSB7CiAgICAgICAgY29uc29sZS53YXJuKGBObyB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FzaCAoQ3VzdG9tIEJ1aWxkKSA8aHR0cHM6Ly9sb2Rhc2guY29tLz4KICogQnVpbGQ6IGBsb2Rhc2ggbW9kdWxhcml6ZSBleHBvcnRzPSJlcyIgLW8gLi9gCiAqIENvcHlyaWdodCBPcGVuSlMgRm91bmRhdGlvbiBhbmQgb3RoZXIgY29udHJpYnV0b3JzIDxodHRwczovL29wZW5qc2Yub3JnLz4KICogUmVsZWFzZWQgdW5kZXIgTUlUIGxpY2Vuc2UgPGh0dHBzOi8vbG9kYXNoLmNvbS9saWNlbnNlPgogKiBCYXNlZCBvbiBVbmRlcnNjb3JlLmpzIDEuOC4zIDxodHRwOi8vdW5kZXJzY29yZWpzLm9yZy9MSUNFTlNFPgogKiBDb3B5cmlnaHQgSmVyZW15IEFzaGtlbmFzLCBEb2N1bWVudENsb3VkIGFuZCBJbnZlc3RpZ2F0aXZlIFJlcG9ydGVycyAmIEVkaXRvcnMKICovCg==",qle=typeof window<"u"&&window.Blob&&new Blob([atob(z2e)],{type:"text/javascript;charset=utf-8"});function eng(){const e=qle&&(window.URL||window.webkitURL).createObjectURL(qle);try{return e?new Worker(e):new Worker("data:application/javascript;base64,"+z2e,{type:"module"})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const tng=200;class P2e{constructor(g,I){rt(this,"dataConfig",{}),rt(this,"uid"),rt(this,"prevRequestTime"),rt(this,"track"),rt(this,"toFetch"),rt(this,"fetchTimeout"),rt(this,"worker"),this.uid=g.libraries.slugid.nice(),this.prevRequestTime=0,this.toFetch=new Set;const{url:i,indexUrl:n,assembly:C,...r}=I;this.worker=JT(new eng).then(async o=>{const a=Object.entries(bI(C).size);return await o.init(this.uid,{url:i,indexUrl:n},a,r),o})}async tilesetInfo(g){(await this.worker).tilesetInfo(this.uid).then(g)}fetchTilesDebounced(g,I){this.track.drawLoadingCue(),I.forEach(i=>this.toFetch.add(i)),this.fetchTimeout&&clearTimeout(this.fetchTimeout),this.fetchTimeout=setTimeout(()=>{this.sendFetch(g,[...this.toFetch]),this.toFetch.clear()},tng)}async sendFetch(g,I){(await this.worker).fetchTilesDebounced(this.uid,I).then(g)}async getTabularData(g){const I=await(await this.worker).getTabularData(this.uid,g);return JSON.parse(new TextDecoder().decode(I))}}rt(P2e,"config",{type:"bed"});const gng=Object.freeze(Object.defineProperty({__proto__:null,BamDataFetcher:BH,BedDataFetcher:P2e,BigWigDataFetcher:K2e,CsvDataFetcher:D2e,GffDataFetcher:M2e,JsonDataFetcher:F2e,VcfDataFetcher:s2e},Symbol.toStringTag,{value:"Module"})),Ing="gosling-data-row-uid";function ing(e,g){var I,i,n,C,r,o,a,s,A,l,c,u,d,h,m,f;const b=[];if(!i7(e.data)){console.warn("No data is specified");return}if(e.data.type==="vector"||e.data.type==="bigwig"){if(!("dense"in g))return;const p=(I=e.data.binSize)!=null?I:1,y=g.dense,Z=g.tileSize,B=g.tileWidth/g.tileSize,G=(i=e.data.value)!=null?i:"value",v=(n=e.data.column)!=null?n:"position",w=(C=e.data.start)!=null?C:"start",V=(r=e.data.end)!=null?r:"end",S=`${G}_min`,X=`${G}_max`,W=(o=e.data.aggregation)!=null?o:"mean";let R=0,H=Number.MAX_SAFE_INTEGER,Y=Number.MIN_SAFE_INTEGER,K=Number.MIN_SAFE_INTEGER,F=Number.MAX_SAFE_INTEGER;Array.from(Array(Z).keys()).forEach((J,P)=>{if(p===1){const ge=y[P]/(W==="mean"?B:1);b.push({[G]:ge,[v]:g.tileX+(P+.5)*B,[w]:g.tileX+P*B,[V]:g.tileX+(P+1)*B,[S]:ge,[X]:ge})}else if(P%p===0)R=H=Y=y[P],K=P,F=P+p;else if(P%p===p-1)b.push({[G]:R/p/(W==="mean"?B:1),[v]:g.tileX+(K+p/2)*B,[w]:g.tileX+K*B,[V]:g.tileX+F*B,[S]:H,[X]:Y});else if(P===Z-1){const ge=Z%p,q=K+ge;b.push({[G]:R/ge/(W==="mean"?B:1),[v]:g.tileX+(K+ge/2)*B,[w]:g.tileX+K*B,[V]:g.tileX+q*B,[S]:H,[X]:Y})}else R+=y[P],H>y[P]&&(H=y[P]),Y{let J=0,P=Number.MIN_SAFE_INTEGER,ge=Number.MAX_SAFE_INTEGER,q=Number.MAX_SAFE_INTEGER,$=Number.MIN_SAFE_INTEGER;Array.from(Array(G).keys()).forEach((j,te)=>{if(p===1){const Q=B[G*F+te]/(Y==="mean"?v:1);b.push({[w]:K,[V]:Q,[S]:g.tileX+(te+.5)*v,[X]:g.tileX+te*v,[W]:g.tileX+(te+1)*v,[R]:Q,[H]:Q})}else if(te%p===0)J=q=$=B[G*F+te],P=te,ge=te+p;else if(te%p===p-1)b.push({[w]:K,[V]:Y==="mean"?J/p/v:J,[S]:g.tileX+(P+p/2)*v,[X]:g.tileX+P*v,[W]:g.tileX+ge*v,[R]:q,[H]:$});else if(te===G-1){const Q=G%p,ie=P+Q;b.push({[w]:K,[V]:Y==="mean"?J/Q/v:J,[S]:g.tileX+(P+Q/2)*v,[X]:g.tileX+P*v,[W]:g.tileX+ie*v,[R]:q,[H]:$})}else{const Q=B[G*F+te];J+=Q,q>Q&&(q=Q),$"u"||typeof g.tileHeight>"u")return;const p=Math.sqrt(g.dense.length),{tileX:y,tileY:Z,tileWidth:B,tileHeight:G}=g,v=g.dense,w=B/p,V=G/p,S=(m=e.data.column)!=null?m:"x",X=(f=e.data.row)!=null?f:"y",W=16;for(let R=0;R{const{chrOffset:v,fields:w}=B,V={};if(V[Ing]=`${G}`,p.forEach(S=>{V[S.name]=+w[S.index]+v}),Z==null||Z.forEach(S=>{V[S.name]=S.type==="quantitative"?+w[S.index]:w[S.index]}),b.push({...V,type:"gene"}),y){const[S,X]=y,W=w[S.index].split(","),R=w[X.index].split(",");W.forEach((H,Y)=>{const K=R[Y];if(b.push({...V,[S.name]:+H+v,[X.name]:+K+v,type:"exon"}),Y+1n===e.chromosome))){if(m4e(e))return[I[e.chromosome][0]+1,I[e.chromosome][1]];if(f4e(e))return e.interval;if(p4e(e)){const i=I[e.chromosome][0],[n,C]=e.interval;return[i+n,i+C]}}}function ang(e,g){const I={},i=Hd;e.forEach(n=>{i.forEach(C=>{const r=n.spec()[C];if(!ut(r)||r.domain===void 0)return;const{domain:o,type:a}=r;if(a==="quantitative"){const s=Array.from(o);if(!I[C])I[C]=s;else{const A=I[C];A[0]>s[0]&&(A[0]=s[0]),A[1]{i.forEach(C=>{const r=n.spec()[C];ut(r)&&r.type==="genomic"||(n.setChannelDomain(C,I[C],g),n.generateScales())}),n.updateChannelValue()})}const Ang={compactLayout:!1,trackSourceServers:["https://server.gosling-lang.org/api/v1/"],views:[{genomePositionSearchBoxVisible:!1,genomePositionSearchBox:{autocompleteServer:"https://higlass.io/api/v1",autocompleteId:"P0PLbQMwTYGy-5uPIQid7A",chromInfoServer:"https://higlass.io/api/v1",chromInfoId:"hg38"},layout:{x:0,y:0,w:6.4,h:600},tracks:{top:[],left:[{type:"combined",width:130,height:600,contents:[{type:"gosling-track",server:"https://server.gosling-lang.org/api/v1/",tilesetUid:"cistrome-multivec",width:130,height:600,options:{showMousePosition:!0,mousePositionColor:"#000000",fontSize:24,labelPosition:"none",labelShowResolution:!1,labelColor:"black",labelBackgroundColor:"white",labelTextOpacity:1,labelLeftMargin:1,labelTopMargin:1,labelRightMargin:0,labelBottomMargin:0,backgroundColor:"transparent",spec:{spacing:10,orientation:"vertical",assembly:"hg38",layout:"linear",static:!1,xDomain:{interval:[0,1e9]},centerRadius:.3,xOffset:0,yOffset:0,style:{outlineWidth:.5},data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"],binSize:4},mark:"rect",x:{field:"start",type:"genomic",axis:"left",domain:{interval:[0,1e9]},linkingId:"7f94b74e-25ec-4e67-8c75-3dc0f1b0d6bd"},xe:{field:"end",type:"genomic"},row:{field:"sample",type:"nominal",legend:!0},color:{field:"peak",type:"quantitative",legend:!0},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:160,height:600,overlayOnPreviousTrack:!1},theme:{base:"light",root:{background:"white",titleColor:"black",titleBackgroundColor:"transparent",titleFontSize:18,titleFontFamily:"Arial",titleAlign:"left",titleFontWeight:"bold",subtitleColor:"gray",subtitleBackgroundColor:"transparent",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleFontWeight:"normal",subtitleAlign:"left",mousePositionColor:"#000000"},track:{background:"transparent",alternatingBackground:"transparent",titleColor:"black",titleBackground:"white",titleFontSize:24,titleAlign:"left",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"#DBDBDB",tickColor:"black"},axis:{tickColor:"black",labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",baselineColor:"black",gridColor:"#E3E3E3",gridStrokeWidth:1,gridStrokeType:"solid",gridStrokeDash:[4,4]},markCommon:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},point:{color:"#E79F00",size:3,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rect:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},triangle:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},area:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},line:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},bar:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rule:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},link:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},text:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6],textAnchor:"middle",textFontWeight:"normal"},brush:{color:"gray",size:1,stroke:"black",strokeWidth:1,opacity:.3,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]}}}}]},{uid:"15483511-f6fb-11eb-914b-976b6ecda162",type:"axis-track",chromInfoPath:"https://s3.amazonaws.com/gosling-lang.org/data/hg38.chrom.sizes",options:{layout:"linear",outerRadius:null,width:160,height:600,theme:{base:"light",root:{background:"white",titleColor:"black",titleBackgroundColor:"transparent",titleFontSize:18,titleFontFamily:"Arial",titleAlign:"left",titleFontWeight:"bold",subtitleColor:"gray",subtitleBackgroundColor:"transparent",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleFontWeight:"normal",subtitleAlign:"left",mousePositionColor:"#000000"},track:{background:"transparent",alternatingBackground:"transparent",titleColor:"black",titleBackground:"white",titleFontSize:24,titleAlign:"left",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"#DBDBDB",tickColor:"black"},axis:{tickColor:"black",labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",baselineColor:"black",gridColor:"#E3E3E3",gridStrokeWidth:1,gridStrokeType:"solid",gridStrokeDash:[4,4]},markCommon:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},point:{color:"#E79F00",size:3,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rect:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},triangle:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},area:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},line:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},bar:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rule:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},link:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},text:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6],textAnchor:"middle",textFontWeight:"normal"},brush:{color:"gray",size:1,stroke:"black",strokeWidth:1,opacity:.3,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]}},assembly:"hg38",stroke:"transparent",color:"black",fontSize:12,fontFamily:"Arial",fontWeight:"normal",tickColor:"black",tickFormat:"plain",tickPositions:"even",reverseOrientation:!1},width:30}],center:[],right:[],bottom:[],gallery:[],whole:[]},initialXDomain:[0,1e9],initialYDomain:[0,1e9],zoomFixed:!1,zoomLimits:[1,null],uid:"15483510-f6fb-11eb-914b-976b6ecda162",chromInfoPath:"https://s3.amazonaws.com/gosling-lang.org/data/hg38.chrom.sizes"},{genomePositionSearchBoxVisible:!1,genomePositionSearchBox:{autocompleteServer:"https://higlass.io/api/v1",autocompleteId:"P0PLbQMwTYGy-5uPIQid7A",chromInfoServer:"https://higlass.io/api/v1",chromInfoId:"hg38"},layout:{x:6.8,y:0,w:5.2,h:600},tracks:{top:[],left:[{type:"combined",width:130,height:600,contents:[{type:"gosling-track",server:"https://server.gosling-lang.org/api/v1/",tilesetUid:"cistrome-multivec",width:130,height:600,options:{showMousePosition:!0,mousePositionColor:"#000000",fontSize:24,labelPosition:"none",labelShowResolution:!1,labelColor:"black",labelBackgroundColor:"white",labelTextOpacity:1,labelLeftMargin:1,labelTopMargin:1,labelRightMargin:0,labelBottomMargin:0,backgroundColor:"transparent",spec:{spacing:10,orientation:"vertical",assembly:"hg38",layout:"linear",static:!1,xDomain:{interval:[0,1e9]},centerRadius:.3,xOffset:0,yOffset:0,style:{outlineWidth:.5},data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"],binSize:4},mark:"rect",x:{field:"start",type:"genomic",domain:{interval:[0,1e9]},linkingId:"7f94b74e-25ec-4e67-8c75-3dc0f1b0d6bd"},xe:{field:"end",type:"genomic"},row:{field:"sample",type:"nominal",legend:!0},color:{field:"peak",type:"quantitative",legend:!0},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:130,height:600},theme:{base:"light",root:{background:"white",titleColor:"black",titleBackgroundColor:"transparent",titleFontSize:18,titleFontFamily:"Arial",titleAlign:"left",titleFontWeight:"bold",subtitleColor:"gray",subtitleBackgroundColor:"transparent",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleFontWeight:"normal",subtitleAlign:"left",mousePositionColor:"#000000"},track:{background:"transparent",alternatingBackground:"transparent",titleColor:"black",titleBackground:"white",titleFontSize:24,titleAlign:"left",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"#DBDBDB",tickColor:"black"},axis:{tickColor:"black",labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",baselineColor:"black",gridColor:"#E3E3E3",gridStrokeWidth:1,gridStrokeType:"solid",gridStrokeDash:[4,4]},markCommon:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},point:{color:"#E79F00",size:3,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rect:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},triangle:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},area:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},line:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},bar:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rule:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},link:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},text:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6],textAnchor:"middle",textFontWeight:"normal"},brush:{color:"gray",size:1,stroke:"black",strokeWidth:1,opacity:.3,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]}}}}]}],center:[],right:[],bottom:[],gallery:[],whole:[]},initialXDomain:[0,1e9],initialYDomain:[0,1e9],zoomFixed:!1,zoomLimits:[1,null],uid:"154b1b40-f6fb-11eb-914b-976b6ecda162"}],zoomLocks:{locksByViewUid:{},locksDict:{}},locationLocks:{locksByViewUid:{},locksDict:{}},editable:!1,chromInfoPath:"https://s3.amazonaws.com/gosling-lang.org/data/hg38.chrom.sizes"},Qr=30,sng=e=>({genomePositionSearchBoxVisible:!1,genomePositionSearchBox:{autocompleteServer:"https://higlass.io/api/v1",autocompleteId:C6e(e),chromInfoServer:"https://higlass.io/api/v1",chromInfoId:e??"hg38"},layout:{w:12,h:12,x:0,y:0},tracks:{top:[],left:[],center:[],right:[],bottom:[],gallery:[],whole:[]},initialXDomain:[0,bI(e).total],initialYDomain:[0,bI(e).total],zoomFixed:!1});class lng{constructor(){rt(this,"assembly"),rt(this,"orientation"),rt(this,"hg"),this.assembly="hg38",this.hg={compactLayout:!1,trackSourceServers:[],views:[],zoomLocks:{locksByViewUid:{},locksDict:{}},locationLocks:{locksByViewUid:{},locksDict:{}}},this.setEditable(!1)}spec(){return this.hg}setViewOrientation(g){return this.orientation=g,this}addDefaultView(g,I){return this.hg.views.push(JSON.parse(JSON.stringify({...sng(I),uid:g}))),this}setAssembly(g){return this.assembly=g,this.setChromInfoPath(bI(this.assembly).path),this}getAssembly(){return this.assembly}setTextTrack(g,I,i,n="black",C=14,r="normal",o="left",a="transparent",s="Arial"){var A;return this.getLastView()&&((A=this.getLastView().tracks.top)==null||A.push({type:"text",width:g,height:I,options:{backgroundColor:a,textColor:n,fontSize:C,fontWeight:r,fontFamily:s,offsetY:0,align:o,text:i}})),this}setDummyTrack(g){var I;return this.getLastView()&&((I=this.getLastView().tracks.top)==null||I.push({type:"dummy-track",width:g.width,height:g.height,options:{width:g.width,height:g.height,title:g.title,...g.style}})),this}addBrush(g,I,i,n,C){var r,o,a,s,A,l;if(n)return(l=this.getView(I))==null||l.tracks.whole.push({type:g==="circular"?"brush-track":"viewport-projection-horizontal",uid:ln(),fromViewUid:n,options:{projectionFillColor:(r=C==null?void 0:C.color)!=null?r:i.brush.color,projectionStrokeColor:(o=C==null?void 0:C.stroke)!=null?o:i.brush.stroke,projectionFillOpacity:(a=C==null?void 0:C.opacity)!=null?a:i.brush.opacity,projectionStrokeOpacity:(s=C==null?void 0:C.opacity)!=null?s:i.brush.opacity,strokeWidth:(A=C==null?void 0:C.strokeWidth)!=null?A:i.brush.strokeWidth,startAngle:C==null?void 0:C.startAngle,endAngle:C==null?void 0:C.endAngle,innerRadius:C==null?void 0:C.innerRadius,outerRadius:C==null?void 0:C.outerRadius}}),this}getLastView(){return this.hg.views[this.hg.views.length-1]}getMainTrackPosition(){return this.orientation==="vertical"?"left":"center"}getLastVisView(){const g=this.hg.views.filter(I=>{var i,n;return((n=(i=I.tracks[this.getMainTrackPosition()])==null?void 0:i[0])==null?void 0:n.type)==="combined"});return g[g.length-1]}getView(g){return this.hg.views.find(I=>I.uid===g)}validateSpec(g=!1){return n2e(ong,this.spec(),g).state==="success"}setDomain(g,I){return g&&(this.getLastView().initialXDomain=a_(g,this.getAssembly())),I&&(this.getLastView().initialYDomain=a_(I,this.getAssembly())),this}adjustDomain(g="horizontal",I,i){if(g!=="vertical")return this;const n=this.getLastView().initialXDomain;if(!n)return this;const[C,r]=n,o=r-C,a=(C+r)/2;return this.getLastView().initialXDomain=[a-o/I/2/i*I,a+o/I/2/i*I],this}setZoomFixed(g){return this.getLastView().zoomFixed=g,this}setZoomLimits(g){return this.getLastView().zoomLimits=g,this}setLayout(g){return this.getLastView().layout=g,this}setEditable(g){return this.hg.editable=g,this}setChromInfoPath(g){return this.getLastView()&&(this.getLastView().chromInfoPath=g),this.hg.chromInfoPath=g,this}addTrackSourceServers(g){var I,i;return g&&((I=this.hg.trackSourceServers)==null?void 0:I.indexOf(g))===-1&&((i=this.hg.trackSourceServers)==null||i.push(g)),this}setMainTrack(g){var I;return this.getLastView()?(this.getLastView().tracks[this.getMainTrackPosition()]=[{type:"combined",uid:`${(I=g.uid)!=null?I:ln()}-${this.getMainTrackPosition()}-combined`,width:g.width-1,height:g.height,contents:[g]}],this):this}addTrackToCombined(g){var I;return this.getLastVisView()?((I=this.getLastVisView().tracks[this.getMainTrackPosition()][0])==null||I.contents.push(g),this):this}setAxisTrack(g,I="regular",i){if(!this.hg.views)return this;const n=g==="left"||g==="right"?"width":"height",C={type:"axis-track",chromInfoPath:this.hg.chromInfoPath,options:{...i,assembly:this.getAssembly(),stroke:"transparent",color:i.theme.axis.labelColor,labelMargin:i.theme.axis.labelMargin,excludeChrPrefix:i.theme.axis.labelExcludeChrPrefix,fontSize:i.theme.axis.labelFontSize,fontFamily:i.theme.axis.labelFontFamily,fontWeight:i.theme.axis.labelFontWeight,tickColor:i.theme.axis.tickColor,tickFormat:I==="narrower"?"si":"plain",tickPositions:I==="regular"?"even":"ends",reverseOrientation:g==="bottom"||g==="right"}};if(i.layout==="circular")this.addTrackToCombined({...C,options:{...C.options,layout:"circular"}});else{const r={...C,[n]:Qr};if(g==="left"){if(this.getLastView().tracks.left.filter(o=>o.type==="axis-track").length!==0)return this;this.getLastView().tracks.left=Lje(this.getLastView().tracks.left,0,r)}else if(g==="right"){if(this.getLastView().tracks.right.filter(o=>o.type==="axis-track").length!==0)return this;this.getLastView().tracks.right.push(r)}else{if(this.getLastView().tracks[g].filter(o=>o.type==="axis-track").length!==0)return this;this.getLastView().tracks[g].push(r)}}return this}setExampleHiglassViewConfig(){this.hg=Ang}}function pG(e,g,I,i){const n=i&&i!==0?i:void 0;let C=0;switch(g){case"less-than":case"LT":case"lt":C=I>e?n?(I-e)/n:1:0;break;case"less-than-or-equal-to":case"LTET":case"ltet":C=I>=e?n?(I-e)/n:1:0;break;case"greater-than":case"GT":case"gt":C=I{e[I]&&I!=="base"&&(g[I]=Object.assign(JSON.parse(JSON.stringify(g[I])),JSON.parse(JSON.stringify(e[I]))))}),g}}class ung{constructor(g,I,i){rt(this,"id"),rt(this,"theme"),rt(this,"specOriginal"),rt(this,"specComplete"),rt(this,"dataAggregated"),rt(this,"channelScales"),rt(this,"mouseEventModel"),this.id=ln(),this.theme=i??J2e(),this.dataAggregated=I,this.specOriginal=g,this.specComplete=structuredClone(g),this.channelScales={},this.mouseEventModel=new hgg;const n=this.validateSpec();if(!n.valid){console.warn("Gosling specification is not valid!",n.errorMessages);return}this.generateCompleteSpec(this.specComplete),this.flipRanges(this.specComplete),this.generateScales(),this.dataAggregated=Qig(this.spec(),this.dataAggregated)}getId(){return this.id}originalSpec(){return this.specOriginal}spec(){return this.specComplete}data(){return this.dataAggregated}getMouseEventModel(){return this.mouseEventModel}generateCompleteSpec(g){if(!g.width||!g.height){console.warn("Size of track is not determined yet.");return}if(g.orientation==="vertical"){const n=g.width;g.width=g.height,g.height=n}const I=this.getGenomicChannelKey();let i=!1;I==="x"&&(i=ut(g.x)&&g.x.axis!==void 0&&g.x.axis!=="none"),I==="y"&&(i=ut(g.y)&&g.y.axis!==void 0&&g.y.axis!=="none"),g.layout!=="circular"?ut(g.x)&&g.x.axis!==void 0&&g.x.axis!=="none"&&(g.height-=Qr):I==="x"&&i&&ut(g.x)&&g.x.axis==="top"?g.outerRadius=g.outerRadius-Qr:I==="x"&&i&&ut(g.x)&&g.x.axis==="bottom"&&(g.innerRadius=g.innerRadius+Qr),Hd.forEach(n=>{const C=g[n];ut(C)&&!("zeroBaseline"in C)&&C.type==="quantitative"&&(C.zeroBaseline=!0)}),this.addScaleMaterials(g)}flipRanges(g){ut(g.y)&&g.y.flip&&Array.isArray(g.y.range)&&(g.y.range=g.y.range.reverse())}getGenomicChannelKey(){return r2e(this.spec())}getGenomicChannel(){return D$(this.spec())}setChannelDomain(g,I,i){const n=this.originalSpec()[g];if(!i&&ut(n)&&n.domain!==void 0)return;const C=this.specComplete[g];ut(C)&&(C.domain=I)}updateChannelValue(){if(this.originalSpec().y===void 0){const g=this.spec().y,I=this.getChannelDomainArray("row");g&&N1(g)&&I&&this.spec().mark!=="withinLink"&&(g.value=this.spec().height/I.length/2)}}encodedValue(g,I){var i;if(g==="text"&&I!==void 0)return`${+I?~~I:I}`;const n=this.spec()[g],C=ut(n)?n.type:N1(n)?"constant":void 0;if(C){if(C==="constant")return this.channelScales[g]();if(I!==void 0&&(I===null&&(C==="quantitative"?I=0:C==="nominal"&&(I="null")),typeof this.channelScales[g]=="function"))switch(g){case"x":case"y":case"x1":case"y1":case"xe":case"ye":case"x1e":if(C==="quantitative"||C==="genomic")return this.channelScales[g](I);if(C==="nominal")return this.channelScales[g](I);break;case"stroke":case"color":if(C==="quantitative"){const r=this.channelScales[g].copy(),o=r.domain(),a=o[1]-o[0],s=Array.from((i=n.scaleOffset)!=null?i:[0,1]);return r.domain([o[0]+a*s.sort()[0],o[0]+a*s.sort()[1]])(I)}if(C==="nominal")return this.channelScales[g](I);break;case"size":if(C==="quantitative")return this.channelScales[g](I);if(C==="nominal")return this.channelScales[g](I);break;case"row":if(C==="nominal")return this.channelScales[g](I);break;case"strokeWidth":case"opacity":if(C==="quantitative")return this.channelScales[g](I);break;default:console.warn(`${g} is not supported for encoding values, so returning a undefined value`);return}}}trackVisibility(g){const I=this.spec();if(!I.visibility||I.visibility.length===0||I.visibility.filter(n=>n.target==="track").length===0)return!0;let i=!0;return I.visibility.filter(n=>n.target==="track").forEach(n=>{const{operation:C,measure:r,threshold:o}=n;let a;r==="zoomLevel"?a=g[r]:a=I[r],a!==void 0&&(i=i&&pG(a,C,o)===1)}),i}markVisibility(g,I){const i=this.spec();if(!i.visibility||i.visibility.length===0||i.visibility.filter(C=>C.target==="mark").length===0)return 1;let n=1;return i.visibility.filter(C=>C.target==="mark").forEach(C=>{const{operation:r,threshold:o,conditionPadding:a,transitionPadding:s,measure:A}=C,l=a??0,c=i.mark;let u=1;if(c==="text"&&o==="|xe-x|"&&A==="width"){const d=this.encodedPIXIProperty("xe",g),h=this.encodedPIXIProperty("x",g);d!==void 0&&(I!=null&&I.width)&&(u=pG(I.width+l,r,Math.abs(d-h),s))}else A==="width"&&typeof o=="number"&&(I!=null&&I.width)?u=pG(I.width+l,r,o,s):A==="zoomLevel"&&typeof o=="number"&&(I!=null&&I.zoomLevel)&&(u=pG(I.zoomLevel,r,o,s));n>u&&(n=u)}),n}visualPropertyByChannel(g,I){const i=I!==void 0?pI(I,this.spec()[g]):void 0;return this.encodedValue(g,i)}encodedPIXIProperty(g,I,i){const n=this.spec().mark;if(["text","color","row","stroke","opacity","strokeWidth","x","y","xe","x1","x1e","ye","size"].includes(g))return this.visualPropertyByChannel(g,I);switch(n){case"bar":return Fje(this,g,I,i);case"point":case"text":return Kje(this,g,I);case"rect":return zje(this,g,I,i);default:return}}addScaleMaterials(g){const I=this.data(),i=this.getGenomicChannel();if(!i||!i.field){console.warn("Genomic field is not provided in the specification");return}if(typeof g.width>"u"||typeof g.height>"u"){console.warn("Track size is not determined yet");return}Hd.forEach(n=>{var C,r,o,a;const s=g[n];if(w4e(g,n)&&ut(s)){const A=yT(I,c=>c[i.field]),l=[...A.keys()];if(!s.domain){const c="zeroBaseline"in s&&s.zeroBaseline?0:X1(l.map(d=>Oee(A.get(d).map(h=>s.field?h[s.field]:void 0)))),u=FG(l.map(d=>Oee(A.get(d).map(h=>s.field?h[s.field]:void 0))));s.domain=[c,u]}if(!s.range){const c=g.row,u=ut(c)?c.field:void 0,d=(C=this.getChannelDomainArray("row"))!=null?C:u?Array.from(new Set(I.map(m=>m[u]))):[1],h=g.height/d.length;switch(n){case"x":s.range=[0,g.width];break;case"y":s.range=[0,h];break}}}else{const A=g.row,l=ut(A)?A.field:void 0,c=(r=this.getChannelDomainArray("row"))!=null?r:l?Array.from(new Set(I.map(d=>d[l]))):[1],u=g.height/c.length;if(s){if(ut(s)&&(s.type==="quantitative"||s.type==="genomic")){if(s.domain===void 0){const d="zeroBaseline"in s&&s.zeroBaseline?0:(o=X1(I.map(m=>+m[s.field])))!=null?o:0,h=(a=FG(I.map(m=>+m[s.field])))!=null?a:0;s.domain=[d,h]}else s.type==="genomic"&&!Kte(s.domain)&&(s.domain=a_(s.domain));if((n==="color"||n==="stroke")&&s.type==="quantitative"&&!s.scaleOffset&&(s.scaleOffset=[0,1]),!s.range){let d;switch(n){case"x":case"xe":case"x1":case"x1e":d=[0,g.width];break;case"y":case"ye":d=[0,u];break;case"color":case"stroke":d=cng.QUANTITATIVE_COLOR;break;case"size":d=this.theme.markCommon.quantitativeSizeRange;break;case"strokeWidth":d=[1,3];break;case"opacity":d=[0,1];break}d&&(s.range=d)}}else if(ut(s)&&s.type==="nominal"&&(s.domain===void 0&&(s.domain=Array.from(new Set(I.map(d=>{var h;return(h=d[s.field])!=null?h:"null"})))),!s.range)){let d=2,h;switch(n){case"x":case"xe":h=[0,g.width];break;case"y":case"ye":h=[u,0];break;case"color":case"stroke":h=this.theme.markCommon.nominalColorRange;break;case"row":h=[0,g.height];break;case"size":h=s.domain.map(()=>d++);break}h&&(s.range=h)}}else{let d;switch(n){case"x":d=g.width/2;break;case"y":g.mark==="withinLink"?d=u:d=u/2;break;case"size":g.mark==="line"?d=this.theme.line.size:g.mark==="bar"||g.mark==="rect"||g.mark==="triangleRight"||g.mark==="triangleLeft"||g.mark==="triangleBottom"||g.stretch&&g.mark==="point"&&ut(g.x)&&ut(g.xe)?d=void 0:g.mark==="text"?d=12:d=this.theme.point.size;break;case"color":d=this.theme.markCommon.color;break;case"row":d=0;break;case"stroke":g.mark==="text"?d=this.theme.text.stroke:d=this.theme.markCommon.stroke;break;case"strokeWidth":g.mark==="rule"?d=this.theme.rule.strokeWidth:g.mark==="withinLink"||g.mark==="betweenLink"?d=this.theme.link.strokeWidth:g.mark==="text"?d=this.theme.text.strokeWidth:d=this.theme.markCommon.strokeWidth;break;case"opacity":d=this.theme.markCommon.opacity;break;case"text":d="";break}typeof d<"u"&&(g[n]={value:d})}}}),[["x","xe"],["y","ye"]].forEach(n=>{const[C,r]=n,o=g[C],a=g[r];if(ut(o)&&ut(a)&&o.type===a.type&&o.domain&&a.domain&&Array.isArray(o.domain)&&Array.isArray(a.domain)){if(o.type==="genomic"||o.type==="quantitative"){const s=X1([o.domain[0],a.domain[0]]),A=FG([o.domain[1],a.domain[1]]);o.domain=a.domain=[s,A]}else if(o.type==="nominal"){const s=Array.from(new Set([...o.domain,...a.domain]));o.range=a.range=s}}})}generateScales(){const g=this.spec();Hd.forEach(I=>{const i=g[I];if(N1(i))this.channelScales[I]=()=>i.value;else if(ut(i)){if(I==="text")return;const n=i.domain,C=i.range;if(n===void 0||C===void 0)return;if(i.type==="quantitative"||i.type==="genomic")switch(I){case"x":case"x1":case"xe":case"x1e":case"y":case"ye":case"size":case"opacity":case"strokeWidth":this.channelScales[I]=eh().domain(n).range(C);break;case"color":case"stroke":let r=sbe;Object.keys(NX).includes(C)&&(r=NX[C]),this.channelScales[I]=Xpe(r).domain(n);break}else if(i.type==="nominal")switch(I){case"x":case"xe":case"y":case"ye":case"row":this.channelScales[I]=Zpe().domain(n).range(C);break;case"size":this.channelScales[I]=wX().domain(n).range(C);break;case"color":case"stroke":this.channelScales[I]=wX(C).domain(n);break}}})}getChannelScale(g){return this.channelScales[g]}setChannelScale(g,I){this.channelScales[g]=I}isShowYAxis(){const g=this.spec(),I=this.getChannelDomainArray("y"),i=this.getChannelRangeArray("y");return ut(g.y)&&g.y.axis!=="none"&&g.y.type==="quantitative"&&!!I&&!!i}getChannelDomainArray(g){const I=this.spec()[g];return ut(I)&&Kte(I.domain)?I.domain:void 0}getChannelRangeArray(g){const I=this.spec()[g];return ut(I)&&S4e(I.range)?I.range:void 0}validateSpec(){return C2e(this.originalSpec())}}function Hr(e,g){G7.publish(e,g)}function dng(e,g){G7.subscribe(e,g)}function hng(e){G7.unsubscribe(e)}const ece={stroke:"black",strokeWidth:1,strokeOpacity:1,color:"none",opacity:1,arrange:"front"};function mng(){return{goslingModels:[],tabularData:[],skipRendering:!1}}const fng={type:"gosling-track",datatype:["multivec","epilogos"],orientation:"1d-horizontal",defaultOptions:{theme:mG("light")}},png=(e,g,I)=>{var i,n,C,r,o,a,s,A,l,c,u,d,h,m,f,b,p,y,Z,B,G,v,w,V,S,X,W,R,H,Y,K,F,J;const{tileProxy:P}=e.services,{BarTrack:ge}=e.tracks,q=xs({color:"black",size:12}),$=class A_ extends ge{constructor(){var Q,ie,he,ne,be,pe;super(g,I),fg(this,d),fg(this,m),fg(this,b),fg(this,y),fg(this,B),fg(this,v),fg(this,V),fg(this,X),fg(this,R),fg(this,Y),fg(this,F),rt(this,"tileSize"),rt(this,"mRangeBrush"),fg(this,i,void 0),fg(this,n,void 0),rt(this,"firstDraw",!0),rt(this,"gLegend",e.libraries.d3Selection.select(g.svgElement).append("g")),rt(this,"displayedLegends",[]),rt(this,"textGraphics",[]),rt(this,"textsBeingUsed",0),rt(this,"pMouseHover",new e.libraries.PIXI.Graphics),rt(this,"pMouseSelection",new e.libraries.PIXI.Graphics),fg(this,C,0),fg(this,r,0),fg(this,o,!1),fg(this,a,e.libraries.d3Selection.select(g.svgElement).append("g")),fg(this,s,new e.libraries.PIXI.TextStyle(q)),fg(this,A,new e.libraries.PIXI.Graphics),fg(this,l,new e.libraries.PIXI.Text("",q)),rt(this,"prevVisibleAndFetchedTiles"),rt(this,"resolvedTracks"),rt(this,"hideMousePosition"),g.dataFetcher.track=this,WC(this,n,{}),WC(this,i,this.options.spec.assembly),"overlay"in this.options.spec?this.options.spec.overlay=this.options.spec._overlay.map(Be=>({...Be,_renderingId:ln()})):this.options.spec._renderingId=ln(),this.fetchedTiles={},this.tileSize=(ie=(Q=this.tilesetInfo)==null?void 0:Q.tile_size)!=null?ie:1024;const{valid:ve,errorMessages:We}=C2e(this.options.spec);ve||console.warn("The specification of the following track is invalid",We,this.options.spec),this.pMain.addChild(this.pMouseHover),this.pMain.addChild(this.pMouseSelection),this.pMask.interactive=!0,this.mRangeBrush=new agg(Dt(this,a),e.libraries,(he=this.options.spec.style)==null?void 0:he.brush),this.mRangeBrush.on("brush",SI(this,R,H).bind(this)),this.pMask.on("mousedown",Be=>{const{x:Je,y:Pe}=Be.data.getLocalPosition(this.pMain);SI(this,b,p).call(this,Je,Pe,Be.data.originalEvent.altKey)}),this.pMask.on("mouseup",Be=>{const{x:Je,y:Pe}=Be.data.getLocalPosition(this.pMain);SI(this,B,G).call(this,Je,Pe)}),this.pMask.on("mousemove",Be=>{const{x:Je}=Be.data.getLocalPosition(this.pMain);SI(this,y,Z).call(this,Je)}),this.pMask.on("mouseout",SI(this,v,w).bind(this)),this.flipText=this.options.spec.orientation==="vertical",this.hideMousePosition&&(this.hideMousePosition(),this.hideMousePosition=void 0),(ne=this.options)!=null&&ne.showMousePosition&&!this.hideMousePosition&&(this.hideMousePosition=e.utils.showMousePosition(this,nC(this.getResolvedTracks()[0]),this.isShowGlobalMousePosition())),this.pLabel.removeChild(this.trackNotFoundText),Dt(this,l).anchor.x=1,Dt(this,l).anchor.y=1,this.pLabel.addChild(Dt(this,A)),this.pLabel.addChild(Dt(this,l)),e.libraries.PIXI.GRAPHICS_CURVES.adaptive=(pe=(be=this.options.spec.style)==null?void 0:be.enableSmoothPath)!=null?pe:!1,e.libraries.PIXI.GRAPHICS_CURVES.adaptive&&(e.libraries.PIXI.GRAPHICS_CURVES.maxLength=1,e.libraries.PIXI.GRAPHICS_CURVES.maxSegments=2048*10)}draw(){var Q,ie;this.clearMouseEventData(),this.textsBeingUsed=0,(Q=this.pMouseHover)==null||Q.clear();const he=()=>{const ne=this.dataFetcher instanceof BH;this.processAllTiles(ne),super.draw(),this.prevVisibleAndFetchedTiles=this.visibleAndFetchedTiles()};PV(this.dataFetcher)&&!abe(this.visibleAndFetchedTiles(),this.prevVisibleAndFetchedTiles)?this.updateTileAsync(this.dataFetcher,he):he(),(ie=this.mRangeBrush)==null||ie.drawBrush(!0),this.firstDraw&&(SI(this,F,J).call(this),this.firstDraw=!1)}initTile(Q){this.drawTile(Q)}updateTile(){}renderTile(){}drawTile(Q){var ie,he;Q.drawnAtScale=this._xScale.copy();const ne=Dt(this,n)[Q.tileId];ne&&((ie=Q.graphics)==null||ie.clear(),(he=Q.graphics)==null||he.removeChildren(),this.pBackground.clear(),this.pBackground.removeChildren(),this.pBorder.clear(),this.pBorder.removeChildren(),this.displayedLegends=[],ne.goslingModels.forEach(be=>{const pe=this.dimensions[0],ve=this._xScale.invert(pe)-this._xScale.invert(0);be.trackVisibility({zoomLevel:ve})&&(A4e(e,this,Q,be,this.options.theme),a4e(e,this,Q,be),s4e(e,this,Q,be,this.options.theme))}),this.forceDraw())}rerender(Q){this.options=Q,this.options.spec.layout==="circular"&&this.mRangeBrush.remove(),this.getResolvedTracks(!0),this.clearMouseEventData(),this.textsBeingUsed=0,this.processAllTiles(!0),this.draw(),this.forceDraw()}clearMouseEventData(){this.visibleAndFetchedGoslingModels().forEach(Q=>Q.getMouseEventModel().clear())}visibleAndFetchedGoslingModels(){return this.visibleAndFetchedTiles().flatMap(Q=>{var ie,he;return(he=(ie=Dt(this,n)[Q.tileId])==null?void 0:ie.goslingModels)!=null?he:[]})}remove(){super.remove(),this.gLegend&&(this.gLegend.remove(),this.gLegend=void 0),this.mRangeBrush.remove()}setDimensions(Q){super.setDimensions(Q),this.mRangeBrush.setSize(Q[1])}setPosition(Q){super.setPosition(Q),[this.pMain.position.x,this.pMain.position.y]=this.position,this.mRangeBrush.setOffset(...Q)}forceDraw(){this.animate()}zoomed(Q,ie){const he=this.mRangeBrush.getRange();this.mRangeBrush.updateRange(he?[Q(this._xScale.invert(he[0])),Q(this._xScale.invert(he[1]))]:null),this.xScale(Q),this.yScale(ie),this.refreshTiles(),this.draw(),this.forceDraw();const ne=Q.domain().map(be=>Uu(be,Dt(this,i),!0));Hr("location",{id:g.viewUid,genomicRange:ne})}setMask(Q,ie){if(this.pMask.clear(),this.pMask.beginFill(),this.options.spec.layout==="circular"){const[he,ne]=this.position,[be,pe]=this.dimensions,ve=he+be/2,We=ne+pe/2,Be=this.options.spec.outerRadius;this.pMask.drawCircle(ve,We,Be)}else this.pMask.drawRect(Q[0],Q[1],ie[0],ie[1]);this.pMask.endFill()}processAllTiles(Q=!1){var ie,he;this.tileSize=(he=(ie=this.tilesetInfo)==null?void 0:ie.tile_size)!=null?he:1024;const ne=this.visibleAndFetchedTiles();ne.forEach(ve=>SI(this,m,f).call(this,ve,Q)),this.combineAllTilesIfNeeded();const be=ne.flatMap(ve=>this.transformDataAndCreateModels(ve));ang(be);const pe=[].concat(...be.map(ve=>ve.data()));pe.length!==0&&this.options.siblingIds.forEach(ve=>Hr("rawData",{id:ve,data:pe}))}async updateTileAsync(Q,ie){if(!this.tilesetInfo)return;const he=this.visibleAndFetchedTiles(),ne=await Q.getTabularData(Object.values(he).map(pe=>pe.remoteId)),be=this.tilesetInfo;he.forEach((pe,ve)=>{if(ve===0){const[We]=e.utils.trackUtils.calculate1DVisibleTiles(be,this._xScale);pe.tileData.zoomLevel=We[0],pe.tileData.tilePos=[We[1],We[1]],pe.tileData.tabularData=ne}else pe.tileData.tabularData=[]}),ie()}calculateVisibleTiles(){var Q,ie,he,ne,be;if(this.tilesetInfo)if(PV(this.dataFetcher)){const pe=e.utils.trackUtils.calculate1DVisibleTiles(this.tilesetInfo,this._xScale),ve=(ie=(Q=this.tilesetInfo.max_tile_width)!=null?Q:this.dataFetcher.MAX_TILE_WIDTH)!=null?ie:Number.MAX_SAFE_INTEGER;for(const We of pe){const{tileWidth:Be}=this.getTilePosAndDimensions(We[0],[We[1],We[1]]);if(this.forceDraw(),Be>ve)return}this.setVisibleTiles(pe)}else{if(!this.tilesetInfo)return;const pe=this.calculateZoomLevel();if("resolutions"in this.tilesetInfo){const ve=this.tilesetInfo.resolutions.map(Pe=>+Pe).sort((Pe,De)=>De-Pe),We=P.calculateTilesFromResolution(ve[pe],this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]);let Be;nC(this.getResolvedTracks()[0])&&(Be=P.calculateTilesFromResolution(ve[pe],this._yScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]));const Je=SI(he=A_,c,u).call(he,We,Be,pe);this.setVisibleTiles(Je)}else{const ve=P.calculateTiles(pe,this.relevantScale(),this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width);let We;nC(this.getResolvedTracks()[0])&&(We=P.calculateTiles(pe,this._yScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1],this.tilesetInfo.max_zoom,(ne=this.tilesetInfo.max_width1)!=null?ne:this.tilesetInfo.max_width));const Be=SI(be=A_,c,u).call(be,ve,We,pe);this.setVisibleTiles(Be)}}}getTilePosAndDimensions(Q,ie){if(!this.tilesetInfo)throw Error("tilesetInfo not parsed");if("resolutions"in this.tilesetInfo){const ne=this.tilesetInfo.resolutions.map(Pe=>+Pe).sort((Pe,De)=>De-Pe)[Q],[be,pe]=ie,ve=ne*Dt(this,d,h),We=ve,Be=ve*be,Je=We*pe;return{tileX:Be,tileY:Je,tileWidth:ve,tileHeight:We}}else{const[he,ne]=ie,be=this.tilesetInfo.min_pos[0],pe=this.tilesetInfo.min_pos[1],ve=this.tilesetInfo.max_width/2**Q,We=this.tilesetInfo.max_width/2**Q,Be=be+he*ve,Je=pe+ne*We;return{tileX:Be,tileY:Je,tileWidth:ve,tileHeight:We}}}getIndicesOfVisibleDataInTile(Q){const ie=this._xScale.range();if(!this.tilesetInfo||!Q.tileData.tilePos||!("dense"in Q.tileData))return[0,0];const{tileX:he,tileWidth:ne}=this.getTilePosAndDimensions(Q.tileData.zoomLevel,Q.tileData.tilePos),be=e.libraries.d3Scale.scaleLinear().domain([0,Dt(this,d,h)]).range([he,he+ne]),pe=Math.max(0,Math.round(be.invert(this._xScale.invert(ie[0])))),ve=Math.min(Q.tileData.dense.length,Math.round(be.invert(this._xScale.invert(ie[1]))));return[pe,ve]}receivedTiles(Q){super.receivedTiles(Q),PV(this.dataFetcher)&&this.drawLoadingCue()}removeOldTiles(){super.removeOldTiles(),PV(this.dataFetcher)&&this.drawLoadingCue()}combineAllTilesIfNeeded(){var Q,ie,he;if(!this.shouldCombineTiles())return;const ne=this.visibleAndFetchedTiles();if(!ne||ne.length<=1)return;this.tileSize=((ie=(Q=this.tilesetInfo)==null?void 0:Q.tile_size)!=null?ie:1024)*ne.length;let be=[];ne.forEach((ve,We)=>{const Be=Dt(this,n)[ve.tileId];Be&&(be=[...be,...Be.tabularData],Be.skipRendering=We!==0)});const pe=Dt(this,n)[ne[0].tileId];pe.tabularData=be,(he=pe.tabularData[0])!=null&&he.uid&&(pe.tabularData=nje(pe.tabularData,"uid"))}shouldCombineTiles(){const Q=l4e(this.options.spec,"displace"),ie=()=>{const ne=this.visibleAndFetchedTiles();return ne.length>=1&&"dense"in ne[0].tileData},he=this.dataFetcher instanceof BH;return Q&&!ie()&&!he}getResolvedTracks(Q=!1){if(Q||!this.resolvedTracks){const ie=structuredClone(this.options.spec),he=T0(ie).filter(ne=>ne.mark!=="brush");he.forEach(ne=>{"values"in ne.data&&(ne.data.values=[])}),this.resolvedTracks=he}return this.resolvedTracks}transformDataAndCreateModels(Q){const ie=Dt(this,n)[Q.tileId];return!ie||ie.skipRendering?[]:(ie.goslingModels=[],this.getResolvedTracks().forEach(ne=>{var be;let pe=Array.from(ie.tabularData);(be=ne.dataTransform)==null||be.forEach(_e=>{switch(_e.type){case"filter":pe=x2e(_e,pe);break;case"concat":pe=Eig(_e,pe);break;case"replace":pe=Mig(_e,pe);break;case"log":pe=zig(_e,pe);break;case"exonSplit":pe=Lig(_e,pe,ne.assembly);break;case"genomicLength":pe=Pig(_e,pe);break;case"svType":pe=Jig(_e,pe);break;case"coverage":pe=Oig(_e,pe,this._xScale.copy());break;case"subjson":pe=Uig(_e,pe);break;case"displace":pe=_ig(_e,pe,this._xScale.copy());break}});try{if(PubSub){const gt=pe.length;PubSub.publish("data-preview",{id:g.viewUid,dataConfig:JSON.stringify({data:ne.data}),data:100>gt?pe:e7(pe,100)})}}catch{}const[ve,We]=this.dimensions,Be=kX(ne)?Qr:0,[Je,Pe]=[ve,We+Be],De=Math.min(Je,Pe)/Math.min(ne.width,ne.height);ne.innerRadius&&(ne.innerRadius=ne.innerRadius*De),ne.outerRadius&&(ne.outerRadius=ne.outerRadius*De),ne.width=Je,ne.height=Pe;const Qe=new ung(ne,pe,this.options.theme);ie.goslingModels.push(Qe)}),ie.goslingModels)}getMouseOverHtml(Q,ie){var he,ne,be,pe,ve;if(SI(this,X,W).call(this,"trackMouseOver",Q,ie),Dt(this,o)||!this.tilesetInfo)return"";this.pMouseHover.clear();const We=Uu(Math.floor(this._xScale.invert(Q)),Dt(this,i)),Be=SI(this,V,S).call(this,Q,ie);if(Be.length!==0?document.body.style.cursor="pointer":document.body.style.cursor="default",Be.length!==0){const Je=(he=this.options.spec.experimental)==null?void 0:he.mouseEvents;if(!!Je||Ym(Je)&&!!Je.mouseOver){const _e=this.pMouseHover;((be=(ne=this.options.spec.style)==null?void 0:ne.mouseOver)==null?void 0:be.arrange)!=="behind"&&(this.pMain.removeChild(_e),this.pMain.addChild(_e)),SI(this,Y,K).call(this,_e,Be,Object.assign({},ece,(pe=this.options.spec.style)==null?void 0:pe.mouseOver)),Hr("mouseOver",{id:g.viewUid,genomicPosition:We,data:Be.map(gt=>gt.value)})}const Qe=(ve=this.visibleAndFetchedGoslingModels().find(_e=>{var gt;return _e.spec().tooltip&&((gt=_e.spec().tooltip)==null?void 0:gt.length)!==0}))==null?void 0:ve.spec().tooltip;if(Qe){let _e=Qe.map(gt=>{var lt;const tt=Be[0].value[gt.field];let Xe=tt;if(gt.type==="quantitative"&>.format)Xe=e.libraries.d3Format.format(gt.format)(+tt);else if(gt.type==="genomic"){const{chromosome:ae,position:ye}=Uu(+tt,Dt(this,i));Xe=`${ae}:${e.libraries.d3Format.format(",")(ye)}`}return`${(lt=gt.alt)!=null?lt:gt.field}${Xe}`}).join("");return _e=`${_e}
`,Be.length>1&&(_e+=`
${Be.length-1} Additional Selections...
`),`
${_e}
`}}return""}minVisibleValue(){return 0}maxVisibleValue(){return 0}exportSVG(){throw new Error("exportSVG() not supported for gosling-track")}drawLoadingCue(){if(this.fetching.size){const ie=`Fetching... ${Array.from(this.fetching).join(" ")}`;Dt(this,l).text=ie,Dt(this,l).x=this.position[0]+this.dimensions[0]-6/2,Dt(this,l).y=this.position[1]+this.dimensions[1]-6/2;const he=e.libraries.PIXI.TextMetrics.measureText(ie,Dt(this,s)),{width:ne,height:be}=he;Dt(this,A).clear(),Dt(this,A).lineStyle(1,pt("grey"),1,.5),Dt(this,A).beginFill(pt("white"),.8),Dt(this,A).drawRect(this.position[0]+this.dimensions[0]-ne-6-1,this.position[1]+this.dimensions[1]-be-6-1,ne+6,be+6),Dt(this,l).visible=!0,Dt(this,A).visible=!0}else Dt(this,l).visible=!1,Dt(this,A).visible=!1}updateScaleOffsetFromOriginalSpec(Q,ie,he){this.getResolvedTracks().map(ne=>{if(ne._renderingId===Q){const be=ne[he];ut(be)&&(be.scaleOffset=ie)}})}shareScaleOffsetAcrossTracksAndTiles(Q,ie){this.visibleAndFetchedGoslingModels().forEach(ne=>{const be=ne.spec()[ie];ut(be)&&(be.scaleOffset=Q);const pe=ne.originalSpec()[ie];ut(pe)&&(pe.scaleOffset=Q)})}};i=new WeakMap,n=new WeakMap,C=new WeakMap,r=new WeakMap,o=new WeakMap,a=new WeakMap,s=new WeakMap,A=new WeakMap,l=new WeakMap,c=new WeakSet,u=function(te,Q,ie){if(!Q)return te.map(ne=>[ie,ne]);const he=[];return te.forEach(ne=>Q.forEach(be=>he.push([ie,ne,be]))),he},d=new WeakSet,h=function(){let te;return this.tilesetInfo&&(te="bins_per_dimension"in this.tilesetInfo?this.tilesetInfo.bins_per_dimension:this.tilesetInfo.tile_size),te??256},m=new WeakSet,f=function(te,Q=!1){if(Dt(this,n)[te.tileId]&&!Q||!te.tileData.tilePos)return;const ie=mng(),he=this.getResolvedTracks();if(he.length===0)return[];const ne=he[0];if("tabularData"in te.tileData)ie.tabularData=te.tileData.tabularData;else{const{tileX:be,tileY:pe,tileWidth:ve,tileHeight:We}=this.getTilePosAndDimensions(te.tileData.zoomLevel,te.tileData.tilePos),Be="length"in te.tileData?Array.from(te.tileData):[],Je=Object.assign({},te.tileData,{sparse:Be,tileX:be,tileY:pe,tileWidth:ve,tileHeight:We,tileSize:this.tileSize}),Pe=ing(ne,Je);Pe&&(ie.tabularData=Pe)}Dt(this,n)[te.tileId]=ie},b=new WeakSet,p=function(te,Q,ie){var he;WC(this,C,te),WC(this,r,Q);const ne=(he=this.options.spec.experimental)==null?void 0:he.mouseEvents,be=!!ne||Ym(ne)&&!!ne.rangeSelect;WC(this,o,be&&ie),this.pMouseHover.clear()},y=new WeakSet,Z=function(te){this.options.spec.layout!=="circular"&&Dt(this,o)&&this.mRangeBrush.updateRange([te,Dt(this,C)]).drawBrush().visible().disable()},B=new WeakSet,G=function(te,Q){var ie;SI(this,X,W).call(this,"trackClick",te,Q);const he=(ie=this.options.spec.experimental)==null?void 0:ie.mouseEvents,ne=!!he||Ym(he)&&!!he.click,be=Math.sqrt((Dt(this,C)-te)**2+(Dt(this,r)-Q)**2)>1;if(!Dt(this,o)&&!be?(this.mRangeBrush.clear(),this.pMouseSelection.clear()):this.mRangeBrush.enable(),WC(this,o,!1),!!this.tilesetInfo&&!be&&ne){const pe=Uu(Math.floor(this._xScale.invert(te)),Dt(this,i)),ve=SI(this,V,S).call(this,te,Q);ve.length!==0&&this.options.siblingIds.forEach(We=>Hr("click",{id:We,genomicPosition:pe,data:ve.map(Be=>Be.value)}))}},v=new WeakSet,w=function(){WC(this,o,!1),document.body.style.cursor="default",this.pMouseHover.clear()},V=new WeakSet,S=function(te,Q){var ie;const he=this.visibleAndFetchedGoslingModels(),ne=(ie=this.options.spec.experimental)==null?void 0:ie.mouseEvents,be=Ym(ne)&&ne.enableMouseOverOnMultipleMarks,pe=Ym(ne)&&ne.groupMarksByField,ve=he.map(We=>We.getMouseEventModel().findAll(te,Q,!0)).flat();if(be||ve.splice(1,ve.length-1),ve.length!==0&&pe){const We=Array.from(ve);he.forEach(Be=>{const Je=Be.getMouseEventModel().getSiblings(We,pe);ve.push(...Je)})}return ve},X=new WeakSet,W=function(te,Q,ie){const[he,ne]=this.position,[be,pe]=this.dimensions;if(this.options.spec.layout==="circular"){const ve=he+be/2,We=ne+pe/2,Be=this.options.spec.innerRadius,Je=this.options.spec.outerRadius,Pe=this.options.spec.startAngle,De=this.options.spec.endAngle;Agg([Q,ie],[be/2,pe/2],[Be,Je],[Pe,De])&&Hr(te,{id:g.viewUid,spec:structuredClone(this.options.spec),shape:{x:he,y:ne,width:be,height:pe,cx:ve,cy:We,innerRadius:Be,outerRadius:Je,startAngle:Pe,endAngle:De}})}else Hr(te,{id:g.viewUid,spec:structuredClone(this.options.spec),shape:{x:he,y:ne,width:be,height:pe}})},R=new WeakSet,H=function(te,Q=!1){var ie,he,ne,be;if(this.pMouseSelection.clear(),te===null){Q||Hr("rangeSelect",{id:g.viewUid,genomicRange:null,data:[]});return}const pe=this.visibleAndFetchedGoslingModels(),[ve,We]=te;let Be=pe.map(De=>De.getMouseEventModel().findAllWithinRange(ve,We,!0)).flat();const Je=(ie=this.options.spec.experimental)==null?void 0:ie.mouseEvents,Pe=Ym(Je)&&Je.groupMarksByField;if(Be.length!==0&&Pe&&pe.forEach(De=>{const Qe=De.getMouseEventModel().getSiblings(Be,Pe),_e=Array.from(new Set(Qe.map(gt=>gt.value[Pe])));Be=Be.filter(gt=>_e.indexOf(gt.value[Pe])===-1)}),Be.length!==0){const De=this.pMouseSelection;((ne=(he=this.options.spec.style)==null?void 0:he.select)==null?void 0:ne.arrange)!=="behind"&&(this.pMain.removeChild(De),this.pMain.addChild(De)),SI(this,Y,K).call(this,De,Be,Object.assign({},ece,(be=this.options.spec.style)==null?void 0:be.select))}if(!Q){const De=[Uu(Math.floor(this._xScale.invert(ve)),Dt(this,i)),Uu(Math.floor(this._xScale.invert(We)),Dt(this,i))];Hr("rangeSelect",{id:g.viewUid,genomicRange:De,data:Be.map(Qe=>Qe.value)})}this.forceDraw()},Y=new WeakSet,K=function(te,Q,ie){te.lineStyle(ie.strokeWidth,pt(ie.stroke),ie.strokeOpacity,.5),te.beginFill(pt(ie.color),ie.color==="none"?0:ie.opacity),Q.forEach(he=>{if(he.type==="point"){const[ne,be,pe=3]=he.polygon;te.drawCircle(ne,be,pe)}else he.type==="line"?(te.moveTo(he.polygon[0],he.polygon[1]),Uje(he.polygon).map(ne=>te.lineTo(ne[0],ne[1]))):te.drawPolygon(he.polygon)})},F=new WeakSet,J=function(){Hr("onNewTrack",{id:g.viewUid})},fg($,c);let j=$;return new j},C1=F$(fng,png),bng={type:"dummy-track",defaultOptions:{height:0,width:0,title:"",background:"#fff",textFontSize:12,textFontWeight:"normal",textStroke:"#000",textStrokeWidth:.1,outline:"#fff"}},yng=(e,g,I)=>{var i,n,C,r;const{SVGTrack:o}=e.tracks;class a extends o{constructor(){super(g,I),fg(this,i),fg(this,C),SI(this,i,n).call(this),SI(this,C,r).call(this),Hr("onNewTrack",{id:g.viewUid})}}return i=new WeakSet,n=function(){this.gMain.append("rect").attr("fill",I.background).attr("x",0).attr("y",0).attr("width",I.width).attr("height",I.height).style("stroke",I.outline)},C=new WeakSet,r=function(){this.gMain.append("text").attr("x",I.width/2).attr("y",(I.height+I.textFontSize)/2).style("text-anchor","middle").style("font-size",`${I.textFontSize}px`).style("font-weight",I.textFontWeight).style("stroke",I.textStroke).style("stroke-width",I.textStrokeWidth).text(I.title)},new a},tce=F$(bng,yng);let gce=!1;function Zng(){if(!gce){Vu({name:"GoslingTrack",track:C1,config:C1.config}),Vu({name:"Gosling2DTrack",track:C1,config:{...C1.config,type:"gosling-2d-track",orientation:"2d"}}),Vu({name:"AxisTrack",track:ale,config:ale.config}),Vu({name:"TextTrack",track:b3,config:b3.config}),Vu({name:"BrushTrack",track:e_,config:e_.config}),Vu({name:"DummyTrack",track:tce,config:tce.config});for(const e of Object.values(gng)){const{config:g}=e;Vu({dataFetcher:e,config:g},{pluginType:"dataFetcher"})}gce=!0}}function O2e(e){let g=0,I=0;return e.forEach(i=>{const n=i.boundingBox.x+i.boundingBox.width,C=i.boundingBox.y+i.boundingBox.height;I{s.boundingBox.y+=o+a}),n=[{track:vng({width:C.width,height:o},e.title,e.subtitle),boundingBox:{x:0,y:0,width:C.width,height:o},layout:{x:0,y:0,w:12,h:o/C.height*12}},...n]}else C.height=C.height+(8-C.height%8);const r=!(typeof e.responsiveSize!="object"?e.responsiveSize:e.responsiveSize.height);return n.forEach(o=>{o.layout.x=o.boundingBox.x/C.width*12,o.layout.w=o.boundingBox.width/C.width*12,o.layout.y=r?o.boundingBox.y:o.boundingBox.y/C.height*12,o.layout.h=r?o.boundingBox.height:o.boundingBox.height/C.height*12}),{trackInfos:n,size:C}}function s_(e,g,I=0,i=0,n=!0){let C=0,r=0,o=!0,a=!1;pb(e,c=>{a=!0,c.layout!=="circular"&&(o=!1)});let s=!0;Ube(e,c=>{(c.arrangement==="vertical"||c.arrangement==="horizontal")&&(s=!1)});const A=n&&o&&a&&s&&("views"in e&&(e.arrangement==="parallel"||e.arrangement==="serial")||"tracks"in e),l=g.length;if("tracks"in e){const c=e.tracks;e.orientation==="vertical"?(r=Math.max(...c.map(u=>u.height)),c.forEach((u,d,h)=>{ice([u])===1&&(u.width+=Qr),u.height=r,g.push({track:u,boundingBox:{x:I+C,y:i,width:u.width,height:r},layout:{x:0,y:0,w:0,h:0}}),h[d+1]&&h[d+1].overlayOnPreviousTrack||(C+=u.width,d!==h.length-1&&(C+=e.spacing!==void 0?e.spacing:0))})):(C=Math.max(...c.map(u=>u.width)),c.forEach((u,d,h)=>{ice([u])===1&&(u.height+=Qr);const m=T0(u);m.length>0&&nC(m[0])&&Gng([u])===1&&(C+=Qr),u.width=C,g.push({track:u,boundingBox:{x:I,y:i+r,width:C,height:u.height},layout:{x:0,y:0,w:0,h:0}}),h[d+1]&&h[d+1].overlayOnPreviousTrack||(r+=u.height,d!==h.length-1&&(r+=e.spacing!==void 0?e.spacing:0))}))}else if(e.arrangement==="parallel"||e.arrangement==="vertical"){const c=e.spacing!==void 0?e.spacing:T1;e.views.forEach((u,d,h)=>{var m,f,b,p,y;const Z=s_(u,g,I+((m=u.xOffset)!=null?m:0),i+((f=u.yOffset)!=null?f:0)+r,!A&&n);C<((b=u.xOffset)!=null?b:0)+Z.width&&(C=((p=u.xOffset)!=null?p:0)+Z.width),d!==h.length-1&&(r+=c),r+=((y=u.yOffset)!=null?y:0)+Z.height})}else(e.arrangement==="serial"||e.arrangement==="horizontal")&&e.views.forEach((c,u,d)=>{var h,m,f,b,p;const y=e.spacing!==void 0?e.spacing:T1,Z=s_(c,g,I+((h=c.xOffset)!=null?h:0)+C,i+((m=c.yOffset)!=null?m:0),!A&&n);r<((f=c.xOffset)!=null?f:0)+Z.height&&(r=((b=c.xOffset)!=null?b:0)+Z.height),u!==d.length-1&&(C+=y),C+=((p=c.xOffset)!=null?p:0)+Z.width});if(A){const c=g.slice(l),u="views"in e&&(e.arrangement==="parallel"||e.arrangement==="serial")&&e.views.length>1,d=e.spacing!==void 0?e.spacing:T1,h=Tje,m=e.centerRadius!==void 0?e.centerRadius:ube,f=C/2+h,b=f*(1-m);c.forEach((p,y)=>{var Z,B;if(VS(p.track))return;p.track.layout="circular",p.track.outerRadius=f-h-(p.boundingBox.y-i)/r*b,p.track.innerRadius=f-h-(p.boundingBox.y+p.boundingBox.height-i)/r*b;const G=d/C*360;p.track.startAngle=G+(p.boundingBox.x-I)/C*(C-d)/C*360,p.track.endAngle=(p.boundingBox.x+p.boundingBox.width-I)/C*(C-d)/C*360,p.boundingBox.x=I+((Z=p.track.xOffset)!=null?Z:0),p.boundingBox.y=i+((B=p.track.yOffset)!=null?B:0),p.boundingBox.height=p.track.height=p.boundingBox.width=p.track.width=f*2,y!==0&&(p.track.overlayOnPreviousTrack=!0),u&&ui(p.track)&&(p.track._overlay=p.track._overlay.filter(v=>v.mark!=="brush"))}),r=f*2}return e._assignedWidth=C,e._assignedHeight=r,{x:I,y:i,width:C,height:r}}function ice(e){return e.filter(g=>kX(g)).length}function Gng(e){return e.filter(g=>R4e(g)).length}const vng=(e,g,I)=>JSON.parse(JSON.stringify({mark:"header",width:e.width,height:e.height,title:g,subtitle:I}));function Bng(e){if(!e.includes("tileset_info/?d=")||!e.includes("https:")&&!e.includes("http:"))return{server:void 0,tilesetUid:void 0};const g=e.split("tileset_info/?d=")[0],I=e.split("tileset_info/?d=")[1];return{server:g,tilesetUid:I}}function Sng(e,g,I,i,n,C,r){var o,a,s,A,l,c,u,d,h,m,f,b,p,y,Z;if(VS(g))return e.addDefaultView(g.id).setDummyTrack(g).setLayout(i),e;const B=T0(g),G=B[0],v=(o=G.id)!=null?o:ln();G.id||(G.id=v),B.forEach(V=>{V.id&&C.addMapping(V.id,v)});const w=G.assembly;if(Yte(G.data)){let V,S;if(i7(G.data)){const ge=Bng(G.data.url);V=ge.server,S=ge.tilesetUid}const X=D$(G),W=r2e(G),H=(W==="x"||W==="xe")&&ut(X)?X.domain:void 0,Y=nC(G)&&ut(G.y)?G.y.domain:void 0,K=I.width-(G.layout!=="circular"&&G.orientation==="vertical"&&kX(G)?Qr:0),F=I.height-(G.layout!=="circular"&&G.orientation==="horizontal"&&kX(G)?Qr:0),J={uid:`${v}-track`,type:nC(G)?"gosling-2d-track":"gosling-track",server:V,tilesetUid:S,width:K,height:F,options:{id:v,siblingIds:C.getSiblingGoslingIds(v),showMousePosition:G.layout==="circular"?!1:n.root.showMousePosition,mousePositionColor:n.root.mousePositionColor,name:G.layout==="linear"?G.title:" ",labelPosition:G.title?n.track.titleAlign==="left"?"topLeft":"topRight":"none",labelShowResolution:!1,labelColor:n.track.titleColor,labelBackgroundColor:n.track.titleBackground,labelBackgroundOpacity:.5,labelTextOpacity:1,labelLeftMargin:1,labelTopMargin:1,labelRightMargin:0,labelBottomMargin:0,backgroundColor:"transparent",spec:{...g},theme:n}};if(G.data&&Yte(G.data)&&(G.data.type==="csv"||G.data.type==="json"||G.data.type==="bigwig"||G.data.type==="bam"||G.data.type==="vcf"||G.data.type==="gff"||G.data.type==="bed")){const ge=te=>{const Q=G[te];return Q&&ut(Q)?Q.field:void 0},q={x:ge("x"),xe:ge("xe"),x1:ge("x1"),x1e:ge("x1e")},$="url"in G.data&&(r==null?void 0:r[G.data.url])||{},j="indexUrl"in G.data&&(r==null?void 0:r[G.data.indexUrl])||{};J.data={...G.data,...q,urlFetchOptions:$,indexUrlFetchOptions:j,assembly:w}}if(Z4e(G)){J.type="heatmap";const ge=ut(G.color)&&typeof G.color.range=="string"?G.color.range:"viridis";J.options.colorRange=c4e(ge),J.options.trackBorderWidth=(s=(a=G.style)==null?void 0:a.outlineWidth)!=null?s:n.track.outlineWidth,J.options.trackBorderColor=(l=(A=G.style)==null?void 0:A.outline)!=null?l:n.track.outline,J.options.extent=(u=(c=G.style)==null?void 0:c.matrixExtent)!=null?u:"full",J.options.colorbarPosition=(d=G.color)!=null&&d.legend?J.options.extent==="lower-left"?"bottomLeft":"topRight":"hidden"}G.overlayOnPreviousTrack?e.setViewOrientation(G.orientation).addTrackToCombined(J):e.setViewOrientation(G.orientation).setAssembly(w).addDefaultView(v,w).setDomain(H,Y??H).adjustDomain(G.orientation,K,F).setMainTrack(J).addTrackSourceServers(V).setZoomFixed(G.static===!0).setZoomLimits((h=G.zoomLimits)!=null?h:[1,null]).setLayout(i);const P=(ge,q="horizontal",$,j)=>q==="horizontal"?ge==="x"&&$<=200||ge==="y"&&j<=200?"narrower":ge==="x"&&$<=400||ge==="y"&&j<=400?"narrow":"regular":ge==="x"&&j<=200||ge==="y"&&$<=200?"narrower":ge==="x"&&j<=400||ge==="y"&&$<=400?"narrow":"regular";["x","y"].forEach(ge=>{const q=G[ge];if(ut(q)&&"axis"in q&&q.axis&&q.axis!=="none"&&q.type==="genomic"){const $=P(ge,g.orientation,I.width,I.height);e.setAxisTrack(q.axis,$,{id:`${v}-${q.axis}-axis`,layout:G.layout,innerRadius:q.axis==="top"?G.outerRadius-Qr:G.innerRadius,outerRadius:q.axis==="top"?G.outerRadius:G.innerRadius+Qr,width:G.width,height:G.height,startAngle:G.startAngle,endAngle:G.endAngle,theme:n})}}),e.validateSpec(!0)}else G.mark==="header"&&(e.addDefaultView(`${v}-title`).setLayout(i),typeof G.title=="string"&&e.setTextTrack(I.width,((m=n.root.titleFontSize)!=null?m:18)+TX,G.title,n.root.titleColor,(f=n.root.titleFontSize)!=null?f:18,n.root.titleFontWeight,n.root.titleAlign,n.root.titleBackgroundColor,(b=n.root.titleFontFamily)!=null?b:C3.fontFamily),typeof G.subtitle=="string"&&e.setTextTrack(I.width,((p=n.root.subtitleFontSize)!=null?p:14)+TX,G.subtitle,n.root.subtitleColor,(y=n.root.subtitleFontSize)!=null?y:14,n.root.subtitleFontWeight,n.root.subtitleAlign,n.root.subtitleBackgroundColor,(Z=n.root.subtitleFontFamily)!=null?Z:C3.fontFamily));return e}function wng(e){const g=[];return e.spec().views.forEach(I=>{var i,n,C,r,o,a,s,A,l,c,u,d,h,m,f;const b=I.uid;let p=(o=(r=(C=(n=(i=I.tracks.center)==null?void 0:i[0])==null?void 0:n.contents)==null?void 0:C[0])==null?void 0:r.options)==null?void 0:o.spec;if(p||(p=(c=(l=(A=(s=(a=I.tracks.left)==null?void 0:a[0])==null?void 0:s.contents)==null?void 0:A[0])==null?void 0:l.options)==null?void 0:c.spec,p||(p=(f=(m=(h=(d=(u=I.tracks.left)==null?void 0:u[1])==null?void 0:d.contents)==null?void 0:h[0])==null?void 0:m.options)==null?void 0:f.spec)),!b||!p)return;T0(p).forEach(Z=>{Hd.forEach(B=>{var G,v,w,V;const S=Z[B];if(ut(S)&&"linkingId"in S&&S.linkingId){g.push({layout:Z.layout==="circular"?"circular":"linear",hgViewId:b,linkId:S.linkingId,isBrush:Z.mark==="brush",style:{color:(G=Z.color)==null?void 0:G.value,stroke:(v=Z.stroke)==null?void 0:v.value,strokeWidth:(w=Z.strokeWidth)==null?void 0:w.value,opacity:(V=Z.opacity)==null?void 0:V.value,startAngle:Z.startAngle,endAngle:Z.endAngle,innerRadius:Z.innerRadius,outerRadius:Z.outerRadius}});return}})})}),g}class Vng{constructor(){fg(this,jA,{})}addMapping(g,I){Dt(this,jA)[g]&&Dt(this,jA)[g]!==I&&console.warn(`The track ID ${g} already exists but overwriting with a different ID.`),Dt(this,jA)[g]=I}getTable(){return Dt(this,jA)}getGoslingIds(){return Object.keys(Dt(this,jA))}getHiGlassId(g){return Dt(this,jA)[g]}getSiblingGoslingIds(g){return Object.entries(Dt(this,jA)).filter(([,I])=>I===g).map(([I])=>I)}}jA=new WeakMap;function Rng(e){const g=new Set;return e.id&&g.add(e.id),pb(e,I=>{("views"in I||"tracks"in I)&&I.id&&g.add(I.id)}),Array.from(g)}function Wng(e){const g=new Set;return pb(e,I=>{!("views"in I)&&!("tracks"in I)&&I.id&&g.add(I.id)}),Array.from(g)}function Xng(e,g){let I;return e.id===g&&(I=e),pb(e,i=>{i.id===g&&(I=i)}),I}function Hng(e,g){return Rng(e).map(I=>{const i=Xng(e,I),n=Wng(i),C={x:Number.MAX_SAFE_INTEGER,y:Number.MAX_SAFE_INTEGER,xe:-Number.MAX_SAFE_INTEGER,ye:-Number.MAX_SAFE_INTEGER};return n.map(r=>g.find(o=>o.id===r)).forEach(r=>{if(!r)return;const{shape:o}=r;C.x>o.x&&(C.x=o.x),C.y>o.y&&(C.y=o.y),C.xe{const{track:u,boundingBox:d,layout:h}=c;Sng(C,u,d,h,i,r,n)});const o=wng(C);o.filter(c=>c.isBrush).forEach(c=>{var u;C.addBrush(c.layout,c.hgViewId,i,(u=o.find(d=>!d.isBrush&&d.linkId===c.linkId))==null?void 0:u.hgViewId,c.style)}),o.filter(c=>!c.isBrush).forEach(c=>{C.spec().zoomLocks.locksByViewUid[c.hgViewId]=c.linkId,C.spec().locationLocks.locksByViewUid[c.hgViewId]=c.linkId}),Array.from(new Set(o.map(c=>c.linkId))).forEach(c=>{C.spec().zoomLocks.locksDict[c]={uid:c},C.spec().locationLocks.locksDict[c]={uid:c},o.filter(u=>!u.isBrush).filter(u=>u.linkId===c).forEach(u=>{C.spec().zoomLocks.locksDict[c][u.hgViewId]=[1246253105e-1,1246253105e-1,249250.621],C.spec().locationLocks.locksDict[c][u.hgViewId]=[1246253105e-1,1246253105e-1,249250.621]})});const s=g.map(c=>({id:c.track.id,spec:c.track,shape:c.track.layout==="linear"||VS(c.track)?c.boundingBox:{...c.boundingBox,cx:c.boundingBox.x+c.boundingBox.width/2,cy:c.boundingBox.y+c.boundingBox.height/2,innerRadius:c.track.innerRadius,outerRadius:c.track.outerRadius,startAngle:c.track.startAngle,endAngle:c.track.endAngle}})),A=Hng(e,s),l=[...s.map(c=>({...c,type:"track"})),...A.map(c=>({...c,type:"view"}))];I(C.spec(),O2e(g),e,l,r.getTable())}function _2e(e,g,I,i,n){if(typeof e._assignedWidth>"u"||typeof e._assignedHeight>"u")return console.warn("Responsive spec cannot be used when width and height of a view is not determined yet."),!1;let C=!1;const{responsiveSpec:r}=e,o=e._assignedWidth*g,a=e._assignedHeight*I,s={width:o,height:a,aspectRatio:o/a},A={width:i,height:n,aspectRatio:i/n};return r&&r.forEach(l=>{const{spec:c,selectivity:u}=l;if(Nng(u,s,A)&&!C){Object.keys(c).forEach(d=>{e[d]=c[d]}),delete e.responsiveSpec,C=!0;return}}),"views"in e&&e.views.forEach(l=>{C=_2e(l,g,I,i,n)||C}),C}function Nng(e,g,I){if(e.length===0)return!1;let i=!0;return e.forEach(n=>{const{measure:C,operation:r,threshold:o,target:a}=n;i=i&&pG((a==="container"?I:g)[C],r,o)===1}),i}function kng(e,g,I,i,n,C){var r,o;const a=JSON.parse(JSON.stringify(e));i6e(a),Mtg(a,I),h3(a);const s=Ice(a,i);let{trackInfos:A}=s;const{size:l}=s,c=typeof e.responsiveSize=="object"&&((r=e.responsiveSize)==null?void 0:r.width)||e.responsiveSize,u=typeof e.responsiveSize=="object"&&((o=e.responsiveSize)==null?void 0:o.height)||e.responsiveSize,d=c&&n.containerSize?n.containerSize.width/l.width:1,h=u&&n.containerSize?n.containerSize.height/l.height:1,m=n.containerParentSize?n.containerParentSize.width:Number.MAX_SAFE_INTEGER,f=n.containerParentSize?n.containerParentSize.height:Number.MAX_SAFE_INTEGER;_2e(a,d,h,m,f)&&(h3(a),A=Ice(a,i).trackInfos),Hr("specProcessed",{id:a.id,spec:a}),Tng(a,A,g,i,C)}Zng();const L2e=U.forwardRef((e,g)=>{var I;const[i,n]=U.useState((I=e.id)!=null?I:ln());U.useEffect(()=>{var u;n((u=e.id)!=null?u:ln())},[e.id]);const C=e.viewConfig||{},r=!1,o=U.useMemo(()=>N.createElement(uy,{ref:g,options:{pixelPreciseMarginPadding:r,containerPaddingX:0,containerPaddingY:0,viewMarginTop:0,viewMarginBottom:0,viewMarginLeft:0,viewMarginRight:0,viewPaddingTop:0,viewPaddingBottom:0,viewPaddingLeft:0,viewPaddingRight:0,sizeMode:"bounded",rangeSelectionOnAlt:!0},viewConfig:C}),[C,r]),{padding:a=60,margin:s=0,border:A="none",background:l,alt:c="Gosling visualization"}=e.options||{};return N.createElement(N.Fragment,null,N.createElement("div",{id:i,className:`gosling-component ${e.className||""}`,style:{position:"relative",padding:a,margin:s,border:A,background:l,width:e.options.responsiveWidth?`calc(100% - ${a*2}px)`:e.size.width,height:e.options.responsiveHeight?`calc(100% - ${a*2}px)`:e.size.height,textAlign:"left"},"aria-label":c,role:"graphics-document","aria-roledescription":"visualization"},N.createElement("div",{key:JSON.stringify(C),id:"higlass-wrapper",className:"higlass-wrapper",style:{position:"relative",display:"block",background:l,margin:0,padding:0,width:e.options.responsiveWidth?"100%":e.size.width,height:e.options.responsiveHeight?"100%":e.size.height}},o)))});L2e.displayName="HiGlassComponentWrapper";function Yng(e,g,I,i,n){const C=structuredClone(n),r=d=>{const h=C[d];return h||console.warn(`Unable to find the track ID, named ${d}.`),h??d},o=()=>Object.keys(C),a=()=>[...I],s=()=>[...a().filter(d=>d.type==="track")],A=d=>{const h=s().find(m=>m.id===d);return h||console.warn(`[getTrack()] Unable to find a track using the ID (${d})`),h},l=()=>[...a().filter(d=>d.type==="view")],c=d=>{const h=l().find(m=>m.id===d);return h||console.warn(`Unable to find a view with the ID of ${d}`),h},u=d=>{var h,m;const f=(h=d==null?void 0:d.resolution)!=null?h:4,b=(m=d==null?void 0:d.transparentBackground)!=null?m:!1,p=e.pixiRenderer,y=Ys.create({width:p.width/2,height:p.height/2,resolution:f});p.render(e.pixiStage,y);const Z=p.plugins.extract.canvas(y),B=document.createElement("canvas");B.width=Z.width,B.height=Z.height;const G=B.getContext("2d");return b||(G.fillStyle=i.root.background,G.fillRect(0,0,B.width,B.height)),G.drawImage(Z,0,0),{canvas:B,resolution:f,canvasWidth:Z.width,canvasHeight:Z.height}};return{subscribe:dng,unsubscribe:hng,zoomTo:(d,h,m=0,f=1e3)=>{var b;const p=(b=A(d))==null?void 0:b.spec.assembly,Z=u7.fromString(h).toAbsoluteCoordinates(p,m),B=r(d);e.api.zoomTo(B,...Z,...Z,f)},zoomToExtent:(d,h=1e3)=>{var m;const f=(m=A(d))==null?void 0:m.spec.assembly,[b,p]=[0,bI(f).total],y=r(d);e.api.zoomTo(y,b,p,b,p,h)},zoomToGene:(d,h,m=0,f=1e3)=>{const b=r(d);e.api.zoomToGene(b,h,m,f)},suggestGene:(d,h,m)=>{const f=r(d);e.api.suggestGene(f,h,m)},getTrackIds:o,getTracksAndViews:a,getTracks:s,getTrack:A,getView:c,getViews:l,getCanvas:u,exportPng:d=>{const{canvas:h}=u({resolution:4,transparentBackground:d});h.toBlob(m=>{const f=document.createElement("a");document.body.append(f),f.download="gosling-visualization",f.href=URL.createObjectURL(m),f.click(),f.remove()},"image/png")},exportPdf:async d=>{const{jsPDF:h}=await s5e(()=>import("./jspdf.es.min-2fc60f34.js").then(p=>p.j),[]),{canvas:m}=u({resolution:4,transparentBackground:d}),f=m.toDataURL("image/jpeg",1),b=new h({orientation:m.width{I7(I)&&g.forEach(i=>{delete I[i]})})}const Kng=(e,g)=>{e.views.forEach(I=>{var i,n,C;const r=I.uid;if(!g.views.find(a=>a.uid===r)){const{locksByViewUid:a}=e.zoomLocks,s=a[r],A=(i=Object.entries(a).find(([c,u])=>c&&u===s))==null?void 0:i[0],l=!!g.views.find(c=>c.uid===A);A&&l&&(I.initialXDomain=(n=g.views.find(c=>c.uid===A))==null?void 0:n.initialXDomain,I.initialYDomain=(C=g.views.find(c=>c.uid===A))==null?void 0:C.initialYDomain)}})},xng=300,U2e=U.forwardRef((e,g)=>{var I,i,n;const[C,r]=U.useState(),[o,a]=U.useState({width:200,height:200}),s=U.useRef(),A=U.useRef(),l=U.useRef(),c=U.useRef([]),u=U.useRef({}),d=U.useRef(null),h=J2e(e.theme||"light"),m=(I=e.id)!=null?I:ln(),f=Z=>{const B=c.current.filter(V=>V.type=="view"),G=Z.filter(V=>V.type=="view"),v=new Set(B.map(V=>V.id));G.filter(V=>!v.has(V.id)).forEach(V=>{Hr("onNewView",{id:V.id})})};U.useImperativeHandle(g,()=>{const Z=Cce(d),B=Cce(c);return{api:Yng(Z,C,B,h,u.current),hgApi:Z}},[C,h]);const b=U.useCallback(()=>{if(e.spec){if(Ftg(e.spec).state==="error"){console.warn("Gosling spec is not valid. Please refer to the console message.");return}kng(e.spec,(B,G,v,w,V)=>{var S,X;if(l.current&&abe(nce(l.current,["linkingId"]),nce(v,["linkingId"])))return;(S=e.compiled)==null||S.call(e,e.spec,B,{_processedSpec:v}),a(G);const W=typeof C<"u";(X=e.experimental)!=null&&X.reactive&&W?setTimeout(()=>{var R,H;Kng(B,(R=d.current)==null?void 0:R.api.getViewConfig()),(H=d.current)==null||H.api.setViewConfig(B)},xng):r(B),f(w),l.current=v,c.current=w,u.current=V},[...Etg],h,{containerSize:s.current,containerParentSize:A.current},e.urlToFetchOptions)}},[e.spec,h]);U.useEffect(()=>{var Z;if(!((Z=e.spec)!=null&&Z.responsiveSize))return;const B=document.getElementById(m);if(!B)return;const G=new jse.ResizeSensor(B,V=>{(!s.current||s.current.height!==V.height||s.current.width!==V.width)&&(s.current=V,b())}),v=B.parentElement;if(!v)return;const w=new jse.ResizeSensor(v,V=>{(!A.current||A.current.height!==V.height||A.current.width!==V.width)&&(A.current=V,b())});return()=>{G.detach(),w.detach()}}),U.useEffect(()=>{b()},[e.spec,h]);const p=typeof((i=e.spec)==null?void 0:i.responsiveSize)!="object"?(n=e.spec)==null?void 0:n.responsiveSize:e.spec.responsiveSize.height;return U.useMemo(()=>{var Z,B,G;return N.createElement(L2e,{ref:d,viewConfig:C,size:o,id:m,className:e.className,options:{padding:e.padding,border:e.border,margin:e.margin,responsiveWidth:typeof((Z=e.spec)==null?void 0:Z.responsiveSize)!="object"?(B=e.spec)==null?void 0:B.responsiveSize:e.spec.responsiveSize.width,responsiveHeight:p,background:h.root.background,alt:(G=e.spec)==null?void 0:G.description}})},[C,o,h,p])});U2e.displayName="GoslingComponent";function Cce(e){return new Proxy({},{get(g,I,i){if(!e.current)throw Error("ref is not set!");return Reflect.get(e.current,I,i)}})}var rce=jI;rce.createRoot,rce.hydrateRoot;const Dng=["x","xe","x1","x1e","y","ye","y1","y1e","color","size","row","stroke","strokeWidth","opacity","text"];function Fng(e){return typeof e=="object"&&e!==null}function Eng(e){return"alignment"in e&&e.alignment==="overlay"}function Mng(e){return"_overlay"in e}function zng(e){return e!==null&&typeof e=="object"&&"value"in e}function Png(e){return Fng(e)&&!("value"in e)}function oce(e,g){return g in e}function Ec(e){return e.length===1?e[0]:e.slice(0,-1).join(", ")+" and "+e.slice(-1)}function bG(e){return e[0].toUpperCase()+e.slice(1)}const _n=new Map([["point","points"],["line","lines"],["bar","bars"],["rect","rectangles"],["area","area displayed"],["withinLink","connections"],["betweenLink","connections"],["triangleLeft","triangles"],["triangleRight","triangles"],["triangleBottom","triangles"]]),LA=new Map([["y","height"],["color","color"],["strokeWidth","stroke width"],["opacity","opacity"],["text","text"]]);function Jng(e){return e.includes("chr")&&(e=e.replace("chr","")),e}function Q2e(e,g){let I;Array.isArray(e.appearance.details.mark)?I=e.appearance.details.mark[g]:I=e.appearance.details.mark;const i=e.appearance.details.encodings.encodingDeepGenomic.map(r=>r.name),n=e.appearance.details.encodings.encodingDeepQuantitative.map(r=>r.name),C=e.appearance.details.encodings.encodingDeepNominal.map(r=>r.name);if(I==="point"&&n.includes("x")&&n.includes("y"))return"scatter plot";if(I==="line"&&i.includes("x")&&n.includes("y")||I==="line"&&n.includes("x")&&i.includes("y"))return"line chart";if(I==="bar"&&i.includes("x")&&n.includes("y"))return"bar chart";if(I==="rect"&&i.includes("x")&&i.includes("xe")&&n.includes("color"))return"heat map";if(I==="rect"&&i.includes("x")&&i.includes("xe")&&C.includes("color"))return"ideogram"}function Ong(e){const g={};g.tracks={},g.title=e.title,g.subtitle=e.subtitle;const I={nTracks:0,rowViews:0,colViews:0,allPositions:[[0,0]],totalRows:0,totalCols:0,matrix:{}},i={};i.arrangement="vertical",i.layout="linear",j2e(e,g,i,I),$ng(I);const n={description:"",nTracks:I.nTracks,parentValues:i,counter:I};return g.composition=n,g.alt="",g.longDescription="",g}function j2e(e,g,I,i){if("tracks"in e){const n=ace(e,I);if(e.tracks.length>1)if(Eng(e)){const C=e;g.tracks[i.nTracks]=Ung(C,n,i),i.nTracks>0&&(i.allPositions=[...i.allPositions,[i.rowViews,i.colViews]]),i.nTracks++}else for(const C in e.tracks){const r=e.tracks[C];g.tracks[i.nTracks]=l_(r,n,i),i.nTracks>0&&(i.allPositions=[...i.allPositions,[i.rowViews,i.colViews]]),i.nTracks++}else{if(Mng(e.tracks[0])){const C=e.tracks[0];g.tracks[i.nTracks]=Lng(C,I,i)}else{const C=e.tracks[0];g.tracks[i.nTracks]=l_(C,I,i)}i.nTracks>0&&(i.allPositions=[...i.allPositions,[i.rowViews,i.colViews]]),i.nTracks++}}else if("views"in e){const n=i.rowViews,C=i.colViews;e.views.forEach((r,o)=>{o!==0&&(I.arrangement==="vertical"||I.arrangement==="parallel"?i.rowViews++:i.colViews++);const a=ace(r,I);j2e(r,g,a,i)}),I.arrangement==="vertical"||I.arrangement==="parallel"?i.rowViews=n:i.colViews=C}}function ace(e,g){const I=JSON.parse(JSON.stringify(g));return oce(e,"arrangement")&&(I.arrangement=e.arrangement),oce(e,"layout")&&(I.layout=e.layout),I}function l_(e,g,I){const i={};i.alttype="single";let n;e.id!=="unknown"?n=e.id:n="";const C={trackNumber:I.nTracks,rowNumber:I.rowViews,colNumber:I.colViews},r={};r.assembly=e.assembly,r.layout=g.layout,r.overlaid=!1,r.mark=e.mark,r.encodings=q2e(e);const o=$2e(e.data,r.encodings),a={data:e.data,fields:o},s={description:"",details:C},A={description:"",details:r},l={description:"",details:a};return i.uid=n,i.position=s,i.appearance=A,i.title=e.title,i.data=l,i.charttype=Q2e(i),i.description="",i}function _ng(e,g,I){let i={...e,...e._overlay[0]};return delete i._overlay,delete i.overlayOnPreviousTrack,i=i,l_(i,g,I)}function Lng(e,g,I){return _ng(e,g,I)}function Ung(e,g,I){let i=Qbe(e);return i=mbe(i),Qng(e,i,g,I)}function Qng(e,g,I,i){const n={};n.alttype="ov-data";const C={trackNumber:i.nTracks,rowNumber:i.rowViews,colNumber:i.colViews},r=[],o=[];for(const s of g){const A=s;let l;A.id!=="unknown"?l=A.id:l="",r.push(l),o.push(jng(A,I))}const a={description:"",details:C};return n.position=a,n.title=e.title,n.appearance={details:{layout:"linear"}},n.tracks=o,n.uids=r,n.description="",n}function jng(e,g,I){const i={},n={};n.assembly=e.assembly,n.layout=g.layout,n.overlaid=!1,n.mark=e.mark,n.encodings=q2e(e);const C=$2e(e.data,n.encodings),r={data:e.data,fields:C},o={description:"",details:n},a={description:"",details:r};return i.appearance=o,i.data=a,i.charttype=Q2e(i),i.description="",i}function $2e(e,g){const I={};return g.encodingDeepGenomic.length>0&&(g.encodingDeepGenomic[0].details.field?I.genomicField=g.encodingDeepGenomic[0].details.field:I.genomicField),g.encodingDeepQuantitative.length>0&&(g.encodingDeepQuantitative[0].details.field?I.valueField=g.encodingDeepQuantitative[0].details.field:I.valueField),g.encodingDeepNominal.length>0&&(g.encodingDeepNominal[0].details.field?I.categoryField=g.encodingDeepNominal[0].details.field:I.categoryField),I}function q2e(e){const g=[],I=[],i=[],n=[];return Dng.forEach(r=>{const o=e[r];Png(o)?o.type==="genomic"?g.push({name:r,description:"",details:o}):o.type==="quantitative"?I.push({name:r,description:"",details:o}):i.push({name:r,description:"",details:o}):zng(o)&&n.push({name:r,description:"",details:o})}),{encodingDeepGenomic:g,encodingDeepQuantitative:I,encodingDeepNominal:i,encodingValue:n}}function $ng(e){e.totalRows=Math.max(...e.allPositions.map(I=>I[0]))+1,e.totalCols=Math.max(...e.allPositions.map(I=>I[1]))+1;const g={};for(let I=0;IC[0]===I).map(C=>C[1]),n={};for(const C of i)n[C]?n[C]=n[C]+1:n[C]=1;g[I]=n}e.matrix=g}function qng(e){eCg(e),ICg(e)}function eCg(e){e.composition.nTracks==1?(e.tracks[0].position.description="This is the only track.",e.tracks[0].alttype==="single"?e.composition.description="There is one ("+e.tracks[0].appearance.details.layout+") track.":e.composition.description="There is one (overlaid) track."):e.composition.nTracks==2?tCg(e):gCg(e)}function tCg(e){let g="",I="",i="";if(e.tracks[0].appearance.details.layout==="circular"&&e.tracks[1].appearance.details.layout==="circular")switch(e.composition.parentValues.arrangement){case"serial":g="left half of ring",I="right half of ring",i="Two circular tracks form one ring, with both the half of the ring.";break;case"parallel":g="outer ring",I="inner ring",i="Two circular tracks form two rings, one around the other.";break;case"horizontal":g="left",I="right",i="Two circular tracks are shown next to each other.";break;default:g="top",I="bottom",i="Two circular tracks are shown below each other."}else{const n=e.tracks[0].appearance.details.layout===e.tracks[1].appearance.details.layout;switch(e.composition.parentValues.arrangement){case"serial":g="left",I="right",i=" are shown next to each other.";break;default:g="top",I="bottom",i="are shown below each other."}n?i="".concat("Two linear tracks ",i):i="".concat("One linear and one circular track ",i)}e.tracks[0].position.description=g,e.tracks[1].position.description=I,e.composition.description=i}function gCg(e){const g=["first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth"];let I="";if(e.composition.counter.totalRows===1)I=I.concat("There are "+e.composition.counter.nTracks+" tracks, displayed next to each other.");else if(e.composition.counter.totalCols===1)I=I.concat("There are "+e.composition.counter.nTracks+" tracks, displayed below each other.");else{I=I.concat("There are "+e.composition.counter.nTracks+" tracks."),I=I.concat(" There are "+e.composition.counter.totalRows+" rows.");const i=Object.keys(e.composition.counter.matrix).map(C=>Object.keys(e.composition.counter.matrix[C]).length),n=[...new Set(i)];if(n.length==1)I=I.concat(" Each row has "+n[0]+" tracks next to each other");else if(n.length==2){const C=[],r=[];for(let o=0;oo+1))+" have "+n[0]+" column(s) each."),I=I.concat(" The other rows have "+n[1]+" column(s) each.")):(I=I.concat(" Row(s) "+Ec(r.map(o=>o+1))+" have "+n[1]+" column(s) each."),I=I.concat(" The other rows have "+n[0]+" column(s) each."))}else for(let C=0;C9?I=I.concat(" Row number "+C+" has "+e.composition.counter.matrix[C].length+" track(s) next to each other."):I=I.concat(" The "+g[C]+" row has "+e.composition.counter.matrix[C].length+" track(s) next to each other.")}e.composition.description=I;for(const i in e.tracks){let n="";const C=e.tracks[i].position.details,r=e.composition.counter;e.composition.counter.totalRows>1&&(C.rowNumber===0?n=n.concat("top row"):C.rowNumber===r.totalRows-1?n=n.concat("bottom row"):C.rowNumber<10?n=n.concat(g[C.rowNumber]+" row"):n=n.concat("row "+C.rowNumber+1)),e.composition.counter.totalCols>1&&(n.length>1&&(n=n.concat(", ")),r.matrix[C.rowNumber].length>1&&(C.colNumber===1?n=n.concat("left"):C.colNumber===r.matrix[C.rowNumber].length?n=n.concat("right"):C.colNumber===2&&r.matrix[C.rowNumber].length===3?n=n.concat("middle"):n=n.concat(g[C.colNumber]+" from left"))),e.tracks[i].position.description=n}}function ICg(e){for(const g in e.tracks){const I=e.tracks[g];if(I.alttype==="single"){let i="";I.charttype?i=i.concat(bG(I.charttype)+"."):i=i.concat("Chart with "+_n.get(I.appearance.details.mark)+".");const n=iCg(I);i=i.concat(" "+n.desc),I.appearance.description=i,I.appearance.details.encodingsDescList=n.descList}else I.alttype==="ov-mark"&&(I.appearance.details.encodingsDescList=[[]])}}function iCg(e){const g=e.appearance.details.mark;let I="",i="",n="",C="";const r=[],o=e.appearance.details.encodings.encodingDeepGenomic.map(l=>l.name);if(o.includes("x")&&o.includes("y"))I=I.concat("The genome is shown on both the x- and y-axes."),o.includes("xe")&&o.includes("ye")?(I=I.concat(" Each displays genomic intervals."),r.push(["x","The x-axis show genomic intervals."]),r.push(["y","The y-axis show genomic intervals."])):o.includes("xe")?(I=I.concat(" The genome on the x-axis displays genomic intervals."),r.push(["x","The x-axis show genomic intervals."]),r.push(["y","The y-axis shows the genome."])):o.includes("ye")?(I=I.concat(" The genome on the y-axis displays genomic intervals."),r.push(["x","The x-axis shows the genome."]),r.push(["y","The y-axis show genomic intervals."])):(r.push(["x","The x-axis shows the genome."]),r.push(["y","The y-axis shows the genome."]));else{if(o.includes("x")){let l="";o.includes("xe")?(l="in intervals",r.push(["x","The x-axis show genomic intervals."])):r.push(["x","The x-axis shows the genome."]),I=I.concat("The genome is shown "+l+" on the x-axis.")}if(o.includes("y")){let l="";o.includes("ye")?(l="in intervals",r.push(["y","The y-axis show genomic intervals."])):r.push(["y","The y-axis shows the genome."]),I=I.concat("The genome is shown "+l+" on the y-axis.")}}const a=e.appearance.details.encodings.encodingDeepQuantitative.map(l=>l.name);if(a.length>1){i=i.concat("The expression values are shown with "+_n.get(g)+" on the "+Ec(a)+"-axes.");for(const l of a)r.push([l,"The "+l+" of the "+_n.get(g)+" shows the expression values."])}else a.length===1&&(a.includes("y")?(i=i.concat("The expression is shown on the y-axis with "+_n.get(g)+"."),r.push(["y","The y-axis shows the expression with"+_n.get(g)+"."])):a.includes("color")?(i=i.concat("The height of the expression values is shown with color."),r.push(["color","The color of the "+_n.get(g)+" shows the expression values."])):(i=i.concat("The height of the expression values is shown with the "+a[0]+"-axis."),r.push([LA.get(a[0]),"The "+LA.get(a[0])+" of the "+_n.get(g)+" shows the expression values."])));const s=e.appearance.details.encodings.encodingDeepNominal.map(l=>l.name);if(s.length>1)if(s.includes("row")){n=n.concat("The chart is stratified by rows for the categories.");const l=s.filter(c=>c!=="row").map(c=>LA.get(c));n=n.concat(" The categories are also shown with the "+Ec(l)+" of the "+_n.get(g)+"."),r.push(["row","The chart is stratified by rows for the categories."]);for(const c of l)r.push([LA.get(c),"The "+c+" of the "+_n.get(g)+" show the different categories."])}else{const l=s.map(c=>LA.get(c));n=n.concat("The categories are shown with the "+Ec(l)+" of the "+_n.get(g)+".");for(const c of s)r.push([LA.get(c),"The "+c+" of the "+_n.get(g)+" show the different categories."])}else s.length==1&&(s.includes("row")?(n=n.concat("The chart is stratified by rows for the categories."),r.push(["row","The chart is stratified by rows for the categories."])):(n=n.concat("The "+LA.get(s[0])+" of the "+_n.get(g)+" indicates the different categories."),r.push([LA.get(s[0]),"The "+LA.get(s[0])+" of the "+_n.get(g)+" show the different categories."])));for(let l=0;lNv(n,I)))}.`):i=i.concat(` The ${g} value is shown at ${e.length} different genomic positions, the first being ${Nv(e[0],I)}.`),i}function c_(e,g){const I=Uu(e,g);return[Jng(I.chromosome),I.position]}function Nv(e,g){const I=c_(e,g);return I[0]==="unknown"?`absolute position ${I[1]} (on the unmapped part of the genome)`:`chromosome ${I[0]} position ${I[1]}`}function eHe(e,g,I){const i=c_(e,I),n=c_(g,I);return i[0]==="unknown"&&n[0]=="unknown"?` The genomic range is shown from from absolute position ${i[1]} to ${n[1]} on an unmapped part of the genome.`:n[0]==="unknown"?(i[0]==="chr1"||i[0]===1)&&i[1]===0?" The full genome is shown.":i[0]==="chrX"||i[0]==="X"?` The genomic range shown is chromomosome X (from position ${i[1]}), Y and an unmapped part of the genome at the end.`:i[0]==="chrY"||i[0]==="Y"?` The genomic range shown is chromomosome Y (from position ${i[1]}) and an unmapped part of the genome at the end.`:` The genomic range is shown from chromosome ${i[0]} to chromosome 22 and the X and Y chromosomes, as well as an unmapped part of the genome at the end.`:i===n?` The genomic range is shown from position ${i[1]} to position ${n[1]} on chromosome ${i[0]}.`:` The genomic range is shown from chromosome ${i[0]} position ${i[1]} to chromosome ${n[0]} position ${n[1]}.`}function tHe(e){var g,I,i,n,C,r,o,a,s,A,l,c,u,d,h,m,f,b;if((e.alttype==="single"||e.alttype==="ov-mark")&&e.data.details.dataStatistics){let p="";const y=e.appearance.details.assembly;if(((g=e.data.details.dataStatistics)==null?void 0:g.genomicMin)!==void 0&&((I=e.data.details.dataStatistics)==null?void 0:I.genomicMax)!==void 0){const Z=eHe(e.data.details.dataStatistics.genomicMin,e.data.details.dataStatistics.genomicMax,y),B=Nv((i=e.data.details.dataStatistics)==null?void 0:i.genomicMin,y),G=Nv((n=e.data.details.dataStatistics)==null?void 0:n.genomicMax,y);e.data.details.dataStatistics.genomicDescList=[["Minimum",B],["Maximum",G]],p=p.concat(Z)}if(((C=e.data.details.dataStatistics)==null?void 0:C.valueMin)!==void 0&&((r=e.data.details.dataStatistics)==null?void 0:r.valueMax)!==void 0){const Z=(o=e.data.details.dataStatistics)==null?void 0:o.valueMin,B=(a=e.data.details.dataStatistics)==null?void 0:a.valueMax;if(p=p.concat(` The expression values range from ${Z} to ${B}.`),(s=e.data.details.dataStatistics)!=null&&s.valueMaxGenomic&&((A=e.data.details.dataStatistics)!=null&&A.valueMinGenomic)){const G=Ace((l=e.data.details.dataStatistics)==null?void 0:l.valueMinGenomic,"minimum",y),v=Ace((c=e.data.details.dataStatistics)==null?void 0:c.valueMaxGenomic,"maximum",y);p=p.concat(v,G),e.data.details.dataStatistics.valueDescList=[["Minimum",`${Z}. ${G}`],["Maximum",`${B}. ${v}`]]}else e.data.details.dataStatistics.valueDescList=[["Minimum",`${Z}`],["Maximum",`${B}`]]}(u=e.data.details.dataStatistics)!=null&&u.categories&&(p=p.concat(` There are ${(d=e.data.details.dataStatistics)==null?void 0:d.categories.length} categories.`),(h=e.data.details.dataStatistics)!=null&&h.highestCategory&&(((m=e.data.details.dataStatistics)==null?void 0:m.highestCategory.length)===1?p=p.concat(` The highest value is observed in sample ${(f=e.data.details.dataStatistics)==null?void 0:f.highestCategory[0]}.`):p=p.concat(` The highest value is observed in samples ${Ec((b=e.data.details.dataStatistics)==null?void 0:b.highestCategory)}.`))),e.data.description=p}}function q$(e,g){if(g!==!1&&CCg(e),e.alt="Gosling visualization.",e.composition.nTracks===1)e.longDescription=e.tracks[0].description,e.alt=e.longDescription.split(".")[0];else if(e.composition.nTracks===2){let I="",i="";i=i.concat("Figure with two charts.");const n=e.tracks[0].description.split("."),C=n[0],r=n.slice(1).join("."),o=e.tracks[0].description.split("."),a=o[0],s=o.slice(1).join(".");i=i.concat(` ${bG(e.tracks[0].position.description)} track is a ${C.toLowerCase()}. ${r}`),i=i.concat(` ${bG(e.tracks[1].position.description)} track is a ${a.toLowerCase()}. ${s}`),I=I.concat(` Figure with ${C.toLowerCase()} on ${bG(e.tracks[0].position.description)} and ${a.toLowerCase()} on ${bG(e.tracks[1].position.description)}`),e.alt=I,e.longDescription=i}else{let I="";const i=[];for(const n in Object.keys(e.tracks)){const C=e.tracks[n].description.split(".")[0];i.push(C)}I=I.concat(`Figure with ${e.composition.nTracks} individual charts. Briefly, these are a ${Ec(i).toLowerCase()}.`),e.alt=`Gosling visualization with ${e.composition.nTracks} individual charts.`,e.longDescription=I}}function CCg(e){if(Object.keys(e.tracks).length===1)u_(e.tracks[0],!1);else for(const g in Object.keys(e.tracks))u_(e.tracks[g],!0)}function u_(e,g){let I="",i="";e.alttype==="single"||e.alttype==="ov-mark"?(g&&(i=i.concat(e.position.description)),I=i.concat(` ${e.appearance.description} ${e.data.description}`)):(g&&i.concat(e.position.description),I=i.concat(" Overlaid track with different data sources. See individual tracks for details.")),e.description=I}function rCg(e){qng(e),q$(e)}function oCg(e){nCg(e),q$(e)}function aCg(e,g,I){const i={id:e,flatTileData:g};if(I){if(I.genomicField!==void 0){const n=I.genomicField;try{const C=g.map(r=>r[n]).filter(r=>!isNaN(r));i.genomicMin=Math.min(...C),i.genomicMax=Math.max(...C)}catch(C){console.log(C)}}if(I.valueField!==void 0){const n=I.valueField;try{const C=g.map(r=>r[n]).filter(r=>!isNaN(r));i.valueMin=Math.min(...C),i.valueMax=Math.max(...C)}catch(C){console.log(C)}}if(I.genomicField!==void 0&&I.valueField!==void 0){const n=I.genomicField,C=I.valueField;try{i.valueMinGenomic=g.filter(r=>r[C]==i.valueMin).map(r=>r[n]),i.valueMaxGenomic=g.filter(r=>r[C]==i.valueMax).map(r=>r[n])}catch(r){console.log(r)}}if(I.categoryField!==void 0){const n=I.genomicField,C=I.valueField,r=I.categoryField;try{const o=g.map(l=>l[r]),a=[...new Set(o)],s={},A=[];for(const l of a){const c=g.filter(b=>b[r]===l),u=c.map(b=>b[C]).filter(b=>!isNaN(b)),d=Math.min(...u),h=Math.max(...u),m=c.filter(b=>b[C]==d).map(b=>b[n]),f=c.filter(b=>b[C]==h).map(b=>b[n]);s[l]=[d,m,h,f],h===i.valueMax&&A.push(l)}i.categories=a,i.categoryMinMaxWG=s,i.highestCategory=A}catch(o){console.log(o)}}return i}else return i}function ACg(e,g,I){const i=e.tracks.length>1;for(let n=0;n{let s=C.current;s!==r&&console.warn(`WARN: A component changed from ${s?"controlled":"uncontrolled"} to ${r?"controlled":"uncontrolled"}.`),C.current=r},[r]);let o=r?e:i,a=U.useCallback((s,...A)=>{let l=(c,...u)=>{I&&(Object.is(o,c)||I(c,...u)),r||(o=c)};typeof s=="function"?(console.warn("We can not support a function callback. See Github Issues for details https://github.com/adobe/react-spectrum/issues/2320"),n((u,...d)=>{let h=s(r?o:u,...d);return l(h,...A),r?u:h})):(r||n(s),l(s,...A))},[r,o,I]);return[o,a]}const WH={prefix:String(Math.round(Math.random()*1e10)),current:0},IHe=N.createContext(WH),uCg=N.createContext(!1);let dCg=!!(typeof window<"u"&&window.document&&window.document.createElement),YF=new WeakMap;function hCg(e=!1){let g=U.useContext(IHe),I=U.useRef(null);if(I.current===null&&!e){var i,n;let C=(n=N.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED)===null||n===void 0||(i=n.ReactCurrentOwner)===null||i===void 0?void 0:i.current;if(C){let r=YF.get(C);r==null?YF.set(C,{id:g.current,state:C.memoizedState}):C.memoizedState!==r.state&&(g.current=r.id,YF.delete(C))}I.current=++g.current}return I.current}function mCg(e){let g=U.useContext(IHe);g===WH&&!dCg&&console.warn("When server rendering, you must wrap your application in an to ensure consistent ids are generated between the client and server.");let I=hCg(!!e),i=`react-aria${g.prefix}`;return e||`${i}-${I}`}function fCg(e){let g=N.useId(),[I]=U.useState(kw()),i=I?"react-aria":`react-aria${WH.prefix}`;return e||`${i}-${g}`}const pCg=typeof N.useId=="function"?fCg:mCg;function bCg(){return!1}function yCg(){return!0}function ZCg(e){return()=>{}}function kw(){return typeof N.useSyncExternalStore=="function"?N.useSyncExternalStore(ZCg,bCg,yCg):U.useContext(uCg)}function iHe(e){var g,I,i="";if(typeof e=="string"||typeof e=="number")i+=e;else if(typeof e=="object")if(Array.isArray(e))for(g=0;g{};function ar(e){const g=U.useRef(null);return bi(()=>{g.current=e},[e]),U.useCallback((...I)=>{const i=g.current;return i(...I)},[])}function vCg(e){let[g,I]=U.useState(e),i=U.useRef(null),n=ar(()=>{let r=i.current.next();if(r.done){i.current=null;return}g===r.value?n():I(r.value)});bi(()=>{i.current&&n()});let C=ar(r=>{i.current=r(g),n()});return[g,C]}let BCg=!!(typeof window<"u"&&window.document&&window.document.createElement),XH=new Map;function Fh(e){let[g,I]=U.useState(e),i=U.useRef(null),n=pCg(g),C=U.useCallback(r=>{i.current=r},[]);return BCg&&XH.set(n,C),bi(()=>{let r=n;return()=>{XH.delete(r)}},[n]),U.useEffect(()=>{let r=i.current;r&&(i.current=null,I(r))}),n}function SCg(e,g){if(e===g)return e;let I=XH.get(e);if(I)return I(g),g;let i=XH.get(g);return i?(i(e),e):g}function sce(e=[]){let g=Fh(),[I,i]=vCg(g),n=U.useCallback(()=>{i(function*(){yield g,yield document.getElementById(g)?g:void 0})},[g,i]);return bi(n,[g,n,...e]),I}function wCg(...e){return(...g)=>{for(let I of e)typeof I=="function"&&I(...g)}}const Cc=e=>{var g;return(g=e==null?void 0:e.ownerDocument)!==null&&g!==void 0?g:document},HH=e=>e&&"window"in e&&e.window===e?e:Cc(e).defaultView||window;function Gi(...e){let g={...e[0]};for(let I=1;I=65&&n.charCodeAt(2)<=90?g[n]=wCg(C,r):(n==="className"||n==="UNSAFE_className")&&typeof C=="string"&&typeof r=="string"?g[n]=GCg(C,r):n==="id"&&C&&r?g.id=SCg(C,r):g[n]=r!==void 0?r:C}}return g}function VCg(...e){return e.length===1?e[0]:g=>{for(let I of e)typeof I=="function"?I(g):I!=null&&(I.current=g)}}const RCg=new Set(["id"]),WCg=new Set(["aria-label","aria-labelledby","aria-describedby","aria-details"]),XCg=new Set(["href","target","rel","download","ping","referrerPolicy"]),HCg=/^(data-.*)$/;function YA(e,g={}){let{labelable:I,isLink:i,propNames:n}=g,C={};for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&(RCg.has(r)||I&&WCg.has(r)||i&&XCg.has(r)||n!=null&&n.has(r)||HCg.test(r))&&(C[r]=e[r]);return C}function vs(e){if(TCg())e.focus({preventScroll:!0});else{let g=NCg(e);e.focus(),kCg(g)}}let r1=null;function TCg(){if(r1==null){r1=!1;try{var e=document.createElement("div");e.focus({get preventScroll(){return r1=!0,!0}})}catch{}}return r1}function NCg(e){for(var g=e.parentNode,I=[],i=document.scrollingElement||document.documentElement;g instanceof HTMLElement&&g!==i;)(g.offsetHeight"u"||window.navigator==null?!1:((g=window.navigator.userAgentData)===null||g===void 0?void 0:g.brands.some(I=>e.test(I.brand)))||e.test(window.navigator.userAgent)}function t8(e){var g;return typeof window<"u"&&window.navigator!=null?e.test(((g=window.navigator.userAgentData)===null||g===void 0?void 0:g.platform)||window.navigator.platform):!1}function Eh(){return t8(/^Mac/i)}function YCg(){return t8(/^iPhone/i)}function nHe(){return t8(/^iPad/i)||Eh()&&navigator.maxTouchPoints>1}function g8(){return YCg()||nHe()}function KCg(){return Eh()||g8()}function xCg(){return $k(/AppleWebKit/i)&&!DCg()}function DCg(){return $k(/Chrome/i)}function TH(){return $k(/Android/i)}function FCg(){return $k(/Firefox/i)}const ECg=U.createContext({isNative:!0,open:zCg});function CHe(){return U.useContext(ECg)}function Mh(e,g,I=!0){var i,n;let{metaKey:C,ctrlKey:r,altKey:o,shiftKey:a}=g;FCg()&&(!((n=window.event)===null||n===void 0||(i=n.type)===null||i===void 0)&&i.startsWith("key"))&&e.target==="_blank"&&(Eh()?C=!0:r=!0);let s=xCg()&&Eh()&&!nHe()?new KeyboardEvent("keydown",{keyIdentifier:"Enter",metaKey:C,ctrlKey:r,altKey:o,shiftKey:a}):new MouseEvent("click",{metaKey:C,ctrlKey:r,altKey:o,shiftKey:a,bubbles:!0,cancelable:!0});Mh.isOpening=I,vs(e),e.dispatchEvent(s),Mh.isOpening=!1}Mh.isOpening=!1;function MCg(e,g){if(e instanceof HTMLAnchorElement)g(e);else if(e.hasAttribute("data-href")){let I=document.createElement("a");I.href=e.getAttribute("data-href"),e.hasAttribute("data-target")&&(I.target=e.getAttribute("data-target")),e.hasAttribute("data-rel")&&(I.rel=e.getAttribute("data-rel")),e.hasAttribute("data-download")&&(I.download=e.getAttribute("data-download")),e.hasAttribute("data-ping")&&(I.ping=e.getAttribute("data-ping")),e.hasAttribute("data-referrer-policy")&&(I.referrerPolicy=e.getAttribute("data-referrer-policy")),e.appendChild(I),g(I),e.removeChild(I)}}function zCg(e,g){MCg(e,I=>Mh(I,g))}function PCg(e){return{"data-href":e.href,"data-target":e.target,"data-rel":e.rel,"data-download":e.download,"data-ping":e.ping,"data-referrer-policy":e.referrerPolicy}}let Ff=new Map,d_=new Set;function lce(){if(typeof window>"u")return;let e=I=>{let i=Ff.get(I.target);i||(i=new Set,Ff.set(I.target,i),I.target.addEventListener("transitioncancel",g)),i.add(I.propertyName)},g=I=>{let i=Ff.get(I.target);if(i&&(i.delete(I.propertyName),i.size===0&&(I.target.removeEventListener("transitioncancel",g),Ff.delete(I.target)),Ff.size===0)){for(let n of d_)n();d_.clear()}};document.body.addEventListener("transitionrun",e),document.body.addEventListener("transitionend",g)}typeof document<"u"&&(document.readyState!=="loading"?lce():document.addEventListener("DOMContentLoaded",lce));function rHe(e){requestAnimationFrame(()=>{Ff.size===0?e():d_.add(e)})}function oHe(){let e=U.useRef(new Map),g=U.useCallback((n,C,r,o)=>{let a=o!=null&&o.once?(...s)=>{e.current.delete(r),r(...s)}:r;e.current.set(r,{type:C,eventTarget:n,fn:a,options:o}),n.addEventListener(C,r,o)},[]),I=U.useCallback((n,C,r,o)=>{var a;let s=((a=e.current.get(r))===null||a===void 0?void 0:a.fn)||r;n.removeEventListener(C,s,o),e.current.delete(r)},[]),i=U.useCallback(()=>{e.current.forEach((n,C)=>{I(n.eventTarget,n.type,C,n.options)})},[I]);return U.useEffect(()=>i,[i]),{addGlobalListener:g,removeGlobalListener:I,removeAllGlobalListeners:i}}function JCg(e,g){let{id:I,"aria-label":i,"aria-labelledby":n}=e;return I=Fh(I),n&&i?n=[...new Set([I,...n.trim().split(/\s+/)])].join(" "):n&&(n=n.trim().split(/\s+/).join(" ")),!i&&!n&&g&&(i=g),{id:I,"aria-label":i,"aria-labelledby":n}}function Yw(e){const g=U.useRef();return U.useMemo(()=>({get current(){return g.current},set current(I){g.current=I,typeof e=="function"?e(I):e&&(e.current=I)}}),[e])}function aHe(e,g){const I=U.useRef(!0),i=U.useRef(null);U.useEffect(()=>(I.current=!0,()=>{I.current=!1}),[]),U.useEffect(()=>{I.current?I.current=!1:(!i.current||g.some((n,C)=>!Object.is(n,i[C])))&&e(),i.current=g},g)}function AHe(e,g){bi(()=>{if(e&&e.ref&&g)return e.ref.current=g.current,()=>{e.ref.current=null}})}function _l(e){for(NH(e)&&(e=e.parentElement);e&&!NH(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}function NH(e){let g=window.getComputedStyle(e);return/(auto|scroll)/.test(g.overflow+g.overflowX+g.overflowY)}let OCg=0;const KF=new Map;function qk(e){let[g,I]=U.useState(void 0);return bi(()=>{if(!e)return;let i=KF.get(e);if(i)I(i.element.id);else{let n=`react-aria-description-${OCg++}`;I(n);let C=document.createElement("div");C.id=n,C.style.display="none",C.textContent=e,document.body.appendChild(C),i={refCount:0,element:C},KF.set(e,i)}return i.refCount++,()=>{--i.refCount===0&&(i.element.remove(),KF.delete(e))}},[e]),{"aria-describedby":e?g:void 0}}function _Cg(e,g,I,i){let n=ar(I),C=I==null;U.useEffect(()=>{if(C)return;let r=e.current;return r.addEventListener(g,n,i),()=>{r.removeEventListener(g,n,i)}},[e,g,i,C,n])}function sHe(e,g){let I=cce(e,g,"left"),i=cce(e,g,"top"),n=g.offsetWidth,C=g.offsetHeight,r=e.scrollLeft,o=e.scrollTop,{borderTopWidth:a,borderLeftWidth:s}=getComputedStyle(e),A=e.scrollLeft+parseInt(s,10),l=e.scrollTop+parseInt(a,10),c=A+e.clientWidth,u=l+e.clientHeight;I<=r?r=I-parseInt(s,10):I+n>c&&(r+=I+n-c),i<=l?o=i-parseInt(a,10):i+C>u&&(o+=i+C-u),e.scrollLeft=r,e.scrollTop=o}function cce(e,g,I){const i=I==="left"?"offsetLeft":"offsetTop";let n=0;for(;g.offsetParent&&(n+=g[i],g.offsetParent!==e);){if(g.offsetParent.contains(e)){n-=e[i];break}g=g.offsetParent}return n}function Ll(e,g){if(document.contains(e)){let r=document.scrollingElement||document.documentElement;if(window.getComputedStyle(r).overflow==="hidden"){let a=_l(e);for(;e&&a&&e!==r&&a!==r;)sHe(a,e),e=a,a=_l(e)}else{var I;let{left:a,top:s}=e.getBoundingClientRect();e==null||(I=e.scrollIntoView)===null||I===void 0||I.call(e,{block:"nearest"});let{left:A,top:l}=e.getBoundingClientRect();if(Math.abs(a-A)>1||Math.abs(s-l)>1){var i,n,C;g==null||(n=g.containingElement)===null||n===void 0||(i=n.scrollIntoView)===null||i===void 0||i.call(n,{block:"center",inline:"center"}),(C=e.scrollIntoView)===null||C===void 0||C.call(e,{block:"nearest"})}}}}function h_(e){return e.mozInputSource===0&&e.isTrusted?!0:TH()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function LCg(e){return!TH()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function UCg(e,g,I){let i=U.useRef(g),n=ar(()=>{I&&I(i.current)});U.useEffect(()=>{var C;let r=e==null||(C=e.current)===null||C===void 0?void 0:C.form;return r==null||r.addEventListener("reset",n),()=>{r==null||r.removeEventListener("reset",n)}},[e,n])}function QCg(e,g){return g.get?g.get.call(e):g.value}function lHe(e,g,I){if(!g.has(e))throw new TypeError("attempted to "+I+" private field on non-instance");return g.get(e)}function jCg(e,g){var I=lHe(e,g,"get");return QCg(e,I)}function $Cg(e,g){if(g.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}function qCg(e,g,I){$Cg(e,g),g.set(e,I)}function erg(e,g,I){if(g.set)g.set.call(e,I);else{if(!g.writable)throw new TypeError("attempted to set read only private field");g.value=I}}function uce(e,g,I){var i=lHe(e,g,"set");return erg(e,i,I),I}let cp="default",m_="",KW=new WeakMap;function dce(e){if(g8()){if(cp==="default"){const g=Cc(e);m_=g.documentElement.style.webkitUserSelect,g.documentElement.style.webkitUserSelect="none"}cp="disabled"}else(e instanceof HTMLElement||e instanceof SVGElement)&&(KW.set(e,e.style.userSelect),e.style.userSelect="none")}function o1(e){if(g8()){if(cp!=="disabled")return;cp="restoring",setTimeout(()=>{rHe(()=>{if(cp==="restoring"){const g=Cc(e);g.documentElement.style.webkitUserSelect==="none"&&(g.documentElement.style.webkitUserSelect=m_||""),m_="",cp="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&KW.has(e)){let g=KW.get(e);e.style.userSelect==="none"&&g&&(e.style.userSelect=g),e.getAttribute("style")===""&&e.removeAttribute("style"),KW.delete(e)}}const cHe=N.createContext({register:()=>{}});cHe.displayName="PressResponderContext";function trg(e){let g=U.useContext(cHe);if(g){let{register:I,...i}=g;e=Gi(i,e),I()}return AHe(g,e.ref),e}var a1=new WeakMap;class A1{continuePropagation(){uce(this,a1,!1)}get shouldStopPropagation(){return jCg(this,a1)}constructor(g,I,i){qCg(this,a1,{writable:!0,value:void 0}),uce(this,a1,!0),this.type=g,this.pointerType=I,this.target=i.currentTarget,this.shiftKey=i.shiftKey,this.metaKey=i.metaKey,this.ctrlKey=i.ctrlKey,this.altKey=i.altKey}}const hce=Symbol("linkClicked");function I8(e){let{onPress:g,onPressChange:I,onPressStart:i,onPressEnd:n,onPressUp:C,isDisabled:r,isPressed:o,preventFocusOnPress:a,shouldCancelOnPointerExit:s,allowTextSelectionOnPress:A,ref:l,...c}=trg(e),[u,d]=U.useState(!1),h=U.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,ignoreClickAfterPress:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null}),{addGlobalListener:m,removeAllGlobalListeners:f}=oHe(),b=ar((v,w)=>{let V=h.current;if(r||V.didFirePressStart)return!1;let S=!0;if(V.isTriggeringEvent=!0,i){let X=new A1("pressstart",w,v);i(X),S=X.shouldStopPropagation}return I&&I(!0),V.isTriggeringEvent=!1,V.didFirePressStart=!0,d(!0),S}),p=ar((v,w,V=!0)=>{let S=h.current;if(!S.didFirePressStart)return!1;S.ignoreClickAfterPress=!0,S.didFirePressStart=!1,S.isTriggeringEvent=!0;let X=!0;if(n){let W=new A1("pressend",w,v);n(W),X=W.shouldStopPropagation}if(I&&I(!1),d(!1),g&&V&&!r){let W=new A1("press",w,v);g(W),X&&(X=W.shouldStopPropagation)}return S.isTriggeringEvent=!1,X}),y=ar((v,w)=>{let V=h.current;if(r)return!1;if(C){V.isTriggeringEvent=!0;let S=new A1("pressup",w,v);return C(S),V.isTriggeringEvent=!1,S.shouldStopPropagation}return!0}),Z=ar(v=>{let w=h.current;w.isPressed&&w.target&&(w.isOverTarget&&w.pointerType!=null&&p(UA(w.target,v),w.pointerType,!1),w.isPressed=!1,w.isOverTarget=!1,w.activePointerId=null,w.pointerType=null,f(),A||o1(w.target))}),B=ar(v=>{s&&Z(v)}),G=U.useMemo(()=>{let v=h.current,w={onKeyDown(S){if(xF(S.nativeEvent,S.currentTarget)&&S.currentTarget.contains(S.target)){var X;fce(S.target,S.key)&&S.preventDefault();let W=!0;!v.isPressed&&!S.repeat&&(v.target=S.currentTarget,v.isPressed=!0,W=b(S,"keyboard"),m(Cc(S.currentTarget),"keyup",V,!1)),W&&S.stopPropagation(),S.metaKey&&Eh()&&((X=v.metaKeyEvents)===null||X===void 0||X.set(S.key,S.nativeEvent))}else S.key==="Meta"&&(v.metaKeyEvents=new Map)},onKeyUp(S){xF(S.nativeEvent,S.currentTarget)&&!S.repeat&&S.currentTarget.contains(S.target)&&v.target&&y(UA(v.target,S),"keyboard")},onClick(S){if(!(S&&!S.currentTarget.contains(S.target))&&S&&S.button===0&&!v.isTriggeringEvent&&!Mh.isOpening){let X=!0;if(r&&S.preventDefault(),!v.ignoreClickAfterPress&&!v.ignoreEmulatedMouseEvents&&!v.isPressed&&(v.pointerType==="virtual"||h_(S.nativeEvent))){!r&&!a&&vs(S.currentTarget);let W=b(S,"virtual"),R=y(S,"virtual"),H=p(S,"virtual");X=W&&R&&H}v.ignoreEmulatedMouseEvents=!1,v.ignoreClickAfterPress=!1,X&&S.stopPropagation()}}},V=S=>{var X;if(v.isPressed&&v.target&&xF(S,v.target)){var W;fce(S.target,S.key)&&S.preventDefault();let H=S.target,Y=p(UA(v.target,S),"keyboard",v.target.contains(H));f(),Y&&S.stopPropagation(),S.key!=="Enter"&&i8(v.target)&&v.target.contains(H)&&!S[hce]&&(S[hce]=!0,Mh(v.target,S,!1)),v.isPressed=!1,(W=v.metaKeyEvents)===null||W===void 0||W.delete(S.key)}else if(S.key==="Meta"&&(!((X=v.metaKeyEvents)===null||X===void 0)&&X.size)){var R;let H=v.metaKeyEvents;v.metaKeyEvents=void 0;for(let Y of H.values())(R=v.target)===null||R===void 0||R.dispatchEvent(new KeyboardEvent("keyup",Y))}};if(typeof PointerEvent<"u"){w.onPointerDown=R=>{if(R.button!==0||!R.currentTarget.contains(R.target))return;if(LCg(R.nativeEvent)){v.pointerType="virtual";return}DF(R.currentTarget)&&R.preventDefault(),v.pointerType=R.pointerType;let H=!0;v.isPressed||(v.isPressed=!0,v.isOverTarget=!0,v.activePointerId=R.pointerId,v.target=R.currentTarget,!r&&!a&&vs(R.currentTarget),A||dce(v.target),H=b(R,v.pointerType),m(Cc(R.currentTarget),"pointermove",S,!1),m(Cc(R.currentTarget),"pointerup",X,!1),m(Cc(R.currentTarget),"pointercancel",W,!1)),H&&R.stopPropagation()},w.onMouseDown=R=>{R.currentTarget.contains(R.target)&&R.button===0&&(DF(R.currentTarget)&&R.preventDefault(),R.stopPropagation())},w.onPointerUp=R=>{!R.currentTarget.contains(R.target)||v.pointerType==="virtual"||R.button===0&&af(R,R.currentTarget)&&y(R,v.pointerType||R.pointerType)};let S=R=>{R.pointerId===v.activePointerId&&(v.target&&af(R,v.target)?!v.isOverTarget&&v.pointerType!=null&&(v.isOverTarget=!0,b(UA(v.target,R),v.pointerType)):v.target&&v.isOverTarget&&v.pointerType!=null&&(v.isOverTarget=!1,p(UA(v.target,R),v.pointerType,!1),B(R)))},X=R=>{R.pointerId===v.activePointerId&&v.isPressed&&R.button===0&&v.target&&(af(R,v.target)&&v.pointerType!=null?p(UA(v.target,R),v.pointerType):v.isOverTarget&&v.pointerType!=null&&p(UA(v.target,R),v.pointerType,!1),v.isPressed=!1,v.isOverTarget=!1,v.activePointerId=null,v.pointerType=null,f(),A||o1(v.target))},W=R=>{Z(R)};w.onDragStart=R=>{R.currentTarget.contains(R.target)&&Z(R)}}else{w.onMouseDown=W=>{if(W.button!==0||!W.currentTarget.contains(W.target))return;if(DF(W.currentTarget)&&W.preventDefault(),v.ignoreEmulatedMouseEvents){W.stopPropagation();return}v.isPressed=!0,v.isOverTarget=!0,v.target=W.currentTarget,v.pointerType=h_(W.nativeEvent)?"virtual":"mouse",!r&&!a&&vs(W.currentTarget),b(W,v.pointerType)&&W.stopPropagation(),m(Cc(W.currentTarget),"mouseup",S,!1)},w.onMouseEnter=W=>{if(!W.currentTarget.contains(W.target))return;let R=!0;v.isPressed&&!v.ignoreEmulatedMouseEvents&&v.pointerType!=null&&(v.isOverTarget=!0,R=b(W,v.pointerType)),R&&W.stopPropagation()},w.onMouseLeave=W=>{if(!W.currentTarget.contains(W.target))return;let R=!0;v.isPressed&&!v.ignoreEmulatedMouseEvents&&v.pointerType!=null&&(v.isOverTarget=!1,R=p(W,v.pointerType,!1),B(W)),R&&W.stopPropagation()},w.onMouseUp=W=>{W.currentTarget.contains(W.target)&&!v.ignoreEmulatedMouseEvents&&W.button===0&&y(W,v.pointerType||"mouse")};let S=W=>{if(W.button===0){if(v.isPressed=!1,f(),v.ignoreEmulatedMouseEvents){v.ignoreEmulatedMouseEvents=!1;return}v.target&&af(W,v.target)&&v.pointerType!=null?p(UA(v.target,W),v.pointerType):v.target&&v.isOverTarget&&v.pointerType!=null&&p(UA(v.target,W),v.pointerType,!1),v.isOverTarget=!1}};w.onTouchStart=W=>{if(!W.currentTarget.contains(W.target))return;let R=grg(W.nativeEvent);if(!R)return;v.activePointerId=R.identifier,v.ignoreEmulatedMouseEvents=!0,v.isOverTarget=!0,v.isPressed=!0,v.target=W.currentTarget,v.pointerType="touch",!r&&!a&&vs(W.currentTarget),A||dce(v.target),b(W,v.pointerType)&&W.stopPropagation(),m(HH(W.currentTarget),"scroll",X,!0)},w.onTouchMove=W=>{if(!W.currentTarget.contains(W.target))return;if(!v.isPressed){W.stopPropagation();return}let R=mce(W.nativeEvent,v.activePointerId),H=!0;R&&af(R,W.currentTarget)?!v.isOverTarget&&v.pointerType!=null&&(v.isOverTarget=!0,H=b(W,v.pointerType)):v.isOverTarget&&v.pointerType!=null&&(v.isOverTarget=!1,H=p(W,v.pointerType,!1),B(W)),H&&W.stopPropagation()},w.onTouchEnd=W=>{if(!W.currentTarget.contains(W.target))return;if(!v.isPressed){W.stopPropagation();return}let R=mce(W.nativeEvent,v.activePointerId),H=!0;R&&af(R,W.currentTarget)&&v.pointerType!=null?(y(W,v.pointerType),H=p(W,v.pointerType)):v.isOverTarget&&v.pointerType!=null&&(H=p(W,v.pointerType,!1)),H&&W.stopPropagation(),v.isPressed=!1,v.activePointerId=null,v.isOverTarget=!1,v.ignoreEmulatedMouseEvents=!0,v.target&&!A&&o1(v.target),f()},w.onTouchCancel=W=>{W.currentTarget.contains(W.target)&&(W.stopPropagation(),v.isPressed&&Z(W))};let X=W=>{v.isPressed&&W.target.contains(v.target)&&Z({currentTarget:v.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})};w.onDragStart=W=>{W.currentTarget.contains(W.target)&&Z(W)}}return w},[m,r,a,f,A,Z,B,p,b,y]);return U.useEffect(()=>()=>{var v;A||o1((v=h.current.target)!==null&&v!==void 0?v:void 0)},[A]),{isPressed:o||u,pressProps:Gi(c,G)}}function i8(e){return e.tagName==="A"&&e.hasAttribute("href")}function xF(e,g){const{key:I,code:i}=e,n=g,C=n.getAttribute("role");return(I==="Enter"||I===" "||I==="Spacebar"||i==="Space")&&!(n instanceof HH(n).HTMLInputElement&&!uHe(n,I)||n instanceof HH(n).HTMLTextAreaElement||n.isContentEditable)&&!((C==="link"||!C&&i8(n))&&I!=="Enter")}function grg(e){const{targetTouches:g}=e;return g.length>0?g[0]:null}function mce(e,g){const I=e.changedTouches;for(let i=0;ig.right||g.left>e.right||e.top>g.bottom||g.top>e.bottom)}function af(e,g){let I=g.getBoundingClientRect(),i=Irg(e);return irg(I,i)}function DF(e){return!(e instanceof HTMLElement)||!e.hasAttribute("draggable")}function fce(e,g){return e instanceof HTMLInputElement?!uHe(e,g):e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!i8(e)}const nrg=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function uHe(e,g){return e.type==="checkbox"||e.type==="radio"?g===" ":nrg.has(e.type)}class Crg{isDefaultPrevented(){return this.nativeEvent.defaultPrevented}preventDefault(){this.defaultPrevented=!0,this.nativeEvent.preventDefault()}stopPropagation(){this.nativeEvent.stopPropagation(),this.isPropagationStopped=()=>!0}isPropagationStopped(){return!1}persist(){}constructor(g,I){this.nativeEvent=I,this.target=I.target,this.currentTarget=I.currentTarget,this.relatedTarget=I.relatedTarget,this.bubbles=I.bubbles,this.cancelable=I.cancelable,this.defaultPrevented=I.defaultPrevented,this.eventPhase=I.eventPhase,this.isTrusted=I.isTrusted,this.timeStamp=I.timeStamp,this.type=g}}function dHe(e){let g=U.useRef({isFocused:!1,observer:null});bi(()=>{const i=g.current;return()=>{i.observer&&(i.observer.disconnect(),i.observer=null)}},[]);let I=ar(i=>{e==null||e(i)});return U.useCallback(i=>{if(i.target instanceof HTMLButtonElement||i.target instanceof HTMLInputElement||i.target instanceof HTMLTextAreaElement||i.target instanceof HTMLSelectElement){g.current.isFocused=!0;let n=i.target,C=r=>{g.current.isFocused=!1,n.disabled&&I(new Crg("blur",r)),g.current.observer&&(g.current.observer.disconnect(),g.current.observer=null)};n.addEventListener("focusout",C,{once:!0}),g.current.observer=new MutationObserver(()=>{if(g.current.isFocused&&n.disabled){var r;(r=g.current.observer)===null||r===void 0||r.disconnect();let o=n===document.activeElement?null:document.activeElement;n.dispatchEvent(new FocusEvent("blur",{relatedTarget:o})),n.dispatchEvent(new FocusEvent("focusout",{bubbles:!0,relatedTarget:o}))}}),g.current.observer.observe(n,{attributes:!0,attributeFilter:["disabled"]})}},[I])}function hHe(e){let{isDisabled:g,onFocus:I,onBlur:i,onFocusChange:n}=e;const C=U.useCallback(a=>{if(a.target===a.currentTarget)return i&&i(a),n&&n(!1),!0},[i,n]),r=dHe(C),o=U.useCallback(a=>{a.target===a.currentTarget&&document.activeElement===a.target&&(I&&I(a),n&&n(!0),r(a))},[n,I,r]);return{focusProps:{onFocus:!g&&(I||n||i)?o:void 0,onBlur:!g&&(i||n)?C:void 0}}}let _s=null,AS=new Set,pce=!1,zh=!1,f_=!1;const rrg={Tab:!0,Escape:!0};function eY(e,g){for(let I of AS)I(e,g)}function org(e){return!(e.metaKey||!Eh()&&e.altKey||e.ctrlKey||e.key==="Control"||e.key==="Shift"||e.key==="Meta")}function bce(e){zh=!0,org(e)&&(_s="keyboard",eY("keyboard",e))}function Af(e){_s="pointer",(e.type==="mousedown"||e.type==="pointerdown")&&(zh=!0,eY("pointer",e))}function arg(e){h_(e)&&(zh=!0,_s="virtual")}function Arg(e){e.target===window||e.target===document||(!zh&&!f_&&(_s="virtual",eY("virtual",e)),zh=!1,f_=!1)}function srg(){zh=!1,f_=!0}function kH(){if(typeof window>"u"||pce)return;let e=HTMLElement.prototype.focus;HTMLElement.prototype.focus=function(){zh=!0,e.apply(this,arguments)},document.addEventListener("keydown",bce,!0),document.addEventListener("keyup",bce,!0),document.addEventListener("click",arg,!0),window.addEventListener("focus",Arg,!0),window.addEventListener("blur",srg,!1),typeof PointerEvent<"u"?(document.addEventListener("pointerdown",Af,!0),document.addEventListener("pointermove",Af,!0),document.addEventListener("pointerup",Af,!0)):(document.addEventListener("mousedown",Af,!0),document.addEventListener("mousemove",Af,!0),document.addEventListener("mouseup",Af,!0)),pce=!0}typeof document<"u"&&(document.readyState!=="loading"?kH():document.addEventListener("DOMContentLoaded",kH));function n8(){return _s!=="pointer"}function p_(){return _s}function lrg(e){_s=e,eY(e,null)}function crg(){kH();let[e,g]=U.useState(_s);return U.useEffect(()=>{let I=()=>{g(_s)};return AS.add(I),()=>{AS.delete(I)}},[]),kw()?null:e}const urg=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function drg(e,g,I){var i;return e=e||(I==null?void 0:I.target)instanceof HTMLInputElement&&!urg.has(I==null||(i=I.target)===null||i===void 0?void 0:i.type)||(I==null?void 0:I.target)instanceof HTMLTextAreaElement||(I==null?void 0:I.target)instanceof HTMLElement&&(I==null?void 0:I.target.isContentEditable),!(e&&g==="keyboard"&&I instanceof KeyboardEvent&&!rrg[I.key])}function hrg(e,g,I){kH(),U.useEffect(()=>{let i=(n,C)=>{drg(!!(I!=null&&I.isTextInput),n,C)&&e(n8())};return AS.add(i),()=>{AS.delete(i)}},g)}function mHe(e){let{isDisabled:g,onBlurWithin:I,onFocusWithin:i,onFocusWithinChange:n}=e,C=U.useRef({isFocusWithin:!1}),r=U.useCallback(s=>{C.current.isFocusWithin&&!s.currentTarget.contains(s.relatedTarget)&&(C.current.isFocusWithin=!1,I&&I(s),n&&n(!1))},[I,n,C]),o=dHe(r),a=U.useCallback(s=>{!C.current.isFocusWithin&&document.activeElement===s.target&&(i&&i(s),n&&n(!0),C.current.isFocusWithin=!0,o(s))},[i,n,o]);return g?{focusWithinProps:{onFocus:void 0,onBlur:void 0}}:{focusWithinProps:{onFocus:a,onBlur:r}}}let YH=!1,FF=0;function b_(){YH=!0,setTimeout(()=>{YH=!1},50)}function yce(e){e.pointerType==="touch"&&b_()}function mrg(){if(!(typeof document>"u"))return typeof PointerEvent<"u"?document.addEventListener("pointerup",yce):document.addEventListener("touchend",b_),FF++,()=>{FF--,!(FF>0)&&(typeof PointerEvent<"u"?document.removeEventListener("pointerup",yce):document.removeEventListener("touchend",b_))}}function C8(e){let{onHoverStart:g,onHoverChange:I,onHoverEnd:i,isDisabled:n}=e,[C,r]=U.useState(!1),o=U.useRef({isHovered:!1,ignoreEmulatedMouseEvents:!1,pointerType:"",target:null}).current;U.useEffect(mrg,[]);let{hoverProps:a,triggerHoverEnd:s}=U.useMemo(()=>{let A=(u,d)=>{if(o.pointerType=d,n||d==="touch"||o.isHovered||!u.currentTarget.contains(u.target))return;o.isHovered=!0;let h=u.currentTarget;o.target=h,g&&g({type:"hoverstart",target:h,pointerType:d}),I&&I(!0),r(!0)},l=(u,d)=>{if(o.pointerType="",o.target=null,d==="touch"||!o.isHovered)return;o.isHovered=!1;let h=u.currentTarget;i&&i({type:"hoverend",target:h,pointerType:d}),I&&I(!1),r(!1)},c={};return typeof PointerEvent<"u"?(c.onPointerEnter=u=>{YH&&u.pointerType==="mouse"||A(u,u.pointerType)},c.onPointerLeave=u=>{!n&&u.currentTarget.contains(u.target)&&l(u,u.pointerType)}):(c.onTouchStart=()=>{o.ignoreEmulatedMouseEvents=!0},c.onMouseEnter=u=>{!o.ignoreEmulatedMouseEvents&&!YH&&A(u,"mouse"),o.ignoreEmulatedMouseEvents=!1},c.onMouseLeave=u=>{!n&&u.currentTarget.contains(u.target)&&l(u,"mouse")}),{hoverProps:c,triggerHoverEnd:l}},[g,I,i,n,o]);return U.useEffect(()=>{n&&s({currentTarget:o.target},o.pointerType)},[n]),{hoverProps:a,isHovered:C}}function Zce(e){if(!e)return;let g=!0;return I=>{let i={...I,preventDefault(){I.preventDefault()},isDefaultPrevented(){return I.isDefaultPrevented()},stopPropagation(){console.error("stopPropagation is now the default behavior for events in React Spectrum. You can use continuePropagation() to revert this behavior.")},continuePropagation(){g=!1}};e(i),g&&I.stopPropagation()}}function frg(e){return{keyboardProps:e.isDisabled?{}:{onKeyDown:Zce(e.onKeyDown),onKeyUp:Zce(e.onKeyUp)}}}const prg=500;function brg(e){let{isDisabled:g,onLongPressStart:I,onLongPressEnd:i,onLongPress:n,threshold:C=prg,accessibilityDescription:r}=e;const o=U.useRef();let{addGlobalListener:a,removeGlobalListener:s}=oHe(),{pressProps:A}=I8({isDisabled:g,onPressStart(c){if(c.continuePropagation(),(c.pointerType==="mouse"||c.pointerType==="touch")&&(I&&I({...c,type:"longpressstart"}),o.current=setTimeout(()=>{c.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),n&&n({...c,type:"longpress"}),o.current=void 0},C),c.pointerType==="touch")){let u=d=>{d.preventDefault()};a(c.target,"contextmenu",u,{once:!0}),a(window,"pointerup",()=>{setTimeout(()=>{s(c.target,"contextmenu",u)},30)},{once:!0})}},onPressEnd(c){o.current&&clearTimeout(o.current),i&&(c.pointerType==="mouse"||c.pointerType==="touch")&&i({...c,type:"longpressend"})}}),l=qk(n&&!g?r:void 0);return{longPressProps:Gi(A,l)}}function gr(e){if(p_()==="virtual"){let g=document.activeElement;rHe(()=>{document.activeElement===g&&document.contains(e)&&vs(e)})}else vs(e)}function yrg(e){if(!(e instanceof HTMLElement)&&!(e instanceof SVGElement))return!1;let{display:g,visibility:I}=e.style,i=g!=="none"&&I!=="hidden"&&I!=="collapse";if(i){const{getComputedStyle:n}=e.ownerDocument.defaultView;let{display:C,visibility:r}=n(e);i=C!=="none"&&r!=="hidden"&&r!=="collapse"}return i}function Zrg(e,g){return!e.hasAttribute("hidden")&&(e.nodeName==="DETAILS"&&g&&g.nodeName!=="SUMMARY"?e.hasAttribute("open"):!0)}function fHe(e,g){return e.nodeName!=="#comment"&&yrg(e)&&Zrg(e,g)&&(!e.parentElement||fHe(e.parentElement,e))}const Gce=N.createContext(null);let mI=null;function Grg(e){let{children:g,contain:I,restoreFocus:i,autoFocus:n}=e,C=U.useRef(null),r=U.useRef(null),o=U.useRef([]),{parentNode:a}=U.useContext(Gce)||{},s=U.useMemo(()=>new Z_({scopeRef:o}),[o]);bi(()=>{let c=a||di.root;if(di.getTreeNode(c.scopeRef)&&mI&&!KH(mI,c.scopeRef)){let u=di.getTreeNode(mI);u&&(c=u)}c.addChild(s),di.addNode(s)},[s,a]),bi(()=>{let c=di.getTreeNode(o);c&&(c.contain=!!I)},[I]),bi(()=>{var c;let u=(c=C.current)===null||c===void 0?void 0:c.nextSibling,d=[];for(;u&&u!==r.current;)d.push(u),u=u.nextSibling;o.current=d},[g]),Rrg(o,i,I),wrg(o,I),Xrg(o,i,I),Vrg(o,n),U.useEffect(()=>{let c=document.activeElement,u=null;if(Yn(c,o.current)){for(let d of di.traverse())d.scopeRef&&Yn(c,d.scopeRef.current)&&(u=d);u===di.getTreeNode(o)&&(mI=u.scopeRef)}},[o]),bi(()=>()=>{var c,u,d;let h=(d=(u=di.getTreeNode(o))===null||u===void 0||(c=u.parent)===null||c===void 0?void 0:c.scopeRef)!==null&&d!==void 0?d:null;(o===mI||KH(o,mI))&&(!h||di.getTreeNode(h))&&(mI=h),di.removeTreeNode(o)},[o]);let A=U.useMemo(()=>vrg(o),[]),l=U.useMemo(()=>({focusManager:A,parentNode:s}),[s,A]);return N.createElement(Gce.Provider,{value:l},N.createElement("span",{"data-focus-scope-start":!0,hidden:!0,ref:C}),g,N.createElement("span",{"data-focus-scope-end":!0,hidden:!0,ref:r}))}function vrg(e){return{focusNext(g={}){let I=e.current,{from:i,tabbable:n,wrap:C,accept:r}=g,o=i||document.activeElement,a=I[0].previousElementSibling,s=yd(I),A=jr(s,{tabbable:n,accept:r},I);A.currentNode=Yn(o,I)?o:a;let l=A.nextNode();return!l&&C&&(A.currentNode=a,l=A.nextNode()),l&&Bs(l,!0),l},focusPrevious(g={}){let I=e.current,{from:i,tabbable:n,wrap:C,accept:r}=g,o=i||document.activeElement,a=I[I.length-1].nextElementSibling,s=yd(I),A=jr(s,{tabbable:n,accept:r},I);A.currentNode=Yn(o,I)?o:a;let l=A.previousNode();return!l&&C&&(A.currentNode=a,l=A.previousNode()),l&&Bs(l,!0),l},focusFirst(g={}){let I=e.current,{tabbable:i,accept:n}=g,C=yd(I),r=jr(C,{tabbable:i,accept:n},I);r.currentNode=I[0].previousElementSibling;let o=r.nextNode();return o&&Bs(o,!0),o},focusLast(g={}){let I=e.current,{tabbable:i,accept:n}=g,C=yd(I),r=jr(C,{tabbable:i,accept:n},I);r.currentNode=I[I.length-1].nextElementSibling;let o=r.previousNode();return o&&Bs(o,!0),o}}}const r8=["input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","a[href]","area[href]","summary","iframe","object","embed","audio[controls]","video[controls]","[contenteditable]"],Brg=r8.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";r8.push('[tabindex]:not([tabindex="-1"]):not([disabled])');const Srg=r8.join(':not([hidden]):not([tabindex="-1"]),');function yd(e){return e[0].parentElement}function yG(e){let g=di.getTreeNode(mI);for(;g&&g.scopeRef!==e;){if(g.contain)return!1;g=g.parent}return!0}function wrg(e,g){let I=U.useRef(),i=U.useRef();bi(()=>{let n=e.current;if(!g){i.current&&(cancelAnimationFrame(i.current),i.current=void 0);return}let C=a=>{if(a.key!=="Tab"||a.altKey||a.ctrlKey||a.metaKey||!yG(e))return;let s=document.activeElement,A=e.current;if(!A||!Yn(s,A))return;let l=yd(A),c=jr(l,{tabbable:!0},A);if(!s)return;c.currentNode=s;let u=a.shiftKey?c.previousNode():c.nextNode();u||(c.currentNode=a.shiftKey?A[A.length-1].nextElementSibling:A[0].previousElementSibling,u=a.shiftKey?c.previousNode():c.nextNode()),a.preventDefault(),u&&Bs(u,!0)},r=a=>{(!mI||KH(mI,e))&&Yn(a.target,e.current)?(mI=e,I.current=a.target):yG(e)&&!y_(a.target,e)?I.current?I.current.focus():mI&&mI.current&&xH(mI.current):yG(e)&&(I.current=a.target)},o=a=>{i.current&&cancelAnimationFrame(i.current),i.current=requestAnimationFrame(()=>{if(document.activeElement&&yG(e)&&!y_(document.activeElement,e))if(mI=e,document.body.contains(a.target)){var s;I.current=a.target,(s=I.current)===null||s===void 0||s.focus()}else mI.current&&xH(mI.current)})};return document.addEventListener("keydown",C,!1),document.addEventListener("focusin",r,!1),n==null||n.forEach(a=>a.addEventListener("focusin",r,!1)),n==null||n.forEach(a=>a.addEventListener("focusout",o,!1)),()=>{document.removeEventListener("keydown",C,!1),document.removeEventListener("focusin",r,!1),n==null||n.forEach(a=>a.removeEventListener("focusin",r,!1)),n==null||n.forEach(a=>a.removeEventListener("focusout",o,!1))}},[e,g]),bi(()=>()=>{i.current&&cancelAnimationFrame(i.current)},[i])}function pHe(e){return y_(e)}function Yn(e,g){return!e||!g?!1:g.some(I=>I.contains(e))}function y_(e,g=null){if(e instanceof Element&&e.closest("[data-react-aria-top-layer]"))return!0;for(let{scopeRef:I}of di.traverse(di.getTreeNode(g)))if(I&&Yn(e,I.current))return!0;return!1}function KH(e,g){var I;let i=(I=di.getTreeNode(g))===null||I===void 0?void 0:I.parent;for(;i;){if(i.scopeRef===e)return!0;i=i.parent}return!1}function Bs(e,g=!1){if(e!=null&&!g)try{gr(e)}catch{}else if(e!=null)try{e.focus()}catch{}}function xH(e,g=!0){let I=e[0].previousElementSibling,i=yd(e),n=jr(i,{tabbable:g},e);n.currentNode=I;let C=n.nextNode();g&&!C&&(i=yd(e),n=jr(i,{tabbable:!1},e),n.currentNode=I,C=n.nextNode()),Bs(C)}function Vrg(e,g){const I=N.useRef(g);U.useEffect(()=>{I.current&&(mI=e,!Yn(document.activeElement,mI.current)&&e.current&&xH(e.current)),I.current=!1},[e])}function Rrg(e,g,I){bi(()=>{if(g||I)return;let i=e.current,n=C=>{let r=C.target;Yn(r,e.current)?mI=e:pHe(r)||(mI=null)};return document.addEventListener("focusin",n,!1),i==null||i.forEach(C=>C.addEventListener("focusin",n,!1)),()=>{document.removeEventListener("focusin",n,!1),i==null||i.forEach(C=>C.removeEventListener("focusin",n,!1))}},[e,g,I])}function Wrg(e){let g=di.getTreeNode(mI);for(;g&&g.scopeRef!==e;){if(g.nodeToRestore)return!1;g=g.parent}return(g==null?void 0:g.scopeRef)===e}function Xrg(e,g,I){const i=U.useRef(typeof document<"u"?document.activeElement:null);bi(()=>{let n=e.current;if(!g||I)return;let C=()=>{(!mI||KH(mI,e))&&Yn(document.activeElement,e.current)&&(mI=e)};return document.addEventListener("focusin",C,!1),n==null||n.forEach(r=>r.addEventListener("focusin",C,!1)),()=>{document.removeEventListener("focusin",C,!1),n==null||n.forEach(r=>r.removeEventListener("focusin",C,!1))}},[e,I]),bi(()=>{if(!g)return;let n=C=>{if(C.key!=="Tab"||C.altKey||C.ctrlKey||C.metaKey||!yG(e))return;let r=document.activeElement;if(!Yn(r,e.current))return;let o=di.getTreeNode(e);if(!o)return;let a=o.nodeToRestore,s=jr(document.body,{tabbable:!0});s.currentNode=r;let A=C.shiftKey?s.previousNode():s.nextNode();if((!a||!document.body.contains(a)||a===document.body)&&(a=void 0,o.nodeToRestore=void 0),(!A||!Yn(A,e.current))&&a){s.currentNode=a;do A=C.shiftKey?s.previousNode():s.nextNode();while(Yn(A,e.current));C.preventDefault(),C.stopPropagation(),A?Bs(A,!0):pHe(a)?Bs(a,!0):r.blur()}};return I||document.addEventListener("keydown",n,!0),()=>{I||document.removeEventListener("keydown",n,!0)}},[e,g,I]),bi(()=>{if(!g)return;let n=di.getTreeNode(e);if(n){var C;return n.nodeToRestore=(C=i.current)!==null&&C!==void 0?C:void 0,()=>{let r=di.getTreeNode(e);if(!r)return;let o=r.nodeToRestore;if(g&&o&&(Yn(document.activeElement,e.current)||document.activeElement===document.body&&Wrg(e))){let a=di.clone();requestAnimationFrame(()=>{if(document.activeElement===document.body){let s=a.getTreeNode(e);for(;s;){if(s.nodeToRestore&&document.body.contains(s.nodeToRestore)){Bs(s.nodeToRestore);return}s=s.parent}for(s=a.getTreeNode(e);s;){if(s.scopeRef&&s.scopeRef.current&&di.getTreeNode(s.scopeRef)){xH(s.scopeRef.current,!0);return}s=s.parent}}})}}}},[e,g])}function jr(e,g,I){let i=g!=null&&g.tabbable?Srg:Brg,n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode(C){var r;return!(g==null||(r=g.from)===null||r===void 0)&&r.contains(C)?NodeFilter.FILTER_REJECT:C.matches(i)&&fHe(C)&&(!I||Yn(C,I))&&(!(g!=null&&g.accept)||g.accept(C))?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});return g!=null&&g.from&&(n.currentNode=g.from),n}class o8{get size(){return this.fastMap.size}getTreeNode(g){return this.fastMap.get(g)}addTreeNode(g,I,i){let n=this.fastMap.get(I??null);if(!n)return;let C=new Z_({scopeRef:g});n.addChild(C),C.parent=n,this.fastMap.set(g,C),i&&(C.nodeToRestore=i)}addNode(g){this.fastMap.set(g.scopeRef,g)}removeTreeNode(g){if(g===null)return;let I=this.fastMap.get(g);if(!I)return;let i=I.parent;for(let C of this.traverse())C!==I&&I.nodeToRestore&&C.nodeToRestore&&I.scopeRef&&I.scopeRef.current&&Yn(C.nodeToRestore,I.scopeRef.current)&&(C.nodeToRestore=I.nodeToRestore);let n=I.children;i&&(i.removeChild(I),n.size>0&&n.forEach(C=>i&&i.addChild(C))),this.fastMap.delete(I.scopeRef)}*traverse(g=this.root){if(g.scopeRef!=null&&(yield g),g.children.size>0)for(let I of g.children)yield*this.traverse(I)}clone(){var g;let I=new o8;var i;for(let n of this.traverse())I.addTreeNode(n.scopeRef,(i=(g=n.parent)===null||g===void 0?void 0:g.scopeRef)!==null&&i!==void 0?i:null,n.nodeToRestore);return I}constructor(){this.fastMap=new Map,this.root=new Z_({scopeRef:null}),this.fastMap.set(null,this.root)}}class Z_{addChild(g){this.children.add(g),g.parent=this}removeChild(g){this.children.delete(g),g.parent=void 0}constructor(g){this.children=new Set,this.contain=!1,this.scopeRef=g.scopeRef}}let di=new o8;function tY(e={}){let{autoFocus:g=!1,isTextInput:I,within:i}=e,n=U.useRef({isFocused:!1,isFocusVisible:g||n8()}),[C,r]=U.useState(!1),[o,a]=U.useState(()=>n.current.isFocused&&n.current.isFocusVisible),s=U.useCallback(()=>a(n.current.isFocused&&n.current.isFocusVisible),[]),A=U.useCallback(u=>{n.current.isFocused=u,r(u),s()},[s]);hrg(u=>{n.current.isFocusVisible=u,s()},[],{isTextInput:I});let{focusProps:l}=hHe({isDisabled:i,onFocusChange:A}),{focusWithinProps:c}=mHe({isDisabled:!i,onFocusWithinChange:A});return{isFocused:C,isFocusVisible:o,focusProps:i?c:l}}let Hrg=N.createContext(null);function Trg(e){let g=U.useContext(Hrg)||{};AHe(g,e);let{ref:I,...i}=g;return i}function bHe(e,g){let{focusProps:I}=hHe(e),{keyboardProps:i}=frg(e),n=Gi(I,i),C=Trg(g),r=e.isDisabled?{}:C,o=U.useRef(e.autoFocus);return U.useEffect(()=>{o.current&&g.current&&gr(g.current),o.current=!1},[g]),{focusableProps:Gi({...n,tabIndex:e.excludeFromTabOrder&&!e.isDisabled?-1:void 0},r)}}function Nrg(e,g){let I=g==null?void 0:g.isDisabled,[i,n]=U.useState(!1);return bi(()=>{if(e!=null&&e.current&&!I){let C=()=>{if(e.current){let o=jr(e.current,{tabbable:!0});n(!!o.nextNode())}};C();let r=new MutationObserver(C);return r.observe(e.current,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["tabIndex","disabled"]}),()=>{r.disconnect()}}}),I?!1:i}class krg{getStringForLocale(g,I){let i=this.strings[I];i||(i=Yrg(I,this.strings,this.defaultLocale),this.strings[I]=i);let n=i[g];if(!n)throw new Error(`Could not find intl message ${g} in ${I} locale`);return n}constructor(g,I="en-US"){this.strings={...g},this.defaultLocale=I}}function Yrg(e,g,I="en-US"){if(g[e])return g[e];let i=Krg(e);if(g[i])return g[i];for(let n in g)if(n.startsWith(i+"-"))return g[n];return g[I]}function Krg(e){return Intl.Locale?new Intl.Locale(e).language:e.split("-")[0]}const vce=new Map,Bce=new Map;class xrg{format(g,I){let i=this.strings.getStringForLocale(g,this.locale);return typeof i=="function"?i(I,this):i}plural(g,I,i="cardinal"){let n=I["="+g];if(n)return typeof n=="function"?n():n;let C=this.locale+":"+i,r=vce.get(C);r||(r=new Intl.PluralRules(this.locale,{type:i}),vce.set(C,r));let o=r.select(g);return n=I[o]||I.other,typeof n=="function"?n():n}number(g){let I=Bce.get(this.locale);return I||(I=new Intl.NumberFormat(this.locale),Bce.set(this.locale,I)),I.format(g)}select(g,I){let i=g[I]||g.other;return typeof i=="function"?i():i}constructor(g,I){this.locale=g,this.strings=I}}const Drg=new Set(["Arab","Syrc","Samr","Mand","Thaa","Mend","Nkoo","Adlm","Rohg","Hebr"]),Frg=new Set(["ae","ar","arc","bcc","bqi","ckb","dv","fa","glk","he","ku","mzn","nqo","pnb","ps","sd","ug","ur","yi"]);function Erg(e){if(Intl.Locale){let I=new Intl.Locale(e).maximize().script;return I?Drg.has(I):!1}let g=e.split("-")[0];return Frg.has(g)}function yHe(){let e=typeof navigator<"u"&&(navigator.language||navigator.userLanguage)||"en-US";try{Intl.DateTimeFormat.supportedLocalesOf([e])}catch{e="en-US"}return{locale:e,direction:Erg(e)?"rtl":"ltr"}}let G_=yHe(),ZG=new Set;function Sce(){G_=yHe();for(let e of ZG)e(G_)}function Mrg(){let e=kw(),[g,I]=U.useState(G_);return U.useEffect(()=>(ZG.size===0&&window.addEventListener("languagechange",Sce),ZG.add(I),()=>{ZG.delete(I),ZG.size===0&&window.removeEventListener("languagechange",Sce)}),[]),e?{locale:"en-US",direction:"ltr"}:g}const zrg=N.createContext(null);function vm(){let e=Mrg();return U.useContext(zrg)||e}const wce=new WeakMap;function Prg(e){let g=wce.get(e);return g||(g=new krg(e),wce.set(e,g)),g}function hy(e){let{locale:g}=vm(),I=U.useMemo(()=>Prg(e),[e]);return U.useMemo(()=>new xrg(g,I),[g,I])}let EF=new Map;function ZHe(e){let{locale:g}=vm(),I=g+(e?Object.entries(e).sort((n,C)=>n[0]{n.remove()},i)}clear(g){this.node&&((!g||g==="assertive")&&(this.assertiveLog.innerHTML=""),(!g||g==="polite")&&(this.politeLog.innerHTML=""))}constructor(){this.node=document.createElement("div"),this.node.dataset.liveAnnouncer="true",Object.assign(this.node.style,{border:0,clip:"rect(0 0 0 0)",clipPath:"inset(50%)",height:"1px",margin:"-1px",overflow:"hidden",padding:0,position:"absolute",width:"1px",whiteSpace:"nowrap"}),this.assertiveLog=this.createLog("assertive"),this.node.appendChild(this.assertiveLog),this.politeLog=this.createLog("polite"),this.node.appendChild(this.politeLog),document.body.prepend(this.node)}}function Org(e,g,I){let{validationBehavior:i,focus:n}=e;bi(()=>{if(i==="native"&&(I!=null&&I.current)){let a=g.realtimeValidation.isInvalid?g.realtimeValidation.validationErrors.join(" ")||"Invalid value.":"";I.current.setCustomValidity(a),I.current.hasAttribute("title")||(I.current.title=""),g.realtimeValidation.isInvalid||g.updateValidation(Lrg(I.current))}});let C=ar(()=>{g.resetValidation()}),r=ar(a=>{var s;g.displayValidation.isInvalid||g.commitValidation();let A=I==null||(s=I.current)===null||s===void 0?void 0:s.form;if(!a.defaultPrevented&&I&&A&&Urg(A)===I.current){var l;n?n():(l=I.current)===null||l===void 0||l.focus(),lrg("keyboard")}a.preventDefault()}),o=ar(()=>{g.commitValidation()});U.useEffect(()=>{let a=I==null?void 0:I.current;if(!a)return;let s=a.form;return a.addEventListener("invalid",r),a.addEventListener("change",o),s==null||s.addEventListener("reset",C),()=>{a.removeEventListener("invalid",r),a.removeEventListener("change",o),s==null||s.removeEventListener("reset",C)}},[I,r,o,C,i])}function _rg(e){let g=e.validity;return{badInput:g.badInput,customError:g.customError,patternMismatch:g.patternMismatch,rangeOverflow:g.rangeOverflow,rangeUnderflow:g.rangeUnderflow,stepMismatch:g.stepMismatch,tooLong:g.tooLong,tooShort:g.tooShort,typeMismatch:g.typeMismatch,valueMissing:g.valueMissing,valid:g.valid}}function Lrg(e){return{isInvalid:!e.validity.valid,validationDetails:_rg(e),validationErrors:e.validationMessage?[e.validationMessage]:[]}}function Urg(e){for(let g=0;gRce(qrg(r,n)),[r,n]);C!=null&&C.validationDetails.valid&&(C=null);let A=U.useContext(Qrg),l=U.useMemo(()=>i?Array.isArray(i)?i.flatMap(V=>v_(A[V])):v_(A[i]):[],[A,i]),[c,u]=U.useState(A),[d,h]=U.useState(!1);A!==c&&(u(A),h(!1));let m=U.useMemo(()=>Rce(d?[]:l),[d,l]),f=U.useRef(GZ),[b,p]=U.useState(GZ),y=U.useRef(GZ),Z=()=>{if(!B)return;G(!1);let V=s||C||f.current;zF(V,y.current)||(y.current=V,p(V))},[B,G]=U.useState(!1);return U.useEffect(Z),{realtimeValidation:a||m||s||C||GZ,displayValidation:o==="native"?a||m||b:a||m||s||C||b,updateValidation(V){o==="aria"&&!zF(b,V)?p(V):f.current=V},resetValidation(){let V=GZ;zF(V,y.current)||(y.current=V,p(V)),o==="native"&&G(!1),h(!0)},commitValidation(){o==="native"&&G(!0),h(!0)}}}function v_(e){return e?Array.isArray(e)?e:[e]:[]}function qrg(e,g){if(typeof e=="function"){let I=e(g);if(I&&typeof I!="boolean")return v_(I)}return[]}function Rce(e){return e.length?{isInvalid:!0,validationErrors:e,validationDetails:SHe}:null}function zF(e,g){return e===g?!0:e&&g&&e.isInvalid===g.isInvalid&&e.validationErrors.length===g.validationErrors.length&&e.validationErrors.every((I,i)=>I===g.validationErrors[i])&&Object.entries(e.validationDetails).every(([I,i])=>g.validationDetails[I]===i)}function eog(e){let{id:g,label:I,"aria-labelledby":i,"aria-label":n,labelElementType:C="label"}=e;g=Fh(g);let r=Fh(),o={};I?(i=i?`${r} ${i}`:r,o={id:r,htmlFor:C==="label"?g:void 0}):!i&&!n&&console.warn("If you do not provide a visible label, you must specify an aria-label or aria-labelledby attribute for accessibility");let a=JCg({id:g,"aria-label":n,"aria-labelledby":i});return{labelProps:o,fieldProps:a}}function tog(e){let{description:g,errorMessage:I,isInvalid:i,validationState:n}=e,{labelProps:C,fieldProps:r}=eog(e),o=sce([!!g,!!I,i,n]),a=sce([!!g,!!I,i,n]);return r=Gi(r,{"aria-describedby":[o,a,e["aria-describedby"]].filter(Boolean).join(" ")||void 0}),{labelProps:C,fieldProps:r,descriptionProps:{id:o},errorMessageProps:{id:a}}}const Wce={border:0,clip:"rect(0 0 0 0)",clipPath:"inset(50%)",height:"1px",margin:"-1px",overflow:"hidden",padding:0,position:"absolute",width:"1px",whiteSpace:"nowrap"};function a8(e={}){let{style:g,isFocusable:I}=e,[i,n]=U.useState(!1),{focusWithinProps:C}=mHe({isDisabled:!I,onFocusWithinChange:o=>n(o)}),r=U.useMemo(()=>i?g:g?{...Wce,...g}:Wce,[i]);return{visuallyHiddenProps:{...C,style:r}}}function B_(e){return KCg()?e.altKey:e.ctrlKey}function Ef(e){return Eh()?e.metaKey:e.ctrlKey}const gog=1e3;function Iog(e){let{keyboardDelegate:g,selectionManager:I,onTypeSelect:i}=e,n=U.useRef({search:"",timeout:null}).current,C=r=>{let o=iog(r.key);if(!o||r.ctrlKey||r.metaKey||!r.currentTarget.contains(r.target))return;o===" "&&n.search.trim().length>0&&(r.preventDefault(),"continuePropagation"in r||r.stopPropagation()),n.search+=o;let a=g.getKeyForSearch(n.search,I.focusedKey);a==null&&(a=g.getKeyForSearch(n.search)),a!=null&&(I.setFocusedKey(a),i&&i(a)),clearTimeout(n.timeout),n.timeout=setTimeout(()=>{n.search=""},gog)};return{typeSelectProps:{onKeyDownCapture:g.getKeyForSearch?C:null}}}function iog(e){return e.length===1||!/^[A-Z]/i.test(e)?e:""}function nog(e){let{selectionManager:g,keyboardDelegate:I,ref:i,autoFocus:n=!1,shouldFocusWrap:C=!1,disallowEmptySelection:r=!1,disallowSelectAll:o=!1,selectOnFocus:a=g.selectionBehavior==="replace",disallowTypeAhead:s=!1,shouldUseVirtualFocus:A,allowsTabNavigation:l=!1,isVirtualized:c,scrollRef:u=i,linkBehavior:d="action"}=e,{direction:h}=vm(),m=CHe(),f=V=>{if(V.altKey&&V.key==="Tab"&&V.preventDefault(),!i.current.contains(V.target))return;const S=(P,ge)=>{if(P!=null){if(g.isLink(P)&&d==="selection"&&a&&!B_(V)){Aa.flushSync(()=>{g.setFocusedKey(P,ge)});let q=u.current.querySelector(`[data-key="${P}"]`);m.open(q,V);return}if(g.setFocusedKey(P,ge),g.isLink(P)&&d==="override")return;V.shiftKey&&g.selectionMode==="multiple"?g.extendSelection(P):a&&!B_(V)&&g.replaceSelection(P)}};switch(V.key){case"ArrowDown":if(I.getKeyBelow){var X,W;V.preventDefault();let P=g.focusedKey!=null?I.getKeyBelow(g.focusedKey):(X=I.getFirstKey)===null||X===void 0?void 0:X.call(I);P==null&&C&&(P=(W=I.getFirstKey)===null||W===void 0?void 0:W.call(I,g.focusedKey)),S(P)}break;case"ArrowUp":if(I.getKeyAbove){var R,H;V.preventDefault();let P=g.focusedKey!=null?I.getKeyAbove(g.focusedKey):(R=I.getLastKey)===null||R===void 0?void 0:R.call(I);P==null&&C&&(P=(H=I.getLastKey)===null||H===void 0?void 0:H.call(I,g.focusedKey)),S(P)}break;case"ArrowLeft":if(I.getKeyLeftOf){var Y,K;V.preventDefault();let P=I.getKeyLeftOf(g.focusedKey);P==null&&C&&(P=h==="rtl"?(Y=I.getFirstKey)===null||Y===void 0?void 0:Y.call(I,g.focusedKey):(K=I.getLastKey)===null||K===void 0?void 0:K.call(I,g.focusedKey)),S(P,h==="rtl"?"first":"last")}break;case"ArrowRight":if(I.getKeyRightOf){var F,J;V.preventDefault();let P=I.getKeyRightOf(g.focusedKey);P==null&&C&&(P=h==="rtl"?(F=I.getLastKey)===null||F===void 0?void 0:F.call(I,g.focusedKey):(J=I.getFirstKey)===null||J===void 0?void 0:J.call(I,g.focusedKey)),S(P,h==="rtl"?"last":"first")}break;case"Home":if(I.getFirstKey){V.preventDefault();let P=I.getFirstKey(g.focusedKey,Ef(V));g.setFocusedKey(P),Ef(V)&&V.shiftKey&&g.selectionMode==="multiple"?g.extendSelection(P):a&&g.replaceSelection(P)}break;case"End":if(I.getLastKey){V.preventDefault();let P=I.getLastKey(g.focusedKey,Ef(V));g.setFocusedKey(P),Ef(V)&&V.shiftKey&&g.selectionMode==="multiple"?g.extendSelection(P):a&&g.replaceSelection(P)}break;case"PageDown":if(I.getKeyPageBelow){V.preventDefault();let P=I.getKeyPageBelow(g.focusedKey);S(P)}break;case"PageUp":if(I.getKeyPageAbove){V.preventDefault();let P=I.getKeyPageAbove(g.focusedKey);S(P)}break;case"a":Ef(V)&&g.selectionMode==="multiple"&&o!==!0&&(V.preventDefault(),g.selectAll());break;case"Escape":V.preventDefault(),r||g.clearSelection();break;case"Tab":if(!l){if(V.shiftKey)i.current.focus();else{let P=jr(i.current,{tabbable:!0}),ge,q;do q=P.lastChild(),q&&(ge=q);while(q);ge&&!ge.contains(document.activeElement)&&vs(ge)}break}}},b=U.useRef({top:0,left:0});_Cg(u,"scroll",c?null:()=>{b.current={top:u.current.scrollTop,left:u.current.scrollLeft}});let p=V=>{if(g.isFocused){V.currentTarget.contains(V.target)||g.setFocused(!1);return}if(V.currentTarget.contains(V.target)){if(g.setFocused(!0),g.focusedKey==null){let W=H=>{H!=null&&(g.setFocusedKey(H),a&&g.replaceSelection(H))},R=V.relatedTarget;var S,X;R&&V.currentTarget.compareDocumentPosition(R)&Node.DOCUMENT_POSITION_FOLLOWING?W((S=g.lastSelectedKey)!==null&&S!==void 0?S:I.getLastKey()):W((X=g.firstSelectedKey)!==null&&X!==void 0?X:I.getFirstKey())}else c||(u.current.scrollTop=b.current.top,u.current.scrollLeft=b.current.left);if(!c&&g.focusedKey!=null){let W=u.current.querySelector(`[data-key="${g.focusedKey}"]`);W&&(W.contains(document.activeElement)||vs(W),p_()==="keyboard"&&Ll(W,{containingElement:i.current}))}}},y=V=>{V.currentTarget.contains(V.relatedTarget)||g.setFocused(!1)};const Z=U.useRef(n);U.useEffect(()=>{if(Z.current){let V=null;n==="first"&&(V=I.getFirstKey()),n==="last"&&(V=I.getLastKey());let S=g.selectedKeys;S.size&&(V=S.values().next().value),g.setFocused(!0),g.setFocusedKey(V),V==null&&!A&&gr(i.current)}Z.current=!1},[]);let B=U.useRef(g.focusedKey);U.useEffect(()=>{let V=p_();if(g.isFocused&&g.focusedKey!=null&&(u!=null&&u.current)){let S=u.current.querySelector(`[data-key="${g.focusedKey}"]`);S&&V==="keyboard"&&(c||sHe(u.current,S),Ll(S,{containingElement:i.current}))}g.isFocused&&g.focusedKey==null&&B.current!=null&&gr(i.current),B.current=g.focusedKey},[c,u,g.focusedKey,g.isFocused,i]);let G={onKeyDown:f,onFocus:p,onBlur:y,onMouseDown(V){u.current===V.target&&V.preventDefault()}},{typeSelectProps:v}=Iog({keyboardDelegate:I,selectionManager:g});s||(G=Gi(v,G));let w;return A||(w=g.focusedKey==null?0:-1),{collectionProps:{...G,tabIndex:w}}}function wHe(e){let{selectionManager:g,key:I,ref:i,shouldSelectOnPressUp:n,shouldUseVirtualFocus:C,focus:r,isDisabled:o,onAction:a,allowsDifferentPressOrigin:s,linkBehavior:A="action"}=e,l=CHe(),c=K=>{if(K.pointerType==="keyboard"&&B_(K))g.toggleSelection(I);else{if(g.selectionMode==="none")return;if(g.isLink(I)){if(A==="selection"){l.open(i.current,K),g.setSelectedKeys(g.selectedKeys);return}else if(A==="override"||A==="none")return}g.selectionMode==="single"?g.isSelected(I)&&!g.disallowEmptySelection?g.toggleSelection(I):g.replaceSelection(I):K&&K.shiftKey?g.extendSelection(I):g.selectionBehavior==="toggle"||K&&(Ef(K)||K.pointerType==="touch"||K.pointerType==="virtual")?g.toggleSelection(I):g.replaceSelection(I)}};U.useEffect(()=>{I===g.focusedKey&&g.isFocused&&!C&&(r?r():document.activeElement!==i.current&&gr(i.current))},[i,I,g.focusedKey,g.childFocusStrategy,g.isFocused,C]),o=o||g.isDisabled(I);let u={};!C&&!o?u={tabIndex:I===g.focusedKey?0:-1,onFocus(K){K.target===i.current&&g.setFocusedKey(I)}}:o&&(u.onMouseDown=K=>{K.preventDefault()});let d=g.isLink(I)&&A==="override",h=g.isLink(I)&&A!=="selection"&&A!=="none",m=!o&&g.canSelectItem(I)&&!d,f=(a||h)&&!o,b=f&&(g.selectionBehavior==="replace"?!m:!m||g.isEmpty),p=f&&m&&g.selectionBehavior==="replace",y=b||p,Z=U.useRef(null),B=y&&m,G=U.useRef(!1),v=U.useRef(!1),w=K=>{a&&a(),h&&l.open(i.current,K)},V={};n?(V.onPressStart=K=>{Z.current=K.pointerType,G.current=B,K.pointerType==="keyboard"&&(!y||Hce())&&c(K)},s?(V.onPressUp=b?null:K=>{K.pointerType!=="keyboard"&&m&&c(K)},V.onPress=b?w:null):V.onPress=K=>{if(b||p&&K.pointerType!=="mouse"){if(K.pointerType==="keyboard"&&!Xce())return;w(K)}else K.pointerType!=="keyboard"&&m&&c(K)}):(V.onPressStart=K=>{Z.current=K.pointerType,G.current=B,v.current=b,m&&(K.pointerType==="mouse"&&!b||K.pointerType==="keyboard"&&(!f||Hce()))&&c(K)},V.onPress=K=>{(K.pointerType==="touch"||K.pointerType==="pen"||K.pointerType==="virtual"||K.pointerType==="keyboard"&&y&&Xce()||K.pointerType==="mouse"&&v.current)&&(y?w(K):m&&c(K))}),u["data-key"]=I,V.preventFocusOnPress=C;let{pressProps:S,isPressed:X}=I8(V),W=p?K=>{Z.current==="mouse"&&(K.stopPropagation(),K.preventDefault(),w(K))}:void 0,{longPressProps:R}=brg({isDisabled:!B,onLongPress(K){K.pointerType==="touch"&&(c(K),g.setSelectionBehavior("toggle"))}}),H=K=>{Z.current==="touch"&&G.current&&K.preventDefault()},Y=g.isLink(I)?K=>{Mh.isOpening||K.preventDefault()}:void 0;return{itemProps:Gi(u,m||b?S:{},B?R:{},{onDoubleClick:W,onDragStartCapture:H,onClick:Y}),isPressed:X,isSelected:g.isSelected(I),isFocused:g.isFocused&&g.focusedKey===I,isDisabled:o,allowsSelection:m,hasAction:y}}function Xce(){let e=window.event;return(e==null?void 0:e.key)==="Enter"}function Hce(){let e=window.event;return(e==null?void 0:e.key)===" "||(e==null?void 0:e.code)==="Space"}class Cog{getNextKey(g){for(g=this.collection.getKeyAfter(g);g!=null;){if(this.collection.getItem(g).type==="item"&&!this.disabledKeys.has(g))return g;g=this.collection.getKeyAfter(g)}return null}getPreviousKey(g){for(g=this.collection.getKeyBefore(g);g!=null;){if(this.collection.getItem(g).type==="item"&&!this.disabledKeys.has(g))return g;g=this.collection.getKeyBefore(g)}return null}findKey(g,I,i){let n=this.getItem(g);if(!n)return null;let C=n.getBoundingClientRect();do g=I(g),n=this.getItem(g);while(n&&i(C,n.getBoundingClientRect()));return g}isSameRow(g,I){return g.top===I.top||g.left!==I.left}isSameColumn(g,I){return g.left===I.left||g.top!==I.top}getKeyBelow(g){return this.layout==="grid"&&this.orientation==="vertical"?this.findKey(g,I=>this.getNextKey(I),this.isSameRow):this.getNextKey(g)}getKeyAbove(g){return this.layout==="grid"&&this.orientation==="vertical"?this.findKey(g,I=>this.getPreviousKey(I),this.isSameRow):this.getPreviousKey(g)}getNextColumn(g,I){return I?this.getPreviousKey(g):this.getNextKey(g)}getKeyRightOf(g){return this.layout==="grid"?this.orientation==="vertical"?this.getNextColumn(g,this.direction==="rtl"):this.findKey(g,I=>this.getNextColumn(I,this.direction==="rtl"),this.isSameColumn):this.orientation==="horizontal"?this.getNextColumn(g,this.direction==="rtl"):null}getKeyLeftOf(g){return this.layout==="grid"?this.orientation==="vertical"?this.getNextColumn(g,this.direction==="ltr"):this.findKey(g,I=>this.getNextColumn(I,this.direction==="ltr"),this.isSameColumn):this.orientation==="horizontal"?this.getNextColumn(g,this.direction==="ltr"):null}getFirstKey(){let g=this.collection.getFirstKey();for(;g!=null;){if(this.collection.getItem(g).type==="item"&&!this.disabledKeys.has(g))return g;g=this.collection.getKeyAfter(g)}return null}getLastKey(){let g=this.collection.getLastKey();for(;g!=null;){if(this.collection.getItem(g).type==="item"&&!this.disabledKeys.has(g))return g;g=this.collection.getKeyBefore(g)}return null}getItem(g){return this.ref.current.querySelector(`[data-key="${g}"]`)}getKeyPageAbove(g){let I=this.ref.current,i=this.getItem(g);if(!i)return null;if(!NH(I))return this.getFirstKey();let n=I.getBoundingClientRect(),C=i.getBoundingClientRect();if(this.orientation==="horizontal"){let r=n.x-I.scrollLeft,o=Math.max(0,C.x-r+C.width-n.width);for(;i&&C.x-r>o;)g=this.getKeyAbove(g),i=g==null?null:this.getItem(g),C=i==null?void 0:i.getBoundingClientRect()}else{let r=n.y-I.scrollTop,o=Math.max(0,C.y-r+C.height-n.height);for(;i&&C.y-r>o;)g=this.getKeyAbove(g),i=g==null?null:this.getItem(g),C=i==null?void 0:i.getBoundingClientRect()}return g??this.getFirstKey()}getKeyPageBelow(g){let I=this.ref.current,i=this.getItem(g);if(!i)return null;if(!NH(I))return this.getLastKey();let n=I.getBoundingClientRect(),C=i.getBoundingClientRect();if(this.orientation==="horizontal"){let r=n.x-I.scrollLeft,o=Math.min(I.scrollWidth,C.x-r-C.width+n.width);for(;i&&C.x-rthis.iterateCollection(g))}*iterateCollection(g){let{children:I,items:i}=g;if(typeof I=="function"){if(!i)throw new Error("props.children was a function but props.items is missing");for(let n of g.items)yield*this.getFullNode({value:n},{renderer:I})}else{let n=[];N.Children.forEach(I,r=>{n.push(r)});let C=0;for(let r of n){let o=this.getFullNode({element:r,index:C},{});for(let a of o)C++,yield a}}}getKey(g,I,i,n){if(g.key!=null)return g.key;if(I.type==="cell"&&I.key!=null)return`${n}${I.key}`;let C=I.value;if(C!=null){var r;let o=(r=C.key)!==null&&r!==void 0?r:C.id;if(o==null)throw new Error("No key found for item");return o}return n?`${n}.${I.index}`:`$.${I.index}`}getChildState(g,I){return{renderer:I.renderer||g.renderer}}*getFullNode(g,I,i,n){let C=g.element;if(!C&&g.value&&I&&I.renderer){let a=this.cache.get(g.value);if(a&&(!a.shouldInvalidate||!a.shouldInvalidate(this.context))){a.index=g.index,a.parentKey=n?n.key:null,yield a;return}C=I.renderer(g.value)}if(N.isValidElement(C)){let a=C.type;if(typeof a!="function"&&typeof a.getCollectionNode!="function"){let c=typeof C.type=="function"?C.type.name:C.type;throw new Error(`Unknown element <${c}> in collection.`)}let s=a.getCollectionNode(C.props,this.context),A=g.index,l=s.next();for(;!l.done&&l.value;){let c=l.value;g.index=A;let u=c.key;u||(u=c.element?null:this.getKey(C,g,I,i));let h=[...this.getFullNode({...c,key:u,index:A,wrapper:oog(g.wrapper,c.wrapper)},this.getChildState(I,c),i?`${i}${C.key}`:C.key,n)];for(let m of h){if(m.value=c.value||g.value,m.value&&this.cache.set(m.value,m),g.type&&m.type!==g.type)throw new Error(`Unsupported type <${PF(m.type)}> in <${PF(n.type)}>. Only <${PF(g.type)}> is supported.`);A++,yield m}l=s.next(h)}return}if(g.key==null)return;let r=this,o={type:g.type,props:g.props,key:g.key,parentKey:n?n.key:null,value:g.value,level:n?n.level+1:0,index:g.index,rendered:g.rendered,textValue:g.textValue,"aria-label":g["aria-label"],wrapper:g.wrapper,shouldInvalidate:g.shouldInvalidate,hasChildNodes:g.hasChildNodes,childNodes:Tce(function*(){if(!g.hasChildNodes)return;let a=0;for(let s of g.childNodes()){s.key!=null&&(s.key=`${o.key}${s.key}`),s.index=a;let A=r.getFullNode(s,r.getChildState(I,s),o.key,o);for(let l of A)a++,yield l}})};yield o}constructor(){this.cache=new WeakMap}}function Tce(e){let g=[],I=null;return{*[Symbol.iterator](){for(let i of g)yield i;I||(I=e());for(let i of I)g.push(i),yield i}}}function oog(e,g){if(e&&g)return I=>e(g(I));if(e)return e;if(g)return g}function PF(e){return e[0].toUpperCase()+e.slice(1)}function aog(e,g,I){let i=U.useMemo(()=>new rog,[]),{children:n,items:C,collection:r}=e;return U.useMemo(()=>{if(r)return r;let a=i.build({children:n,items:C},I);return g(a)},[i,n,C,r,I,g])}function wi(e,g){return typeof g.getChildren=="function"?g.getChildren(e.key):e.childNodes}function As(e){return Ul(e,0)}function Ul(e,g){if(g<0)return;let I=0;for(let i of e){if(I===g)return i;I++}}function yc(e){let g;for(let I of e)g=I;return g}function JF(e,g,I){if(g.parentKey===I.parentKey)return g.index-I.index;let i=[...Nce(e,g),g],n=[...Nce(e,I),I],C=i.slice(0,n.length).findIndex((r,o)=>r!==n[o]);return C!==-1?(g=i[C],I=n[C],g.index-I.index):i.findIndex(r=>r===I)>=0?1:(n.findIndex(r=>r===g)>=0,-1)}function Nce(e,g){let I=[];for(;(g==null?void 0:g.parentKey)!=null;)g=e.getItem(g.parentKey),I.unshift(g);return I}function Aog(e,g){let{inputElementType:I="input",isDisabled:i=!1,isRequired:n=!1,isReadOnly:C=!1,type:r="text",validationBehavior:o="aria"}=e,[a,s]=gHe(e.value,e.defaultValue||"",e.onChange),{focusableProps:A}=bHe(e,g),l=jrg({...e,value:a}),{isInvalid:c,validationErrors:u,validationDetails:d}=l.displayValidation,{labelProps:h,fieldProps:m,descriptionProps:f,errorMessageProps:b}=tog({...e,isInvalid:c,errorMessage:e.errorMessage||u}),p=YA(e,{labelable:!0});const y={type:r,pattern:e.pattern};return UCg(g,a,s),Org(e,l,g),U.useEffect(()=>{if(g.current instanceof HH(g.current).HTMLTextAreaElement){let Z=g.current;Object.defineProperty(Z,"defaultValue",{get:()=>Z.value,set:()=>{},configurable:!0})}},[g]),{labelProps:h,inputProps:Gi(p,I==="input"&&y,{disabled:i,readOnly:C,required:n&&o==="native","aria-required":n&&o==="aria"||void 0,"aria-invalid":c||void 0,"aria-errormessage":e["aria-errormessage"],"aria-activedescendant":e["aria-activedescendant"],"aria-autocomplete":e["aria-autocomplete"],"aria-haspopup":e["aria-haspopup"],value:a,onChange:Z=>s(Z.target.value),autoComplete:e.autoComplete,maxLength:e.maxLength,minLength:e.minLength,name:e.name,placeholder:e.placeholder,inputMode:e.inputMode,onCopy:e.onCopy,onCut:e.onCut,onPaste:e.onPaste,onCompositionEnd:e.onCompositionEnd,onCompositionStart:e.onCompositionStart,onCompositionUpdate:e.onCompositionUpdate,onSelect:e.onSelect,onBeforeInput:e.onBeforeInput,onInput:e.onInput,...A,...m}),descriptionProps:f,errorMessageProps:b,isInvalid:c,validationErrors:u,validationDetails:d}}class up{copy(){return new up(this.x,this.y)}equals(g){return this.x===g.x&&this.y===g.y}isOrigin(){return this.x===0&&this.y===0}constructor(g=0,I=0){this.x=g,this.y=I}}class dp{get maxX(){return this.x+this.width}get maxY(){return this.y+this.height}get area(){return this.width*this.height}get topLeft(){return new up(this.x,this.y)}get topRight(){return new up(this.maxX,this.y)}get bottomLeft(){return new up(this.x,this.maxY)}get bottomRight(){return new up(this.maxX,this.maxY)}intersects(g){return this.x<=g.x+g.width&&g.x<=this.x+this.width&&this.y<=g.y+g.height&&g.y<=this.y+this.height}containsRect(g){return this.x<=g.x&&this.y<=g.y&&this.maxX>=g.maxX&&this.maxY>=g.maxY}containsPoint(g){return this.x<=g.x&&this.y<=g.y&&this.maxX>=g.x&&this.maxY>=g.y}getCornerInRect(g){for(let I of["topLeft","topRight","bottomLeft","bottomRight"])if(g.containsPoint(this[I]))return I;return null}equals(g){return g.x===this.x&&g.y===this.y&&g.width===this.width&&g.height===this.height}pointEquals(g){return this.x===g.x&&this.y===g.y}sizeEquals(g){return this.width===g.width&&this.height===g.height}union(g){let I=Math.min(this.x,g.x),i=Math.min(this.y,g.y),n=Math.max(this.maxX,g.maxX)-I,C=Math.max(this.maxY,g.maxY)-i;return new dp(I,i,n,C)}intersection(g){if(!this.intersects(g))return new dp(0,0,0,0);let I=Math.max(this.x,g.x),i=Math.max(this.y,g.y);return new dp(I,i,Math.min(this.maxX,g.maxX)-I,Math.min(this.maxY,g.maxY)-i)}copy(){return new dp(this.x,this.y,this.width,this.height)}constructor(g=0,I=0,i=0,n=0){this.x=g,this.y=I,this.width=i,this.height=n}}let Mf=typeof window<"u"?window.performance:null,kce=Mf&&(Mf.now||Mf.webkitNow||Mf.msNow||Mf.mozNow);kce&&kce.bind(Mf);function A8(e){return e&&e.__esModule?e.default:e}class VHe{isCell(g){return g.type==="cell"}isRow(g){return g.type==="row"||g.type==="item"}findPreviousKey(g,I){let i=g!=null?this.collection.getKeyBefore(g):this.collection.getLastKey();for(;i!=null;){let n=this.collection.getItem(i);if(!this.disabledKeys.has(i)&&(!I||I(n)))return i;i=this.collection.getKeyBefore(i)}}findNextKey(g,I){let i=g!=null?this.collection.getKeyAfter(g):this.collection.getFirstKey();for(;i!=null;){let n=this.collection.getItem(i);if(!this.disabledKeys.has(i)&&(!I||I(n)))return i;i=this.collection.getKeyAfter(i)}}getKeyBelow(g){let I=this.collection.getItem(g);if(I&&(this.isCell(I)&&(g=I.parentKey),g=this.findNextKey(g),g!=null)){if(this.isCell(I)){let i=this.collection.getItem(g);return Ul(wi(i,this.collection),I.index).key}if(this.focusMode==="row")return g}}getKeyAbove(g){let I=this.collection.getItem(g);if(I&&(this.isCell(I)&&(g=I.parentKey),g=this.findPreviousKey(g),g!=null)){if(this.isCell(I)){let i=this.collection.getItem(g);return Ul(wi(i,this.collection),I.index).key}if(this.focusMode==="row")return g}}getKeyRightOf(g){let I=this.collection.getItem(g);if(I){if(this.isRow(I)){let i=wi(I,this.collection);return this.direction==="rtl"?yc(i).key:As(i).key}if(this.isCell(I)){let i=this.collection.getItem(I.parentKey),n=wi(i,this.collection),C=this.direction==="rtl"?Ul(n,I.index-1):Ul(n,I.index+1);return C?C.key:this.focusMode==="row"?I.parentKey:this.direction==="rtl"?this.getFirstKey(g):this.getLastKey(g)}}}getKeyLeftOf(g){let I=this.collection.getItem(g);if(I){if(this.isRow(I)){let i=wi(I,this.collection);return this.direction==="rtl"?As(i).key:yc(i).key}if(this.isCell(I)){let i=this.collection.getItem(I.parentKey),n=wi(i,this.collection),C=this.direction==="rtl"?Ul(n,I.index+1):Ul(n,I.index-1);return C?C.key:this.focusMode==="row"?I.parentKey:this.direction==="rtl"?this.getLastKey(g):this.getFirstKey(g)}}}getFirstKey(g,I){let i;if(g!=null){if(i=this.collection.getItem(g),!i)return;if(this.isCell(i)&&!I){let n=this.collection.getItem(i.parentKey);return As(wi(n,this.collection)).key}}if(g=this.findNextKey(),g!=null&&i&&this.isCell(i)&&I||this.focusMode==="cell"){let n=this.collection.getItem(g);g=As(wi(n,this.collection)).key}return g}getLastKey(g,I){let i;if(g!=null){if(i=this.collection.getItem(g),!i)return;if(this.isCell(i)&&!I){let n=this.collection.getItem(i.parentKey),C=wi(n,this.collection);return yc(C).key}}if(g=this.findPreviousKey(),g!=null&&i&&this.isCell(i)&&I||this.focusMode==="cell"){let n=this.collection.getItem(g),C=wi(n,this.collection);g=yc(C).key}return g}getItem(g){return this.ref.current.querySelector(`[data-key="${g}"]`)}getItemRect(g){var I;if(this.layout)return(I=this.layout.getLayoutInfo(g))===null||I===void 0?void 0:I.rect;let i=this.getItem(g);if(i)return new dp(i.offsetLeft,i.offsetTop,i.offsetWidth,i.offsetHeight)}getPageHeight(){var g,I,i;return this.layout?(g=this.layout.virtualizer)===null||g===void 0?void 0:g.visibleRect.height:(i=this.ref)===null||i===void 0||(I=i.current)===null||I===void 0?void 0:I.offsetHeight}getContentHeight(){var g,I;return this.layout?this.layout.getContentSize().height:(I=this.ref)===null||I===void 0||(g=I.current)===null||g===void 0?void 0:g.scrollHeight}getKeyPageAbove(g){let I=this.getItemRect(g);if(!I)return null;let i=Math.max(0,I.maxY-this.getPageHeight());for(;I&&I.y>i;)g=this.getKeyAbove(g),I=this.getItemRect(g);return g}getKeyPageBelow(g){let I=this.getItemRect(g);if(!I)return null;let i=this.getPageHeight(),n=Math.min(this.getContentHeight(),I.y+i);for(;I&&I.maxY`${e.item} غير المحدد`,longPressToSelect:"اضغط مطولًا للدخول إلى وضع التحديد.",select:"تحديد",selectedAll:"جميع العناصر المحددة.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"لم يتم تحديد عناصر",one:()=>`${g.number(e.count)} عنصر محدد`,other:()=>`${g.number(e.count)} عنصر محدد`})}.`,selectedItem:e=>`${e.item} المحدد`};var WHe={};WHe={deselectedItem:e=>`${e.item} не е избран.`,longPressToSelect:"Натиснете и задръжте за да влезете в избирателен режим.",select:"Изберете",selectedAll:"Всички елементи са избрани.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Няма избрани елементи",one:()=>`${g.number(e.count)} избран елемент`,other:()=>`${g.number(e.count)} избрани елементи`})}.`,selectedItem:e=>`${e.item} избран.`};var XHe={};XHe={deselectedItem:e=>`Položka ${e.item} není vybrána.`,longPressToSelect:"Dlouhým stisknutím přejdete do režimu výběru.",select:"Vybrat",selectedAll:"Vybrány všechny položky.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nevybrány žádné položky",one:()=>`Vybrána ${g.number(e.count)} položka`,other:()=>`Vybráno ${g.number(e.count)} položek`})}.`,selectedItem:e=>`Vybrána položka ${e.item}.`};var HHe={};HHe={deselectedItem:e=>`${e.item} ikke valgt.`,longPressToSelect:"Lav et langt tryk for at aktivere valgtilstand.",select:"Vælg",selectedAll:"Alle elementer valgt.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Ingen elementer valgt",one:()=>`${g.number(e.count)} element valgt`,other:()=>`${g.number(e.count)} elementer valgt`})}.`,selectedItem:e=>`${e.item} valgt.`};var THe={};THe={deselectedItem:e=>`${e.item} nicht ausgewählt.`,longPressToSelect:"Gedrückt halten, um Auswahlmodus zu öffnen.",select:"Auswählen",selectedAll:"Alle Elemente ausgewählt.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Keine Elemente ausgewählt",one:()=>`${g.number(e.count)} Element ausgewählt`,other:()=>`${g.number(e.count)} Elemente ausgewählt`})}.`,selectedItem:e=>`${e.item} ausgewählt.`};var NHe={};NHe={deselectedItem:e=>`Δεν επιλέχθηκε το στοιχείο ${e.item}.`,longPressToSelect:"Πατήστε παρατεταμένα για να μπείτε σε λειτουργία επιλογής.",select:"Επιλογή",selectedAll:"Επιλέχθηκαν όλα τα στοιχεία.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Δεν επιλέχθηκαν στοιχεία",one:()=>`Επιλέχθηκε ${g.number(e.count)} στοιχείο`,other:()=>`Επιλέχθηκαν ${g.number(e.count)} στοιχεία`})}.`,selectedItem:e=>`Επιλέχθηκε το στοιχείο ${e.item}.`};var kHe={};kHe={deselectedItem:e=>`${e.item} not selected.`,select:"Select",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"No items selected",one:()=>`${g.number(e.count)} item selected`,other:()=>`${g.number(e.count)} items selected`})}.`,selectedAll:"All items selected.",selectedItem:e=>`${e.item} selected.`,longPressToSelect:"Long press to enter selection mode."};var YHe={};YHe={deselectedItem:e=>`${e.item} no seleccionado.`,longPressToSelect:"Mantenga pulsado para abrir el modo de selección.",select:"Seleccionar",selectedAll:"Todos los elementos seleccionados.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Ningún elemento seleccionado",one:()=>`${g.number(e.count)} elemento seleccionado`,other:()=>`${g.number(e.count)} elementos seleccionados`})}.`,selectedItem:e=>`${e.item} seleccionado.`};var KHe={};KHe={deselectedItem:e=>`${e.item} pole valitud.`,longPressToSelect:"Valikurežiimi sisenemiseks vajutage pikalt.",select:"Vali",selectedAll:"Kõik üksused valitud.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Üksusi pole valitud",one:()=>`${g.number(e.count)} üksus valitud`,other:()=>`${g.number(e.count)} üksust valitud`})}.`,selectedItem:e=>`${e.item} valitud.`};var xHe={};xHe={deselectedItem:e=>`Kohdetta ${e.item} ei valittu.`,longPressToSelect:"Siirry valintatilaan painamalla pitkään.",select:"Valitse",selectedAll:"Kaikki kohteet valittu.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Ei yhtään kohdetta valittu",one:()=>`${g.number(e.count)} kohde valittu`,other:()=>`${g.number(e.count)} kohdetta valittu`})}.`,selectedItem:e=>`${e.item} valittu.`};var DHe={};DHe={deselectedItem:e=>`${e.item} non sélectionné.`,longPressToSelect:"Appuyez de manière prolongée pour passer en mode de sélection.",select:"Sélectionner",selectedAll:"Tous les éléments sélectionnés.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Aucun élément sélectionné",one:()=>`${g.number(e.count)} élément sélectionné`,other:()=>`${g.number(e.count)} éléments sélectionnés`})}.`,selectedItem:e=>`${e.item} sélectionné.`};var FHe={};FHe={deselectedItem:e=>`${e.item} לא נבחר.`,longPressToSelect:"הקשה ארוכה לכניסה למצב בחירה.",select:"בחר",selectedAll:"כל הפריטים נבחרו.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"לא נבחרו פריטים",one:()=>`פריט ${g.number(e.count)} נבחר`,other:()=>`${g.number(e.count)} פריטים נבחרו`})}.`,selectedItem:e=>`${e.item} נבחר.`};var EHe={};EHe={deselectedItem:e=>`Stavka ${e.item} nije odabrana.`,longPressToSelect:"Dugo pritisnite za ulazak u način odabira.",select:"Odaberite",selectedAll:"Odabrane su sve stavke.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nije odabrana nijedna stavka",one:()=>`Odabrana je ${g.number(e.count)} stavka`,other:()=>`Odabrano je ${g.number(e.count)} stavki`})}.`,selectedItem:e=>`Stavka ${e.item} je odabrana.`};var MHe={};MHe={deselectedItem:e=>`${e.item} nincs kijelölve.`,longPressToSelect:"Nyomja hosszan a kijelöléshez.",select:"Kijelölés",selectedAll:"Az összes elem kijelölve.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Egy elem sincs kijelölve",one:()=>`${g.number(e.count)} elem kijelölve`,other:()=>`${g.number(e.count)} elem kijelölve`})}.`,selectedItem:e=>`${e.item} kijelölve.`};var zHe={};zHe={deselectedItem:e=>`${e.item} non selezionato.`,longPressToSelect:"Premi a lungo per passare alla modalità di selezione.",select:"Seleziona",selectedAll:"Tutti gli elementi selezionati.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nessun elemento selezionato",one:()=>`${g.number(e.count)} elemento selezionato`,other:()=>`${g.number(e.count)} elementi selezionati`})}.`,selectedItem:e=>`${e.item} selezionato.`};var PHe={};PHe={deselectedItem:e=>`${e.item} が選択されていません。`,longPressToSelect:"長押しして選択モードを開きます。",select:"選択",selectedAll:"すべての項目を選択しました。",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"項目が選択されていません",one:()=>`${g.number(e.count)} 項目を選択しました`,other:()=>`${g.number(e.count)} 項目を選択しました`})}。`,selectedItem:e=>`${e.item} を選択しました。`};var JHe={};JHe={deselectedItem:e=>`${e.item}이(가) 선택되지 않았습니다.`,longPressToSelect:"선택 모드로 들어가려면 길게 누르십시오.",select:"선택",selectedAll:"모든 항목이 선택되었습니다.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"선택된 항목이 없습니다",one:()=>`${g.number(e.count)}개 항목이 선택되었습니다`,other:()=>`${g.number(e.count)}개 항목이 선택되었습니다`})}.`,selectedItem:e=>`${e.item}이(가) 선택되었습니다.`};var OHe={};OHe={deselectedItem:e=>`${e.item} nepasirinkta.`,longPressToSelect:"Norėdami įjungti pasirinkimo režimą, paspauskite ir palaikykite.",select:"Pasirinkti",selectedAll:"Pasirinkti visi elementai.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nepasirinktas nė vienas elementas",one:()=>`Pasirinktas ${g.number(e.count)} elementas`,other:()=>`Pasirinkta elementų: ${g.number(e.count)}`})}.`,selectedItem:e=>`Pasirinkta: ${e.item}.`};var _He={};_He={deselectedItem:e=>`Vienums ${e.item} nav atlasīts.`,longPressToSelect:"Ilgi turiet nospiestu. lai ieslēgtu atlases režīmu.",select:"Atlasīt",selectedAll:"Atlasīti visi vienumi.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nav atlasīts neviens vienums",one:()=>`Atlasīto vienumu skaits: ${g.number(e.count)}`,other:()=>`Atlasīto vienumu skaits: ${g.number(e.count)}`})}.`,selectedItem:e=>`Atlasīts vienums ${e.item}.`};var LHe={};LHe={deselectedItem:e=>`${e.item} er ikke valgt.`,longPressToSelect:"Bruk et langt trykk for å gå inn i valgmodus.",select:"Velg",selectedAll:"Alle elementer er valgt.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Ingen elementer er valgt",one:()=>`${g.number(e.count)} element er valgt`,other:()=>`${g.number(e.count)} elementer er valgt`})}.`,selectedItem:e=>`${e.item} er valgt.`};var UHe={};UHe={deselectedItem:e=>`${e.item} niet geselecteerd.`,longPressToSelect:"Druk lang om de selectiemodus te openen.",select:"Selecteren",selectedAll:"Alle items geselecteerd.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Geen items geselecteerd",one:()=>`${g.number(e.count)} item geselecteerd`,other:()=>`${g.number(e.count)} items geselecteerd`})}.`,selectedItem:e=>`${e.item} geselecteerd.`};var QHe={};QHe={deselectedItem:e=>`Nie zaznaczono ${e.item}.`,longPressToSelect:"Naciśnij i przytrzymaj, aby wejść do trybu wyboru.",select:"Zaznacz",selectedAll:"Wszystkie zaznaczone elementy.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nie zaznaczono żadnych elementów",one:()=>`${g.number(e.count)} zaznaczony element`,other:()=>`${g.number(e.count)} zaznaczonych elementów`})}.`,selectedItem:e=>`Zaznaczono ${e.item}.`};var jHe={};jHe={deselectedItem:e=>`${e.item} não selecionado.`,longPressToSelect:"Mantenha pressionado para entrar no modo de seleção.",select:"Selecionar",selectedAll:"Todos os itens selecionados.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nenhum item selecionado",one:()=>`${g.number(e.count)} item selecionado`,other:()=>`${g.number(e.count)} itens selecionados`})}.`,selectedItem:e=>`${e.item} selecionado.`};var $He={};$He={deselectedItem:e=>`${e.item} não selecionado.`,longPressToSelect:"Prima continuamente para entrar no modo de seleção.",select:"Selecionar",selectedAll:"Todos os itens selecionados.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nenhum item selecionado",one:()=>`${g.number(e.count)} item selecionado`,other:()=>`${g.number(e.count)} itens selecionados`})}.`,selectedItem:e=>`${e.item} selecionado.`};var qHe={};qHe={deselectedItem:e=>`${e.item} neselectat.`,longPressToSelect:"Apăsați lung pentru a intra în modul de selectare.",select:"Selectare",selectedAll:"Toate elementele selectate.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Niciun element selectat",one:()=>`${g.number(e.count)} element selectat`,other:()=>`${g.number(e.count)} elemente selectate`})}.`,selectedItem:e=>`${e.item} selectat.`};var eTe={};eTe={deselectedItem:e=>`${e.item} не выбрано.`,longPressToSelect:"Нажмите и удерживайте для входа в режим выбора.",select:"Выбрать",selectedAll:"Выбраны все элементы.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Нет выбранных элементов",one:()=>`${g.number(e.count)} элемент выбран`,other:()=>`${g.number(e.count)} элементов выбрано`})}.`,selectedItem:e=>`${e.item} выбрано.`};var tTe={};tTe={deselectedItem:e=>`Nevybraté položky: ${e.item}.`,longPressToSelect:"Dlhším stlačením prejdite do režimu výberu.",select:"Vybrať",selectedAll:"Všetky vybraté položky.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Žiadne vybraté položky",one:()=>`${g.number(e.count)} vybratá položka`,other:()=>`Počet vybratých položiek:${g.number(e.count)}`})}.`,selectedItem:e=>`Vybraté položky: ${e.item}.`};var gTe={};gTe={deselectedItem:e=>`Element ${e.item} ni izbran.`,longPressToSelect:"Za izbirni način pritisnite in dlje časa držite.",select:"Izberite",selectedAll:"Vsi elementi so izbrani.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Noben element ni izbran",one:()=>`${g.number(e.count)} element je izbran`,other:()=>`${g.number(e.count)} elementov je izbranih`})}.`,selectedItem:e=>`Element ${e.item} je izbran.`};var ITe={};ITe={deselectedItem:e=>`${e.item} nije izabrano.`,longPressToSelect:"Dugo pritisnite za ulazak u režim biranja.",select:"Izaberite",selectedAll:"Izabrane su sve stavke.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nije izabrana nijedna stavka",one:()=>`Izabrana je ${g.number(e.count)} stavka`,other:()=>`Izabrano je ${g.number(e.count)} stavki`})}.`,selectedItem:e=>`${e.item} je izabrano.`};var iTe={};iTe={deselectedItem:e=>`${e.item} ej markerat.`,longPressToSelect:"Tryck länge när du vill öppna väljarläge.",select:"Markera",selectedAll:"Alla markerade objekt.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Inga markerade objekt",one:()=>`${g.number(e.count)} markerat objekt`,other:()=>`${g.number(e.count)} markerade objekt`})}.`,selectedItem:e=>`${e.item} markerat.`};var nTe={};nTe={deselectedItem:e=>`${e.item} seçilmedi.`,longPressToSelect:"Seçim moduna girmek için uzun basın.",select:"Seç",selectedAll:"Tüm ögeler seçildi.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Hiçbir öge seçilmedi",one:()=>`${g.number(e.count)} öge seçildi`,other:()=>`${g.number(e.count)} öge seçildi`})}.`,selectedItem:e=>`${e.item} seçildi.`};var CTe={};CTe={deselectedItem:e=>`${e.item} не вибрано.`,longPressToSelect:"Виконайте довге натиснення, щоб перейти в режим вибору.",select:"Вибрати",selectedAll:"Усі елементи вибрано.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Жодних елементів не вибрано",one:()=>`${g.number(e.count)} елемент вибрано`,other:()=>`Вибрано елементів: ${g.number(e.count)}`})}.`,selectedItem:e=>`${e.item} вибрано.`};var rTe={};rTe={deselectedItem:e=>`未选择 ${e.item}。`,longPressToSelect:"长按以进入选择模式。",select:"选择",selectedAll:"已选择所有项目。",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"未选择项目",one:()=>`已选择 ${g.number(e.count)} 个项目`,other:()=>`已选择 ${g.number(e.count)} 个项目`})}。`,selectedItem:e=>`已选择 ${e.item}。`};var oTe={};oTe={deselectedItem:e=>`未選取「${e.item}」。`,longPressToSelect:"長按以進入選擇模式。",select:"選取",selectedAll:"已選取所有項目。",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"未選取任何項目",one:()=>`已選取 ${g.number(e.count)} 個項目`,other:()=>`已選取 ${g.number(e.count)} 個項目`})}。`,selectedItem:e=>`已選取「${e.item}」。`};gY={"ar-AE":RHe,"bg-BG":WHe,"cs-CZ":XHe,"da-DK":HHe,"de-DE":THe,"el-GR":NHe,"en-US":kHe,"es-ES":YHe,"et-EE":KHe,"fi-FI":xHe,"fr-FR":DHe,"he-IL":FHe,"hr-HR":EHe,"hu-HU":MHe,"it-IT":zHe,"ja-JP":PHe,"ko-KR":JHe,"lt-LT":OHe,"lv-LV":_He,"nb-NO":LHe,"nl-NL":UHe,"pl-PL":QHe,"pt-BR":jHe,"pt-PT":$He,"ro-RO":qHe,"ru-RU":eTe,"sk-SK":tTe,"sl-SI":gTe,"sr-SP":ITe,"sv-SE":iTe,"tr-TR":nTe,"uk-UA":CTe,"zh-CN":rTe,"zh-TW":oTe};function sog(e,g){let{getRowText:I=r=>{var o,a,s,A;return(A=(o=(a=g.collection).getTextValue)===null||o===void 0?void 0:o.call(a,r))!==null&&A!==void 0?A:(s=g.collection.getItem(r))===null||s===void 0?void 0:s.textValue}}=e,i=hy(A8(gY)),n=g.selectionManager.rawSelection,C=U.useRef(n);aHe(()=>{var r;if(!g.selectionManager.isFocused){C.current=n;return}let o=Yce(n,C.current),a=Yce(C.current,n),s=g.selectionManager.selectionBehavior==="replace",A=[];if(g.selectionManager.selectedKeys.size===1&&s){if(g.collection.getItem(g.selectionManager.selectedKeys.keys().next().value)){let l=I(g.selectionManager.selectedKeys.keys().next().value);l&&A.push(i.format("selectedItem",{item:l}))}}else if(o.size===1&&a.size===0){let l=I(o.keys().next().value);l&&A.push(i.format("selectedItem",{item:l}))}else if(a.size===1&&o.size===0&&g.collection.getItem(a.keys().next().value)){let l=I(a.keys().next().value);l&&A.push(i.format("deselectedItem",{item:l}))}g.selectionManager.selectionMode==="multiple"&&(A.length===0||n==="all"||n.size>1||C.current==="all"||((r=C.current)===null||r===void 0?void 0:r.size)>1)&&A.push(n==="all"?i.format("selectedAll"):i.format("selectedCount",{count:n.size})),A.length>0&&vHe(A.join(" ")),C.current=n},[n])}function Yce(e,g){let I=new Set;if(e==="all"||g==="all")return I;for(let i of e.keys())g.has(i)||I.add(i);return I}function log(e){let g=hy(A8(gY)),I=crg(),i=(I==="pointer"||I==="virtual"||I==null)&&typeof window<"u"&&"ontouchstart"in window,n=U.useMemo(()=>{let r=e.selectionManager.selectionMode,o=e.selectionManager.selectionBehavior,a;return i&&(a=g.format("longPressToSelect")),o==="replace"&&r!=="none"&&e.hasItemActions?a:void 0},[e.selectionManager.selectionMode,e.selectionManager.selectionBehavior,e.hasItemActions,g,i]);return qk(n)}function cog(e,g,I){let{isVirtualized:i,keyboardDelegate:n,focusMode:C,scrollRef:r,getRowText:o,onRowAction:a,onCellAction:s}=e,{selectionManager:A}=g;!e["aria-label"]&&!e["aria-labelledby"]&&console.warn("An aria-label or aria-labelledby prop is required for accessibility.");let l=ZHe({usage:"search",sensitivity:"base"}),{direction:c}=vm(),u=g.selectionManager.disabledBehavior,d=U.useMemo(()=>n||new VHe({collection:g.collection,disabledKeys:u==="selection"?new Set:g.disabledKeys,ref:I,direction:c,collator:l,focusMode:C}),[n,g.collection,g.disabledKeys,u,I,c,l,C]),{collectionProps:h}=nog({ref:I,selectionManager:A,keyboardDelegate:d,isVirtualized:i,scrollRef:r}),m=Fh(e.id);s8.set(g,{keyboardDelegate:d,actions:{onRowAction:a,onCellAction:s}});let f=log({selectionManager:A,hasItemActions:!!(a||s)}),b=YA(e,{labelable:!0}),p=U.useCallback(G=>{if(A.isFocused){G.currentTarget.contains(G.target)||A.setFocused(!1);return}G.currentTarget.contains(G.target)&&A.setFocused(!0)},[A]),y=U.useMemo(()=>({onBlur:h.onBlur,onFocus:p}),[p,h.onBlur]),Z=Nrg(I,{isDisabled:g.collection.size!==0}),B=Gi(b,{role:"grid",id:m,"aria-multiselectable":A.selectionMode==="multiple"?"true":void 0},g.isKeyboardNavigationDisabled?y:h,g.collection.size===0&&{tabIndex:Z?-1:0},f);return i&&(B["aria-rowcount"]=g.collection.size,B["aria-colcount"]=g.collection.columnCount),sog({getRowText:o},g),{gridProps:B}}function uog(){return{rowGroupProps:{role:"rowgroup"}}}function dog(e,g,I){let{node:i,isVirtualized:n,shouldSelectOnPressUp:C,onAction:r}=e,{actions:{onRowAction:o}}=s8.get(g),{itemProps:a,...s}=wHe({selectionManager:g.selectionManager,key:i.key,ref:I,isVirtualized:n,shouldSelectOnPressUp:C,onAction:o?()=>o(i.key):r,isDisabled:g.collection.size===0}),A=g.selectionManager.isSelected(i.key),l={role:"row","aria-selected":g.selectionManager.selectionMode!=="none"?A:void 0,"aria-disabled":s.isDisabled||void 0,...a};return n&&(l["aria-rowindex"]=i.index+1),{rowProps:l,...s}}function aTe(e,g,I){let{node:i,isVirtualized:n,focusMode:C="child",shouldSelectOnPressUp:r,onAction:o}=e,{direction:a}=vm(),{keyboardDelegate:s,actions:{onCellAction:A}}=s8.get(g),l=U.useRef(null),c=()=>{let p=jr(I.current);if(C==="child"){if(I.current.contains(document.activeElement)&&I.current!==document.activeElement)return;let y=g.selectionManager.childFocusStrategy==="last"?OF(p):p.firstChild();if(y){gr(y);return}}(l.current!=null&&i.key!==l.current||!I.current.contains(document.activeElement))&&gr(I.current)},{itemProps:u,isPressed:d}=wHe({selectionManager:g.selectionManager,key:i.key,ref:I,isVirtualized:n,focus:c,shouldSelectOnPressUp:r,onAction:A?()=>A(i.key):o,isDisabled:g.collection.size===0}),f=Gi(u,{role:"gridcell",onKeyDownCapture:p=>{if(!p.currentTarget.contains(p.target)||g.isKeyboardNavigationDisabled)return;let y=jr(I.current);switch(y.currentNode=document.activeElement,p.key){case"ArrowLeft":{let Z=a==="rtl"?y.nextNode():y.previousNode();if(C==="child"&&Z===I.current&&(Z=null),Z)p.preventDefault(),p.stopPropagation(),gr(Z),Ll(Z,{containingElement:_l(I.current)});else{if(s.getKeyLeftOf(i.key)!==i.key)break;p.preventDefault(),p.stopPropagation(),C==="cell"&&a==="rtl"?(gr(I.current),Ll(I.current,{containingElement:_l(I.current)})):(y.currentNode=I.current,Z=a==="rtl"?y.firstChild():OF(y),Z&&(gr(Z),Ll(Z,{containingElement:_l(I.current)})))}break}case"ArrowRight":{let Z=a==="rtl"?y.previousNode():y.nextNode();if(C==="child"&&Z===I.current&&(Z=null),Z)p.preventDefault(),p.stopPropagation(),gr(Z),Ll(Z,{containingElement:_l(I.current)});else{if(s.getKeyRightOf(i.key)!==i.key)break;p.preventDefault(),p.stopPropagation(),C==="cell"&&a==="ltr"?(gr(I.current),Ll(I.current,{containingElement:_l(I.current)})):(y.currentNode=I.current,Z=a==="rtl"?OF(y):y.firstChild(),Z&&(gr(Z),Ll(Z,{containingElement:_l(I.current)})))}break}case"ArrowUp":case"ArrowDown":!p.altKey&&I.current.contains(p.target)&&(p.stopPropagation(),p.preventDefault(),I.current.parentElement.dispatchEvent(new KeyboardEvent(p.nativeEvent.type,p.nativeEvent)));break}},onFocus:p=>{if(l.current=i.key,p.target!==I.current){n8()||g.selectionManager.setFocusedKey(i.key);return}requestAnimationFrame(()=>{C==="child"&&document.activeElement===I.current&&c()})}});var b;return n&&(f["aria-colindex"]=((b=i.colIndex)!==null&&b!==void 0?b:i.index)+1),r&&f.tabIndex!=null&&f.onPointerDown==null&&(f.onPointerDown=p=>{let y=p.currentTarget,Z=y.getAttribute("tabindex");y.removeAttribute("tabindex"),requestAnimationFrame(()=>{y.setAttribute("tabindex",Z)})}),{gridCellProps:f,isPressed:d}}function OF(e){let g,I;do I=e.lastChild(),I&&(g=I);while(I);return g}function hog(e,g){let{key:I}=e,i=g.selectionManager,n=Fh(),C=!g.selectionManager.canSelectItem(I),r=g.selectionManager.isSelected(I),o=()=>i.select(I);const a=hy(A8(gY));return{checkboxProps:{id:n,"aria-label":a.format("select"),isSelected:r,isDisabled:C,onChange:o}}}let mog=!1;function DH(){return mog}function l8(e){return e&&e.__esModule?e.default:e}const c8=new WeakMap;function S_(e){return typeof e=="string"?e.replace(/\s*/g,""):""+e}function fog(e,g){let I=c8.get(e);if(!I)throw new Error("Unknown grid");return`${I}-${S_(g)}`}function ATe(e,g,I){let i=c8.get(e);if(!i)throw new Error("Unknown grid");return`${i}-${S_(g)}-${S_(I)}`}function sTe(e,g){return[...e.collection.rowHeaderColumnKeys].map(I=>ATe(e,g,I)).join(" ")}var IY={},lTe={};lTe={ascending:"تصاعدي",ascendingSort:e=>`ترتيب حسب العمود ${e.columnName} بترتيب تصاعدي`,columnSize:e=>`${e.value} بالبكسل`,descending:"تنازلي",descendingSort:e=>`ترتيب حسب العمود ${e.columnName} بترتيب تنازلي`,resizerDescription:"اضغط على مفتاح Enter لبدء تغيير الحجم",select:"تحديد",selectAll:"تحديد الكل",sortable:"عمود قابل للترتيب"};var cTe={};cTe={ascending:"възходящ",ascendingSort:e=>`сортирано по колона ${e.columnName} във възходящ ред`,columnSize:e=>`${e.value} пиксела`,descending:"низходящ",descendingSort:e=>`сортирано по колона ${e.columnName} в низходящ ред`,resizerDescription:"Натиснете „Enter“, за да започнете да преоразмерявате",select:"Изберете",selectAll:"Изберете всичко",sortable:"сортираща колона"};var uTe={};uTe={ascending:"vzestupně",ascendingSort:e=>`řazeno vzestupně podle sloupce ${e.columnName}`,columnSize:e=>`${e.value} pixelů`,descending:"sestupně",descendingSort:e=>`řazeno sestupně podle sloupce ${e.columnName}`,resizerDescription:"Stisknutím klávesy Enter začnete měnit velikost",select:"Vybrat",selectAll:"Vybrat vše",sortable:"sloupec s možností řazení"};var dTe={};dTe={ascending:"stigende",ascendingSort:e=>`sorteret efter kolonne ${e.columnName} i stigende rækkefølge`,columnSize:e=>`${e.value} pixels`,descending:"faldende",descendingSort:e=>`sorteret efter kolonne ${e.columnName} i faldende rækkefølge`,resizerDescription:"Tryk på Enter for at ændre størrelse",select:"Vælg",selectAll:"Vælg alle",sortable:"sorterbar kolonne"};var hTe={};hTe={ascending:"aufsteigend",ascendingSort:e=>`sortiert nach Spalte ${e.columnName} in aufsteigender Reihenfolge`,columnSize:e=>`${e.value} Pixel`,descending:"absteigend",descendingSort:e=>`sortiert nach Spalte ${e.columnName} in absteigender Reihenfolge`,resizerDescription:"Eingabetaste zum Starten der Größenänderung drücken",select:"Auswählen",selectAll:"Alles auswählen",sortable:"sortierbare Spalte"};var mTe={};mTe={ascending:"αύξουσα",ascendingSort:e=>`διαλογή ανά στήλη ${e.columnName} σε αύξουσα σειρά`,columnSize:e=>`${e.value} pixel`,descending:"φθίνουσα",descendingSort:e=>`διαλογή ανά στήλη ${e.columnName} σε φθίνουσα σειρά`,resizerDescription:"Πατήστε Enter για έναρξη της αλλαγής μεγέθους",select:"Επιλογή",selectAll:"Επιλογή όλων",sortable:"Στήλη διαλογής"};var fTe={};fTe={select:"Select",selectAll:"Select All",sortable:"sortable column",ascending:"ascending",descending:"descending",ascendingSort:e=>`sorted by column ${e.columnName} in ascending order`,descendingSort:e=>`sorted by column ${e.columnName} in descending order`,columnSize:e=>`${e.value} pixels`,resizerDescription:"Press Enter to start resizing"};var pTe={};pTe={ascending:"de subida",ascendingSort:e=>`ordenado por columna ${e.columnName} en orden de subida`,columnSize:e=>`${e.value} píxeles`,descending:"de bajada",descendingSort:e=>`ordenado por columna ${e.columnName} en orden de bajada`,resizerDescription:"Pulse Intro para empezar a redimensionar",select:"Seleccionar",selectAll:"Seleccionar todos",sortable:"columna ordenable"};var bTe={};bTe={ascending:"tõusev järjestus",ascendingSort:e=>`sorditud veeru järgi ${e.columnName} tõusvas järjestuses`,columnSize:e=>`${e.value} pikslit`,descending:"laskuv järjestus",descendingSort:e=>`sorditud veeru järgi ${e.columnName} laskuvas järjestuses`,resizerDescription:"Suuruse muutmise alustamiseks vajutage klahvi Enter",select:"Vali",selectAll:"Vali kõik",sortable:"sorditav veerg"};var yTe={};yTe={ascending:"nouseva",ascendingSort:e=>`lajiteltu sarakkeen ${e.columnName} mukaan nousevassa järjestyksessä`,columnSize:e=>`${e.value} pikseliä`,descending:"laskeva",descendingSort:e=>`lajiteltu sarakkeen ${e.columnName} mukaan laskevassa järjestyksessä`,resizerDescription:"Aloita koon muutos painamalla Enter-näppäintä",select:"Valitse",selectAll:"Valitse kaikki",sortable:"lajiteltava sarake"};var ZTe={};ZTe={ascending:"croissant",ascendingSort:e=>`trié en fonction de la colonne ${e.columnName} par ordre croissant`,columnSize:e=>`${e.value} pixels`,descending:"décroissant",descendingSort:e=>`trié en fonction de la colonne ${e.columnName} par ordre décroissant`,resizerDescription:"Appuyez sur Entrée pour commencer le redimensionnement.",select:"Sélectionner",selectAll:"Sélectionner tout",sortable:"colonne triable"};var GTe={};GTe={ascending:"עולה",ascendingSort:e=>`מוין לפי עמודה ${e.columnName} בסדר עולה`,columnSize:e=>`${e.value} פיקסלים`,descending:"יורד",descendingSort:e=>`מוין לפי עמודה ${e.columnName} בסדר יורד`,resizerDescription:"הקש Enter כדי לשנות את הגודל",select:"בחר",selectAll:"בחר הכול",sortable:"עמודה שניתן למיין"};var vTe={};vTe={ascending:"rastući",ascendingSort:e=>`razvrstano po stupcima ${e.columnName} rastućem redoslijedom`,columnSize:e=>`${e.value} piksela`,descending:"padajući",descendingSort:e=>`razvrstano po stupcima ${e.columnName} padajućim redoslijedom`,resizerDescription:"Pritisnite Enter da biste započeli promenu veličine",select:"Odaberite",selectAll:"Odaberite sve",sortable:"stupac koji se može razvrstati"};var BTe={};BTe={ascending:"növekvő",ascendingSort:e=>`rendezve a(z) ${e.columnName} oszlop szerint, növekvő sorrendben`,columnSize:e=>`${e.value} képpont`,descending:"csökkenő",descendingSort:e=>`rendezve a(z) ${e.columnName} oszlop szerint, csökkenő sorrendben`,resizerDescription:"Nyomja le az Enter billentyűt az átméretezés megkezdéséhez",select:"Kijelölés",selectAll:"Összes kijelölése",sortable:"rendezendő oszlop"};var STe={};STe={ascending:"crescente",ascendingSort:e=>`in ordine crescente in base alla colonna ${e.columnName}`,columnSize:e=>`${e.value} pixel`,descending:"decrescente",descendingSort:e=>`in ordine decrescente in base alla colonna ${e.columnName}`,resizerDescription:"Premi Invio per iniziare a ridimensionare",select:"Seleziona",selectAll:"Seleziona tutto",sortable:"colonna ordinabile"};var wTe={};wTe={ascending:"昇順",ascendingSort:e=>`列 ${e.columnName} を昇順で並べ替え`,columnSize:e=>`${e.value} ピクセル`,descending:"降順",descendingSort:e=>`列 ${e.columnName} を降順で並べ替え`,resizerDescription:"Enter キーを押してサイズ変更を開始",select:"選択",selectAll:"すべて選択",sortable:"並べ替え可能な列"};var VTe={};VTe={ascending:"오름차순",ascendingSort:e=>`${e.columnName} 열을 기준으로 오름차순으로 정렬됨`,columnSize:e=>`${e.value} 픽셀`,descending:"내림차순",descendingSort:e=>`${e.columnName} 열을 기준으로 내림차순으로 정렬됨`,resizerDescription:"크기 조정을 시작하려면 Enter를 누르세요.",select:"선택",selectAll:"모두 선택",sortable:"정렬 가능한 열"};var RTe={};RTe={ascending:"didėjančia tvarka",ascendingSort:e=>`surikiuota pagal stulpelį ${e.columnName} didėjančia tvarka`,columnSize:e=>`${e.value} piks.`,descending:"mažėjančia tvarka",descendingSort:e=>`surikiuota pagal stulpelį ${e.columnName} mažėjančia tvarka`,resizerDescription:"Paspauskite „Enter“, kad pradėtumėte keisti dydį",select:"Pasirinkti",selectAll:"Pasirinkti viską",sortable:"rikiuojamas stulpelis"};var WTe={};WTe={ascending:"augošā secībā",ascendingSort:e=>`kārtots pēc kolonnas ${e.columnName} augošā secībā`,columnSize:e=>`${e.value} pikseļi`,descending:"dilstošā secībā",descendingSort:e=>`kārtots pēc kolonnas ${e.columnName} dilstošā secībā`,resizerDescription:"Nospiediet Enter, lai sāktu izmēru mainīšanu",select:"Atlasīt",selectAll:"Atlasīt visu",sortable:"kārtojamā kolonna"};var XTe={};XTe={ascending:"stigende",ascendingSort:e=>`sortert etter kolonne ${e.columnName} i stigende rekkefølge`,columnSize:e=>`${e.value} piksler`,descending:"synkende",descendingSort:e=>`sortert etter kolonne ${e.columnName} i synkende rekkefølge`,resizerDescription:"Trykk på Enter for å starte størrelsesendring",select:"Velg",selectAll:"Velg alle",sortable:"kolonne som kan sorteres"};var HTe={};HTe={ascending:"oplopend",ascendingSort:e=>`gesorteerd in oplopende volgorde in kolom ${e.columnName}`,columnSize:e=>`${e.value} pixels`,descending:"aflopend",descendingSort:e=>`gesorteerd in aflopende volgorde in kolom ${e.columnName}`,resizerDescription:"Druk op Enter om het formaat te wijzigen",select:"Selecteren",selectAll:"Alles selecteren",sortable:"sorteerbare kolom"};var TTe={};TTe={ascending:"rosnąco",ascendingSort:e=>`posortowano według kolumny ${e.columnName} w porządku rosnącym`,columnSize:e=>`Liczba pikseli: ${e.value}`,descending:"malejąco",descendingSort:e=>`posortowano według kolumny ${e.columnName} w porządku malejącym`,resizerDescription:"Naciśnij Enter, aby rozpocząć zmienianie rozmiaru",select:"Zaznacz",selectAll:"Zaznacz wszystko",sortable:"kolumna z możliwością sortowania"};var NTe={};NTe={ascending:"crescente",ascendingSort:e=>`classificado pela coluna ${e.columnName} em ordem crescente`,columnSize:e=>`${e.value} pixels`,descending:"decrescente",descendingSort:e=>`classificado pela coluna ${e.columnName} em ordem decrescente`,resizerDescription:"Pressione Enter para começar a redimensionar",select:"Selecionar",selectAll:"Selecionar tudo",sortable:"coluna classificável"};var kTe={};kTe={ascending:"ascendente",ascendingSort:e=>`Ordenar por coluna ${e.columnName} em ordem ascendente`,columnSize:e=>`${e.value} pixels`,descending:"descendente",descendingSort:e=>`Ordenar por coluna ${e.columnName} em ordem descendente`,resizerDescription:"Prima Enter para iniciar o redimensionamento",select:"Selecionar",selectAll:"Selecionar tudo",sortable:"Coluna ordenável"};var YTe={};YTe={ascending:"crescătoare",ascendingSort:e=>`sortate după coloana ${e.columnName} în ordine crescătoare`,columnSize:e=>`${e.value} pixeli`,descending:"descrescătoare",descendingSort:e=>`sortate după coloana ${e.columnName} în ordine descrescătoare`,resizerDescription:"Apăsați pe Enter pentru a începe redimensionarea",select:"Selectare",selectAll:"Selectare totală",sortable:"coloană sortabilă"};var KTe={};KTe={ascending:"возрастание",ascendingSort:e=>`сортировать столбец ${e.columnName} в порядке возрастания`,columnSize:e=>`${e.value} пикс.`,descending:"убывание",descendingSort:e=>`сортировать столбец ${e.columnName} в порядке убывания`,resizerDescription:"Нажмите клавишу Enter для начала изменения размеров",select:"Выбрать",selectAll:"Выбрать все",sortable:"сортируемый столбец"};var xTe={};xTe={ascending:"vzostupne",ascendingSort:e=>`zoradené zostupne podľa stĺpca ${e.columnName}`,columnSize:e=>`Počet pixelov: ${e.value}`,descending:"zostupne",descendingSort:e=>`zoradené zostupne podľa stĺpca ${e.columnName}`,resizerDescription:"Stlačením klávesu Enter začnete zmenu veľkosti",select:"Vybrať",selectAll:"Vybrať všetko",sortable:"zoraditeľný stĺpec"};var DTe={};DTe={ascending:"naraščajoče",ascendingSort:e=>`razvrščeno po stolpcu ${e.columnName} v naraščajočem vrstnem redu`,columnSize:e=>`${e.value} slikovnih pik`,descending:"padajoče",descendingSort:e=>`razvrščeno po stolpcu ${e.columnName} v padajočem vrstnem redu`,resizerDescription:"Pritisnite tipko Enter da začnete spreminjati velikost",select:"Izberite",selectAll:"Izberite vse",sortable:"razvrstljivi stolpec"};var FTe={};FTe={ascending:"rastući",ascendingSort:e=>`sortirano po kolonama ${e.columnName} rastućim redosledom`,columnSize:e=>`${e.value} piksela`,descending:"padajući",descendingSort:e=>`sortirano po kolonama ${e.columnName} padajućim redosledom`,resizerDescription:"Pritisnite Enter da biste započeli promenu veličine",select:"Izaberite",selectAll:"Izaberite sve",sortable:"kolona koja se može sortirati"};var ETe={};ETe={ascending:"stigande",ascendingSort:e=>`sorterat på kolumn ${e.columnName} i stigande ordning`,columnSize:e=>`${e.value} pixlar`,descending:"fallande",descendingSort:e=>`sorterat på kolumn ${e.columnName} i fallande ordning`,resizerDescription:"Tryck på Retur för att börja ändra storlek",select:"Markera",selectAll:"Markera allt",sortable:"sorterbar kolumn"};var MTe={};MTe={ascending:"artan sırada",ascendingSort:e=>`${e.columnName} sütuna göre artan düzende sırala`,columnSize:e=>`${e.value} piksel`,descending:"azalan sırada",descendingSort:e=>`${e.columnName} sütuna göre azalan düzende sırala`,resizerDescription:"Yeniden boyutlandırmak için Enter'a basın",select:"Seç",selectAll:"Tümünü Seç",sortable:"Sıralanabilir sütun"};var zTe={};zTe={ascending:"висхідний",ascendingSort:e=>`відсортовано за стовпцем ${e.columnName} у висхідному порядку`,columnSize:e=>`${e.value} пікс.`,descending:"низхідний",descendingSort:e=>`відсортовано за стовпцем ${e.columnName} у низхідному порядку`,resizerDescription:"Натисніть Enter, щоб почати зміну розміру",select:"Вибрати",selectAll:"Вибрати все",sortable:"сортувальний стовпець"};var PTe={};PTe={ascending:"升序",ascendingSort:e=>`按列 ${e.columnName} 升序排序`,columnSize:e=>`${e.value} 像素`,descending:"降序",descendingSort:e=>`按列 ${e.columnName} 降序排序`,resizerDescription:"按“输入”键开始调整大小。",select:"选择",selectAll:"全选",sortable:"可排序的列"};var JTe={};JTe={ascending:"遞增",ascendingSort:e=>`已依據「${e.columnName}」欄遞增排序`,columnSize:e=>`${e.value} 像素`,descending:"遞減",descendingSort:e=>`已依據「${e.columnName}」欄遞減排序`,resizerDescription:"按 Enter 鍵以開始調整大小",select:"選取",selectAll:"全選",sortable:"可排序的欄"};IY={"ar-AE":lTe,"bg-BG":cTe,"cs-CZ":uTe,"da-DK":dTe,"de-DE":hTe,"el-GR":mTe,"en-US":fTe,"es-ES":pTe,"et-EE":bTe,"fi-FI":yTe,"fr-FR":ZTe,"he-IL":GTe,"hr-HR":vTe,"hu-HU":BTe,"it-IT":STe,"ja-JP":wTe,"ko-KR":VTe,"lt-LT":RTe,"lv-LV":WTe,"nb-NO":XTe,"nl-NL":HTe,"pl-PL":TTe,"pt-BR":NTe,"pt-PT":kTe,"ro-RO":YTe,"ru-RU":KTe,"sk-SK":xTe,"sl-SI":DTe,"sr-SP":FTe,"sv-SE":ETe,"tr-TR":MTe,"uk-UA":zTe,"zh-CN":PTe,"zh-TW":JTe};class pog extends VHe{isCell(g){return g.type==="cell"||g.type==="rowheader"||g.type==="column"}getKeyBelow(g){let I=this.collection.getItem(g);if(I){if(I.type==="column"){let i=As(wi(I,this.collection));if(i)return i.key;let n=this.getFirstKey();if(n==null)return;let C=this.collection.getItem(n);return Ul(wi(C,this.collection),I.index).key}return super.getKeyBelow(g)}}getKeyAbove(g){let I=this.collection.getItem(g);if(!I)return;if(I.type==="column"){let n=this.collection.getItem(I.parentKey);return n&&n.type==="column"?n.key:void 0}let i=super.getKeyAbove(g);return i!=null&&this.collection.getItem(i).type!=="headerrow"?i:this.isCell(I)?this.collection.columns[I.index].key:this.collection.columns[0].key}findNextColumnKey(g){let I=this.findNextKey(g.key,n=>n.type==="column");if(I!=null)return I;let i=this.collection.headerRows[g.level];for(let n of wi(i,this.collection))if(n.type==="column")return n.key}findPreviousColumnKey(g){let I=this.findPreviousKey(g.key,C=>C.type==="column");if(I!=null)return I;let i=this.collection.headerRows[g.level],n=[...wi(i,this.collection)];for(let C=n.length-1;C>=0;C--){let r=n[C];if(r.type==="column")return r.key}}getKeyRightOf(g){let I=this.collection.getItem(g);if(I)return I.type==="column"?this.direction==="rtl"?this.findPreviousColumnKey(I):this.findNextColumnKey(I):super.getKeyRightOf(g)}getKeyLeftOf(g){let I=this.collection.getItem(g);if(I)return I.type==="column"?this.direction==="rtl"?this.findNextColumnKey(I):this.findPreviousColumnKey(I):super.getKeyLeftOf(g)}getKeyForSearch(g,I){if(!this.collator)return null;let i=this.collection,n=I??this.getFirstKey();if(n==null)return null;let C=i.getItem(n);C.type==="cell"&&(n=C.parentKey);let r=!1;for(;n!=null;){let o=i.getItem(n);for(let a of wi(o,this.collection)){let s=i.columns[a.index];if(i.rowHeaderColumnKeys.has(s.key)&&a.textValue){let A=a.textValue.slice(0,g.length);if(this.collator.compare(A,g)===0)return(I!=null?i.getItem(I):C).type==="cell"?a.key:o.key}}n=this.getKeyBelow(n),n==null&&!r&&(n=this.getFirstKey(),r=!0)}return null}}function bog(e,g,I){let{keyboardDelegate:i,isVirtualized:n,layout:C}=e,r=ZHe({usage:"search",sensitivity:"base"}),{direction:o}=vm(),a=g.selectionManager.disabledBehavior,s=U.useMemo(()=>i||new pog({collection:g.collection,disabledKeys:a==="selection"?new Set:g.disabledKeys,ref:I,direction:o,collator:r,layout:C}),[i,g.collection,g.disabledKeys,a,I,o,r,C]),A=Fh(e.id);c8.set(g,A);let{gridProps:l}=cog({...e,id:A,keyboardDelegate:s},g,I);n&&(l["aria-rowcount"]=g.collection.size+g.collection.headerRows.length),DH()&&"expandedKeys"in g&&(l.role="treegrid");let{column:c,direction:u}=g.sortDescriptor||{},d=hy(l8(IY)),h=U.useMemo(()=>{var f;let b=(f=g.collection.columns.find(p=>p.key===c))===null||f===void 0?void 0:f.textValue;return u&&c?d.format(`${u}Sort`,{columnName:b}):void 0},[u,c,g.collection.columns]),m=qk(h);return aHe(()=>{vHe(h,"assertive",500)},[h]),{gridProps:Gi(l,m,{"aria-describedby":[m["aria-describedby"],l["aria-describedby"]].filter(Boolean).join(" ")})}}function yog(e,g,I){var i,n;let{node:C}=e,r=C.props.allowsSorting,{gridCellProps:o}=aTe({...e,focusMode:"child"},g,I),a=C.props.isSelectionCell&&g.selectionManager.selectionMode==="single",{pressProps:s}=I8({isDisabled:!r||a,onPress(){g.sort(C.key)},ref:I}),{focusableProps:A}=bHe({},I),l=null,c=((i=g.sortDescriptor)===null||i===void 0?void 0:i.column)===C.key,u=(n=g.sortDescriptor)===null||n===void 0?void 0:n.direction;C.props.allowsSorting&&!TH()&&(l=c?u:"none");let d=hy(l8(IY)),h;r&&(h=`${d.format("sortable")}`,c&&u&&TH()&&(h=`${h}, ${d.format(u)}`));let m=qk(h),f=g.collection.size===0;return U.useEffect(()=>{f&&g.selectionManager.focusedKey===C.key&&g.selectionManager.setFocusedKey(null)},[f,g.selectionManager,C.key]),{columnHeaderProps:{...Gi(o,s,A,m,f&&{tabIndex:-1}),role:"columnheader",id:fog(g,C.key),"aria-colspan":C.colspan&&C.colspan>1?C.colspan:null,"aria-sort":l}}}const Kce={expand:{ltr:"ArrowRight",rtl:"ArrowLeft"},collapse:{ltr:"ArrowLeft",rtl:"ArrowRight"}};function Zog(e,g,I){let{node:i,isVirtualized:n}=e,{rowProps:C,...r}=dog(e,g,I),{direction:o}=vm();n&&!(DH()&&"expandedKeys"in g)?C["aria-rowindex"]=i.index+1+g.collection.headerRows.length:delete C["aria-rowindex"];let a={};if(DH()&&"expandedKeys"in g){let u=g.keyMap.get(i.key);if(u!=null){var s,A,l;let d=((s=u.props)===null||s===void 0?void 0:s.UNSTABLE_childItems)||((l=u.props)===null||l===void 0||(A=l.children)===null||A===void 0?void 0:A.length)>g.userColumnCount;a={onKeyDown:h=>{(h.key===Kce.expand[o]&&g.selectionManager.focusedKey===u.key&&d&&g.expandedKeys!=="all"&&!g.expandedKeys.has(u.key)||h.key===Kce.collapse[o]&&g.selectionManager.focusedKey===u.key&&d&&(g.expandedKeys==="all"||g.expandedKeys.has(u.key)))&&(g.toggleKey(u.key),h.stopPropagation())},"aria-expanded":d?g.expandedKeys==="all"||g.expandedKeys.has(i.key):void 0,"aria-level":u.level,"aria-posinset":u.indexOfType+1,"aria-setsize":u.level>1?yc(g.keyMap.get(u==null?void 0:u.parentKey).childNodes).indexOfType+1:yc(g.keyMap.get(g.collection.body.key).childNodes).indexOfType+1}}}let c=r.hasAction?PCg(i.props):{};return{rowProps:{...Gi(C,a,c),"aria-labelledby":sTe(g,i.key)},...r}}function Gog(e,g,I){let{node:i,isVirtualized:n}=e,C={role:"row"};return n&&!(DH()&&"expandedKeys"in g)&&(C["aria-rowindex"]=i.index+1),{rowProps:C}}function vog(e,g,I){let{gridCellProps:i,isPressed:n}=aTe(e,g,I),C=e.node.column.key;return g.collection.rowHeaderColumnKeys.has(C)&&(i.role="rowheader",i.id=ATe(g,e.node.parentKey,C)),{gridCellProps:i,isPressed:n}}function Bog(e,g){let{key:I}=e;const{checkboxProps:i}=hog(e,g);return{checkboxProps:{...i,"aria-labelledby":`${i.id} ${sTe(g,I)}`}}}function Sog(e){let{isEmpty:g,isSelectAll:I,selectionMode:i}=e.selectionManager;return{checkboxProps:{"aria-label":hy(l8(IY)).format(i==="single"?"select":"selectAll"),isSelected:I,isDisabled:i!=="multiple"||e.collection.size===0,isIndeterminate:!g&&!I,onChange:()=>e.selectionManager.toggleSelectAll()}}}function OTe(){return uog()}var _Te={exports:{}},LTe={};/** +${s}`:s,l=Tet(o).parse(A,c=>SI(this,x$,t2e).call(this,c,r,I,i));if(C&&((g=l[0])!=null&&g[C])){const c=Object.keys(l[0]),u={};l.forEach(d=>{u[d[C]]?c.forEach(h=>{u[d[C]][`${h}_2`]=d[h]}):u[d[C]]=JSON.parse(JSON.stringify(d))}),WC(this,rS,Object.keys(u).map(d=>u[d]))}else WC(this,rS,l)}catch(a){console.error("[Gosling Data Fetcher] Error fetching data",a)}};x$=new WeakSet;t2e=function(e,g,I,i){try{return g?g.forEach(n=>{const C=n.genomicFields,r=e[n.chromosomeField];C.forEach(o=>{const a=e[o];e[o]=String(SI(this,vH,LO).call(this,r,a))})}):I&&i&&i.forEach(n=>{const C=e[n],r=e[I];e[n]=String(SI(this,vH,LO).call(this,r,C))}),e}catch{return}};vH=new WeakSet;LO=function(e,g){if(Dt(this,Md)!=="unknown"){const I=m3(e,Dt(this,Md),this.dataConfig.chromosomePrefix);return bI(Dt(this,Md)).interval[I][0]+ +g}else return g};UO=new WeakSet;g2e=function(e){this.tilesetInfoLoading=!1;const g=1024,I=Dt(this,CS).totalLength,i={tile_size:g,max_zoom:Math.ceil(Math.log(I/g)/Math.log(2)),max_width:I,min_pos:[0,0],max_pos:[I,I]};return e&&e(i),i};QO=new WeakSet;I2e=async function(e,g,I){var i,n;const C=await this.tilesetInfo();if(!C)return;const r=+C.max_width/2**+e,o=C.min_pos[0]+g*r,a=C.min_pos[0]+(g+1)*r;let s=jbe(Dt(this,rS),[o,a],this.dataConfig);(i=Dt(this,ZH))==null||i.forEach(l=>{s=x2e(l,s)});const A=(n=this.dataConfig.sampleLength)!=null?n:1e3;return{tabularData:s.length>A?e7(s,A):s,server:null,tilePos:[g,I],zoomLevel:e}};jO=new WeakSet;i2e=function(){const e=bI(Dt(this,Md)).size,g=[],I={};let i=0;return Object.keys(e).forEach((n,C)=>{const r={id:C,chr:n,pos:i};g.push(r),I[n]=r,i+=e[n]}),{chrToAbs:(n,C)=>Dt(this,CS).chrPositions[n].pos+C,cumPositions:g,chrPositions:I,totalLength:i,chromLengths:e}};function D2e(e,g,I){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');return new jig(g)}D2e.config={type:"csv"};function F2e(e,...g){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');class I{constructor(n){rt(this,"dataConfig"),rt(this,"tilesetInfoLoading"),rt(this,"chromSizes"),rt(this,"values"),rt(this,"assembly");const[C]=n;if(this.dataConfig=C,this.tilesetInfoLoading=!1,this.assembly=this.dataConfig.assembly,!C.values){console.error("Please provide `values` of the JSON data");return}const r=bI(this.assembly).size,o=[],a={};let s=0;Object.keys(bI(this.assembly).size).forEach((u,d)=>{const h={id:d,chr:u,pos:s};o.push(h),a[u]=h,s+=bI(this.assembly).size[u]}),this.chromSizes={chrToAbs:(u,d)=>this.chromSizes.chrPositions[u].pos+d,cumPositions:o,chrPositions:a,totalLength:s,chromLengths:r};const{chromosomeField:A,genomicFields:l,genomicFieldsToConvert:c}=this.dataConfig;this.values=C.values.map(u=>{try{return c?c.forEach(d=>{const h=d.genomicFields,m=m3(u[d.chromosomeField],this.assembly);h.forEach(f=>{const b=u[f];u[f]=String(this.chromSizes.chrToAbs(m,b))})}):A&&l&&l.forEach(d=>{const h=u[d],m=m3(u[A],this.assembly);u[d]=String(this.chromSizes.chrToAbs(m,h))}),u}catch{return}})}tilesetInfo(n){this.tilesetInfoLoading=!1;const C=1024,r=this.chromSizes.totalLength,o={tile_size:C,max_zoom:Math.ceil(Math.log(r/C)/Math.log(2)),max_width:r,min_pos:[0,0],max_pos:[r,r]};return n&&n(o),o}fetchTilesDebounced(n,C){const r={},o=[],a=[];for(const s of C){const A=s.split("."),l=parseInt(A[0],10),c=parseInt(A[1],10),u=parseInt(A[2],10);if(Number.isNaN(c)||Number.isNaN(l)){console.warn("[Gosling Data Fetcher] Invalid tile zoom or position:",l,c,u);continue}o.push(s),a.push(this.tile(l,c,u))}return Promise.all(a).then(s=>{s.forEach((A,l)=>{const c=o[l];r[c]=A,r[c].tilePositionId=c}),n(r)}),r}tile(n,C,r){var o;const a=this.tilesetInfo(),s=+a.max_width/2**+n,A=a.min_pos[0]+C*s,l=a.min_pos[0]+(C+1)*s;let c=jbe(this.values,[A,l],this.dataConfig);const u=(o=this.dataConfig.sampleLength)!=null?o:1e3;return u{const a=Object.entries(bI(C).size);return await o.init(this.uid,{url:i,indexUrl:n},a,r),o})}async tilesetInfo(g){(await this.worker).tilesetInfo(this.uid).then(g)}fetchTilesDebounced(g,I){this.track.drawLoadingCue(),I.forEach(i=>this.toFetch.add(i)),this.fetchTimeout&&clearTimeout(this.fetchTimeout),this.fetchTimeout=setTimeout(()=>{this.sendFetch(g,[...this.toFetch]),this.toFetch.clear()},qig)}async sendFetch(g,I){(await this.worker).fetchTilesDebounced(this.uid,I).then(g)}async getTabularData(g){const I=await(await this.worker).getTabularData(this.uid,g);return JSON.parse(new TextDecoder().decode(I))}}rt(M2e,"config",{type:"gff"});const z2e="KCgpID0+IHsKICB2YXIgX19jcmVhdGUgPSBPYmplY3QuY3JlYXRlOwogIHZhciBfX2RlZlByb3AgPSBPYmplY3QuZGVmaW5lUHJvcGVydHk7CiAgdmFyIF9fZ2V0T3duUHJvcERlc2MgPSBPYmplY3QuZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9yOwogIHZhciBfX2dldE93blByb3BOYW1lcyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eU5hbWVzOwogIHZhciBfX2dldFByb3RvT2YgPSBPYmplY3QuZ2V0UHJvdG90eXBlT2Y7CiAgdmFyIF9faGFzT3duUHJvcCA9IE9iamVjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHk7CiAgdmFyIF9fbWFya0FzTW9kdWxlID0gKHRhcmdldCkgPT4gX19kZWZQcm9wKHRhcmdldCwgIl9fZXNNb2R1bGUiLCB7IHZhbHVlOiB0cnVlIH0pOwogIHZhciBfX2VzbSA9IChmbiwgcmVzKSA9PiBmdW5jdGlvbiBfX2luaXQoKSB7CiAgICByZXR1cm4gZm4gJiYgKHJlcyA9ICgwLCBmbltPYmplY3Qua2V5cyhmbilbMF1dKShmbiA9IDApKSwgcmVzOwogIH07CiAgdmFyIF9fY29tbW9uSlMgPSAoY2IsIG1vZCkgPT4gZnVuY3Rpb24gX19yZXF1aXJlKCkgewogICAgcmV0dXJuIG1vZCB8fCAoMCwgY2JbT2JqZWN0LmtleXMoY2IpWzBdXSkoKG1vZCA9IHsgZXhwb3J0czoge30gfSkuZXhwb3J0cywgbW9kKSwgbW9kLmV4cG9ydHM7CiAgfTsKICB2YXIgX19leHBvcnQgPSAodGFyZ2V0LCBhbGwpID0+IHsKICAgIF9fbWFya0FzTW9kdWxlKHRh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9va3VwW2I2NC5jaGFyQ29kZUF0KGkyKV0gPDwgMTAgfCByZXZMb29rdXBbYjY0LmNoYXJDb2RlQXQoaTIgKyAxKV0gPDwgNCB8IHJldkxvb2t1cFtiNjQuY2hhckNvZGVBdChpMiArIDIpXSA+PiAyOwogICAgICAgICAgYXJyW2N1ckJ5dGUrK10gPSB0bXAgPj4gOCAmIDI1NTsKICAgICAgICAgIGFycltjdXJCeXRlKytdID0gdG1wICYgMjU1OwogICAgICAgIH0KICAgICAgICByZXR1cm4gYXJyOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHRyaXBsZXRUb0Jhc2U2NChudW0pIHsKICAgICAgICByZXR1cm4gbG9va3VwW251bSA+PiAxOCAmIDYzXSArIGxvb2t1cFtudW0gPj4gMTIgJiA2M10gKyBsb29rdXBbbnVtID4+IDYgJiA2M10gKyBsb29rdXBbbnVtICYgNjNdOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGVuY29kZUNodW5rKHVpbnQ4LCBzdGFydCwgZW5kKSB7CiAgICAgICAgdmFyIHRtcDsKICAgICAgICB2YXIgb3V0cHV0ID0gW107CiAgICAgICAgZm9yICh2YXIgaTIgPSBzdGFydDsgaTIgPCBlbmQ7IGkyICs9IDMpIHsKICAgICAgICAgIHRtcCA9ICh1aW50OFtpMl0gPDwgMTYgJiAxNjcxMTY4MCkgKyAodWludDhbaTIgKyAxXSA8PCA4ICYgNjUyODApICsgKHVpbnQ4W2kyICsgMl0gJiAyNTUpOwogICAgICAgICAgb3V0cHV0LnB1c2godHJpcGxldFRvQmFzZTY0KHRtcCkpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gb3V0cHV0LmpvaW4oIiIpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZyb21CeXRlQXJyYXkodWludDgpIHsKICAgICAgICB2YXIgdG1wOwogICAgICAgIHZhciBsZW4yID0gdWludDgubGVuZ3RoOwogICAgICAgIHZhciBleHRyYUJ5dGVzID0gbGVuMiAlIDM7CiAgICAgICAgdmFyIHBhcnRzID0gW107CiAgICAgICAgdmFyIG1heENodW5rTGVuZ3RoID0gMTYzODM7CiAgICAgICAgZm9yICh2YXIgaTIgPSAwLCBsZW4yMiA9IGxlbjIgLSBleHRyYUJ5dGVzOyBpMiA8IGxlbjIyOyBpMiArPSBtYXhDaHVua0xlbmd0aCkgewogICAgICAgICAgcGFydHMucHVzaChlbmNvZGVDaHVuayh1aW50OCwgaTIsIGkyICsgbWF4Q2h1bmtMZW5ndGggPiBsZW4yMiA/IGxlbjIyIDogaTIgKyBtYXhDaHVua0xlbmd0aCkpOwogICAgICAgIH0KICAgICAgICBpZiAoZXh0cmFCeXRlcyA9PT0gMSkgewogICAgICAgICAgdG1wID0gdWludDhbbGVuMiAtIDFdOwogICAgICAgICAgcGFydHMucHVzaChsb29rdXBbdG1wID4+IDJdICsgbG9va3VwW3RtcCA8PCA0ICYgNjNdICsgIj09Iik7CiAgICAgICAgfSBlbHNlIGlmIChleHRyYUJ5dGVzID09PSAyKSB7CiAgICAgICAgICB0bXAgPSAodWludDhbbGVuMiAtIDJdIDw8IDgpICsgdWludDhbbGVuMiAtIDFdOwogICAgICAgICAgcGFydHMucHVzaChsb29rdXBbdG1wID4+IDEwXSArIGxvb2t1cFt0bXAgPj4gNCAmIDYzXSArIGxvb2t1cFt0bXAgPDwgMiAmIDYzXSArICI9Iik7CiAgICAgICAgfQogICAgICAgIHJldHVybiBwYXJ0cy5qb2luKCIiKTsKICAgICAgfQogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vaWVlZTc1NEAxLjIuMS9ub2RlX21vZHVsZXMvaWVlZTc1NC9pbmRleC5qcwogIHZhciByZXF1aXJlX2llZWU3NTQgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vaWVlZTc1NEAxLjIuMS9ub2RlX21vZHVsZXMvaWVlZTc1NC9pbmRleC5qcyIoZXhwb3J0czIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICBleHBvcnRzMi5yZWFkID0gZnVuY3Rpb24oYnVmZmVyLCBvZmZzZXQsIGlzTEUsIG1MZW4sIG5CeXRlcykgewogICAgICAgIHZhciBlLCBtOwogICAgICAgIHZhciBlTGVuID0gbkJ5dGVzICogOCAtIG1MZW4gLSAxOwogICAgICAgIHZhciBlTWF4ID0gKDEgPDwgZUxlbikgLSAxOwogICAgICAgIHZhciBlQmlhcyA9IGVNYXggPj4gMTsKICAgICAgICB2YXIgbkJpdHMgPSAtNzsKICAgICAgICB2YXIgaSA9IGlzTEUgPyBuQnl0ZXMgLSAxIDogMDsKICAgICAgICB2YXIgZCA9IGlzTEUgPyAtMSA6IDE7CiAgICAgICAgdmFyIHMgPSBidWZmZXJbb2Zmc2V0ICsgaV07CiAgICAgICAgaSArPSBkOwogICAgICAgIGUgPSBzICYgKDEgPDwgLW5CaXRzKSAtIDE7CiAgICAgICAgcyA+Pj0gLW5CaXRzOwogICAgICAgIG5CaXRzICs9IGVMZW47CiAgICAgICAgZm9yICg7IG5CaXRzID4gMDsgZSA9IGUgKiAyNTYgKyBidWZmZXJbb2Zmc2V0ICsgaV0sIGkgKz0gZCwgbkJpdHMgLT0gOCkgewogICAgICAgIH0KICAgICAgICBtID0gZSAmICgxIDw8IC1uQml0cykgLSAxOwogICAgICAgIGUgPj49IC1uQml0czsKICAgICAgICBuQml0cyArPSBtTGVuOwogICAgICAgIGZvciAoOyBuQml0cyA+IDA7IG0gPSBtICogMjU2ICsgYnVmZmVyW29mZnNldCArIGldLCBpICs9IGQsIG5CaXRzIC09IDgpIHsKICAgICAgICB9CiAgICAgICAgaWYgKGUgPT09IDApIHsKICAgICAgICAgIGUgPSAxIC0gZUJpYXM7CiAgICAgICAgfSBlbHNlIGlmIChlID09PSBlTWF4KSB7CiAgICAgICAgICByZXR1cm4gbSA/IE5hTiA6IChzID8gLTEgOiAxKSAqIEluZmluaXR5OwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBtID0gbS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gICAgICAgICB9CiAgICAgICAgICBpZiAoZSArIGVCaWFzID49IDEpIHsKICAgICAgICAgICAgdmFsdWUgKz0gcnQgLyBjOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdmFsdWUgKz0gcnQgKiBNYXRoLnBvdygyLCAxIC0gZUJpYXMpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHZhbHVlICogYyA+PSAyKSB7CiAgICAgICAgICAgIGUrKzsKICAgICAgICAgICAgYyAvPSAyOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGUgKyBlQmlhcyA+PSBlTWF4KSB7CiAgICAgICAgICAgIG0gPSAwOwogICAgICAgICAgICBlID0gZU1heDsKICAgICAgICAgIH0gZWxzZSBpZiAoZSArIGVCaWFzID49IDEpIHsKICAgICAgICAgICAgbSA9ICh2YWx1ZSAqIGMgLSAxKSAqIE1hdGgucG93KDIsIG1MZW4pOwogICAgICAgICAgICBlID0gZSArIGVCaWFzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbSA9IHZhbHVlICogTWF0aC5wb3coMiwgZUJpYXMgLSAxKSAqIE1hdGgucG93KDIsIG1MZW4pOwogICAgICAgICAgICBlID0gMDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZm9yICg7IG1MZW4gPj0gODsgYnVmZmVyW29mZnNldCArIGldID0gbSAmIDI1NSwgaSArPSBkLCBtIC89IDI1NiwgbUxlbiAtPSA4KSB7CiAgICAgICAgfQogICAgICAgIGUgPSBlIDw8IG1MZW4gfCBtOwogICAgICAgIGVMZW4gKz0gbUxlbjsKICAgICAgICBmb3IgKDsgZUxlbiA+IDA7IGJ1ZmZlcltvZmZzZXQgKyBpXSA9IGUgJiAyNTUsIGkgKz0gZCwgZSAvPSAyNTYsIGVMZW4gLT0gOCkgewogICAgICAgIH0KICAgICAgICBidWZmZXJbb2Zmc2V0ICsgaSAtIGRdIHw9IHMgKiAxMjg7CiAgICAgIH07CiAgICB9CiAgfSk7CgogIC8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KICAgICAgICBjb25zb2xlLmVycm9yKCJUaGlzIGJyb3dzZXIgbGFja3MgdHlwZWQgYXJyYXkgKFVpbnQ4QXJyYXkpIHN1cHBvcnQgd2hpY2ggaXMgcmVxdWlyZWQgYnkgYGJ1ZmZlcmAgdjUueC4gVXNlIGBidWZmZXJgIHY0LnggaWYgeW91IHJlcXVpcmUgb2xkIGJyb3dzZXIgc3VwcG9ydC4iKTsKICAgICAgfQogICAgICBmdW5jdGlvbiB0eXBlZEFycmF5U3VwcG9ydCgpIHsKICAgICAgICB0cnkgewogICAgICAgICAgY29uc3QgYXJyID0gbmV3IFVpbnQ4QXJyYXkoMSk7CiAgICAgICAgICBjb25zdCBwcm90byA9IHsgZm9vOiBmdW5jdGlvbigpIHsKICAgICAgICAgICAgcmV0dXJuIDQyOwogICAgICAgICAgfSB9OwogICAgICAgICAgT2JqZWN0LnNldFByb3RvdHlwZU9mKHByb3RvLCBVaW50OEFycmF5LnByb3RvdHlwZSk7CiAgICAgICAgICBPYmplY3Quc2V0UHJvdG90eXBlT2YoYXJyLCBwcm90byk7CiAgICAgICAgICByZXR1cm4gYXJyLmZvbygpID09PSA0MjsKICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICB9CiAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShCdWZmZXIxMC5wcm90b3R5cGUsICJwYXJlbnQiLCB7CiAgICAgICAgZW51bWVyYWJsZTogdHJ1ZSwKICAgICAgICBnZXQ6IGZ1bmN0aW9uKCkgewogICAgICAgICAgaWYgKCFCdWZmZXIxMC5pc0J1ZmZlcih0aGlzKSkKICAgICAgICAgICAgcmV0dXJuIHZvaWQgMDsKICAgICAgICAgIHJldHVybiB0aGlzLmJ1ZmZlcjsKICAgICAgICB9CiAgICAgIH0pOwogICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoQnVmZmVyMTAucHJvdG90eXBlLCAib2Zmc2V0IiwgewogICAgICAgIGVudW1lcmFibGU6IHRydWUsCiAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHsKICAgICAgICAgIGlmICghQnVmZmVyMTAuaXNCdWZmZXIodGhpcykpCiAgICAgICAgICAgIHJldHVybiB2b2lkIDA7CiAgICAgICAgICByZXR1cm4gdGhpcy5ieXRlT2Zmc2V0OwogICAgICAgIH0KICAgICAgfSk7CiAgICAgIGZ1bmN0aW9uIGNyZWF0ZUJ1ZmZlcihsZW5ndGgpIHsKICAgICAgICBpZiAobGVuZ3RoID4gS19NQVhfTEVOR1RIKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcignVGhlIHZhbHVlICInICsgbGVuZ3RoICsgJyIgaXMgaW52YWxpZCBmb3Igb3B0aW9uICJzaXplIicpOwogICAgICAgIH0KICAgICAgICBjb25zdCBidWYgPSBuZXcgVWludDhBcnJheShsZW5ndGgpOwogICAgICAgIE9iamVjdC5zZXRQcm90b3R5cGVPZihidWYsIEJ1ZmZlcjEwLnByb3RvdHlwZSk7CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfQogICAgICBmdW5jdGlvbiBCdWZmZXIxMChhcmcsIGVuY29kaW5nT3JPZmZzZXQsIGxlbmd0aCkgewogICAgICAgIGlmICh0eXBlb2YgYXJnID09PSAibnVtYmVyIikgewogICAgICAgICAgaWYgKHR5cGVvZiBlbmNvZGluZ09yT2Zmc2V0ID09PSAic3RyaW5nIikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCdUaGUgInN0cmluZyIgYXJndW1lbnQgbXVzdCBiZSBvZiB0eXBlIHN0cmluZy4gUmVjZWl2ZWQgdHlwZSBudW1iZXInKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBhbGxvY1Vuc2FmZShhcmcpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gZnJvbShhcmcsIGVuY29kaW5nT3JPZmZzZXQsIGxlbmd0aCk7CiAgICAgIH0KICAgICAgQnVm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AgICAgICBsZXQgYnVmID0gY3JlYXRlQnVmZmVyKGxlbmd0aCk7CiAgICAgICAgY29uc3QgYWN0dWFsID0gYnVmLndyaXRlKHN0cmluZywgZW5jb2RpbmcpOwogICAgICAgIGlmIChhY3R1YWwgIT09IGxlbmd0aCkgewogICAgICAgICAgYnVmID0gYnVmLnNsaWNlKDAsIGFjdHVhbCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZnJvbUFycmF5TGlrZShhcnJheSkgewogICAgICAgIGNvbnN0IGxlbmd0aCA9IGFycmF5Lmxlbmd0aCA8IDAgPyAwIDogY2hlY2tlZChhcnJheS5sZW5ndGgpIHwgMDsKICAgICAgICBjb25zdCBidWYgPSBjcmVhdGVCdWZmZXIobGVuZ3RoKTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbmd0aDsgaSArPSAxKSB7CiAgICAgICAgICBidWZbaV0gPSBhcnJheVtpXSAmIDI1NTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfQogICAgICBmdW5jdGlvbiBmcm9tQXJyYXlWaWV3KGFycmF5VmlldykgewogICAgICAgIGlmIChpc0luc3RhbmNlKGFycmF5VmlldywgVWludDhBcnJheSkpIHsKICAgICAgICAgIGNvbnN0IGNvcHkgPSBuZXcgVWludDhBcnJheShhcnJheVZpZXcpOwogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUJ1ZmZlcihjb3B5LmJ1ZmZlciwgY29weS5ieXRlT2Zmc2V0LCBjb3B5LmJ5dGVMZW5ndGgpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gZnJvbUFycmF5TGlrZShhcnJheVZpZXcpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZyb21BcnJheUJ1ZmZlcihhcnJheSwgYnl0ZU9mZnNldCwgbGVuZ3RoKSB7CiAgICAgICAgaWYgKGJ5dGVPZmZzZXQgPCAwIHx8IGFycmF5LmJ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OwogICAgICAgICAgfQogICAgICAgICAgb2JqLmNvcHkoYnVmLCAwLCAwLCBsZW4pOwogICAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai5sZW5ndGggIT09IHZvaWQgMCkgewogICAgICAgICAgaWYgKHR5cGVvZiBvYmoubGVuZ3RoICE9PSAibnVtYmVyIiB8fCBudW1iZXJJc05hTihvYmoubGVuZ3RoKSkgewogICAgICAgICAgICByZXR1cm4gY3JlYXRlQnVmZmVyKDApOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqKTsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai50eXBlID09PSAiQnVmZmVyIiAmJiBBcnJheS5pc0FycmF5KG9iai5kYXRhKSkgewogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqLmRhdGEpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBjaGVja2VkKGxlbmd0aCkgewogICAgICAgIGlmIChsZW5ndGggPj0gS19NQVhfTEVOR1RIKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiQXR0ZW1wdCB0byBhbGxvY2F0ZSBCdWZmZXIgbGFyZ2VyIHRoYW4gbWF4aW11bSBzaXplOiAweCIgKyBLX01BWF9MRU5HVEgudG9TdHJpbmcoMTYpICsgIiBieXRlcyIpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gbGVuZ3RoIHwgMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBTbG93QnVmZmVyKGxlbmd0aCkgewogICAgICAgIGlmICgrbGVuZ3RoICE9IGxlbmd0aCkgewogICAgICAgICAgbGVuZ3RoID0gMDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJ1ZmZlcjEwLmFsbG9jKCtsZW5ndGgpOwogICAgICB9CiAgICAgIEJ1ZmZlcjEwLmlzQnVmZmVyID0gZnVuY3Rpb24gaXNCdWZmZXIyKGIpIHsKICAgICAgICByZXR1cm4gYiAhPSBudWxsICYmIGIuX2lzQnVmZmVyID09PSB0cnVlICYmIGIgIT09IEJ1ZmZlcjEwLnByb3RvdHlwZTsKICAgICAgfTsKICAgICAgQnVmZmVyMTAuY29tcGFyZSA9IGZ1bmN0aW9uIGNvbXBhcmUoYSwgYikgewogICAgICAgIGlmIChpc0luc3RhbmNlKGEsIFVpbnQ4QXJyYXkpKQogICAgICAgICAgYSA9IEJ1ZmZlcjEwLmZyb20oYSwgYS5vZmZzZXQsIGEuYnl0ZUxlbmd0aCk7CiAgICAgICAgaWYgKGlzSW5zdGFuY2UoYiwgVWludDhBcnJheSkpCiAgICAgICAgICBiID0gQnVmZmVyMTAuZnJvbShiLCBiLm9mZnNldCwgYi5ieXRlTGVuZ3RoKTsKICAgICAgICBpZiAoIUJ1ZmZlcjEwLmlzQnVmZmVyKGEpIHx8ICFCdWZmZXIxMC5pc0J1ZmZlcihiKSkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignVGhlICJidWYxIiwgImJ1ZjIiIGFyZ3VtZW50cyBtdXN0IGJlIG9uZSBvZiB0eXBlIEJ1ZmZlciBvciBVaW50OEFycmF5Jyk7CiAgICAgICAgfQogICAgICAgIGlmIChhID09PSBiKQogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgbGV0IHggPSBhLmxlbmd0aDsKICAgICAgICBsZXQgeSA9IGIubGVuZ3RoOwogICAgICAgIGZvciAobGV0IGkgPSAwLCBsZW4gPSBNYXRoLm1pbih4LCB5KTsgaSA8IGxlbjsgKytpKSB7CiAgICAgICAgICBpZiAoYVtpXSAhPT0gYltpXSkgewogICAgICAgICAgICB4ID0gYVtpXTsKICAgICAgICAgICAgeSA9IGJbaV07CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoeCA8IHkpCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHkgPCB4KQogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgcmV0dXJuIDA7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjEwLmlzRW5jb2RpbmcgPSBmdW5jdGlvbiBpc0VuY29kaW5nKGVuY29kaW5nKSB7CiAgICAgICAgc3dpdGNoIChTdHJpbmcoZW5jb2RpbmcpLnRvTG93ZXJDYXNlKCkpIHsKICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICBjYXNlICJ1dGY4IjoKICAgICAgICAgIGNhc2UgInV0Zi04IjoKICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgIGNhc2UgImxhdGluMSI6CiAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgY2FzZSAidXRmMTZsZSI6CiAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgfTsKICAgICAgQnVmZmVyMTAuY29uY2F0ID0gZnVuY3Rpb24gY29uY2F0KGxpc3QsIGxlbmd0aCkgewogICAgICAgIGlmICghQXJyYXkuaXNBcnJheShsaXN0KSkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignImxpc3QiIGFyZ3VtZW50IG11c3QgYmUgYW4gQXJyYXkgb2YgQnVmZmVycycpOwogICAgICAgIH0KICAgICAgICBpZiAobGlzdC5sZW5ndGggPT09IDApIHsKICAgICAgICAgIHJldHVybiBCdWZmZXIxMC5hbGxvYygwKTsKICAgICAgICB9CiAgICAgICAgbGV0IGk7CiAgICAgICAgaWYgKGxlbmd0aCA9PT0gdm9pZCAwKSB7CiAgICAgICAgICBsZW5ndGggPSAwOwogICAgICAgICAgZm9yIChpID0gMDsgaSA8IGxpc3QubGVuZ3RoOyArK2kpIHsKICAgICAgICAgICAgbGVuZ3RoICs9IGxpc3RbaV0ubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIgPSBCdWZmZXIxMC5hbGxvY1Vuc2FmZShsZW5ndGgpOwogICAgICAgIGxldCBwb3MgPSAwOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsaXN0Lmxlbmd0aDsgKytpKSB7CiAgICAgICAgICBsZXQgYnVmID0gbGlzdFtpXTsKICAgICAgICAgIGlmIChpc0luc3RhbmNlKGJ1ZiwgVWludDhBcnJheSkpIHsKICAgICAgICAgICAgaWYgKHBvcyArIGJ1Zi5sZW5ndGggPiBidWZmZXIubGVuZ3RoKSB7CiAgICAgICAgICAgICAgaWYgKCFCdWZmZXIxMC5pc0J1ZmZlcihidWYpKQogICAgICAgICAgICAgICAgYnVmID0gQnVmZmVyMTAuZnJvbShidWYpOwogICAgICAgICAgICAgIGJ1Zi5jb3B5KGJ1ZmZlciwgcG9zKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBVaW50OEFycmF5LnByb3RvdHlwZS5zZXQuY2FsbChidWZmZXIsIGJ1ZiwgcG9zKTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIGlmICghQnVmZmVyMTAuaXNCdWZmZXIoYnVmKSkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCcibGlzdCIgYXJndW1lbnQgbXVzdCBiZSBhbiBBcnJheSBvZiBCdWZmZXJzJyk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBidWYuY29weShidWZmZXIsIHBvcyk7CiAgICAgICAgICB9CiAgICAgICAgICBwb3MgKz0gYnVmLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZmZlcjsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gYnl0ZUxlbmd0aChzdHJpbmcsIGVuY29kaW5nKSB7CiAgICAgICAgaWYgKEJ1ZmZlcjEwLmlzQnVmZmVyKHN0cmluZykpIHsKICAgICAgICAgIHJldHVybiBzdHJpbmcubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoQXJyYXlCdWZmZXIuaXNWaWV3KHN0cmluZykgfHwgaXNJbnN0YW5jZShzdHJpbmcsIEFycmF5QnVmZmVyKSkgewogICAgICAgICAgcmV0dXJuIHN0cmluZy5ieXRlTGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAodHlwZW9mIHN0cmluZyAhPT0gInN0cmluZyIpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJ1RoZSAic3RyaW5nIiBhcmd1bWVudCBtdXN0IGJlIG9uZSBvZiB0eXBlIHN0cmluZywgQnVmZmVyLCBvciBBcnJheUJ1ZmZlci4gUmVjZWl2ZWQgdHlwZSAnICsgdHlwZW9mIHN0cmluZyk7CiAgICAgICAgfQogICAgICAgIGNvbnN0IGxlbiA9IHN0cmluZy5sZW5ndGg7CiAgICAgICAgY29uc3QgbXVzdE1hdGNoID0gYXJndW1lbnRzLmxlbmd0aCA+IDIgJiYgYXJndW1lbnRzWzJdID09PSB0cnVlOwogICAgICAgIGlmICghbXVzdE1hdGNoICYmIGxlbiA9PT0gMCkKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIGxldCBsb3dlcmVkQ2FzZSA9IGZhbHNlOwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgc3dpdGNoIChlbmNvZGluZykgewogICAgICAgICAgICBjYXNlICJhc2NpaSI6CiAgICAgICAgICAgIGNhc2UgImxhdGluMSI6CiAgICAgICAgICAgIGNhc2UgImJpbmFyeSI6CiAgICAgICAgICAgICAgcmV0dXJuIGxlbjsKICAgICAgICAgICAgY2FzZSAidXRmOCI6CiAgICAgICAgICAgIGNhc2UgInV0Zi04IjoKICAgICAgICAgICAgICByZXR1cm4gdXRmOFRvQnl0ZXMoc3RyaW5nKS5sZW5ndGg7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIGxlbiAqIDI7CiAgICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICAgICAgcmV0dXJuIGxlbiA+Pj4gMTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0VG9CeXRlcyhzdHJpbmcpLmxlbmd0aDsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpIHsKICAgICAgICAgICAgICAgIHJldHVybiBtdXN0TWF0Y2ggPyAtMSA6IHV0ZjhUb0J5dGVzKHN0cmluZykubGVuZ3RoOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBlbmNvZGluZyA9ICgiIiArIGVuY29kaW5nKS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgICAgIGxvd2VyZWRDYXNlID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgQnVmZmVyMTAuYnl0ZUxlbmd0aCA9IGJ5dGVMZW5ndGg7CiAgICAgIGZ1bmN0aW9uIHNsb3dUb1N0cmluZyhlbmNvZGluZywgc3RhcnQsIGVuZCkgewogICAgICAgIGxldCBsb3dlcmVkQ2FzZSA9IGZhbHNlOwogICAgICAgIGlmIChzdGFydCA9PT0gdm9pZCAwIHx8IHN0YXJ0IDwgMCkgewogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPiB0aGlzLmxlbmd0aCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kID09PSB2b2lkIDAgfHwgZW5kID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kIDw9IDApIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgZW5kID4+Pj0gMDsKICAgICAgICBzdGFydCA+Pj49IDA7CiAgICAgICAgaWYgKGVuZCA8PSBzdGFydCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoIWVuY29kaW5nKQogICAgICAgICAgZW5jb2RpbmcgPSAidXRmOCI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgICAgICByZXR1cm4gaGV4U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICAgIHJldHVybiBhc2NpaVNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsYXRpbjFTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjE2bGVTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gKGVuY29kaW5nICsgIiIpLnRvTG93ZXJDYXNlKCk7CiAgICAgICAgICAgICAgbG93ZXJlZENhc2UgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBCdWZmZXIxMC5wcm90b3R5cGUuX2lzQnVmZmVyID0gdHJ1ZTsKICAgICAgZnVuY3Rpb24gc3dhcChiLCBuLCBtKSB7CiAgICAgICAgY29uc3QgaSA9IGJbbl07CiAgICAgICAgYltuXSA9IGJbbV07CiAgICAgICAgYlttXSA9IGk7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnN3YXAxNiA9IGZ1bmN0aW9uIHN3YXAxNigpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgMiAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiAxNi1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDIpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDEpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnN3YXAzMiA9IGZ1bmN0aW9uIHN3YXAzMigpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgNCAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiAzMi1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDQpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDMpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMSwgaSArIDIpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnN3YXA2NCA9IGZ1bmN0aW9uIHN3YXA2NCgpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgOCAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiA2NC1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDgpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDcpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMSwgaSArIDYpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMiwgaSArIDUpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMywgaSArIDQpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnRvU3RyaW5nID0gZnVuY3Rpb24gdG9TdHJpbmcoKSB7CiAgICAgICAgY29uc3QgbGVuZ3RoID0gdGhpcy5sZW5ndGg7CiAgICAgICAgaWYgKGxlbmd0aCA9PT0gMCkKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICBpZiAoYXJndW1lbnRzLmxlbmd0aCA9PT0gMCkKICAgICAgICAgIHJldHVybiB1dGY4U2xpY2UodGhpcywgMCwgbGVuZ3RoKTsKICAgICAgIC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YgKHRoaXNTdGFydCA+PSB0aGlzRW5kICYmIHN0YXJ0ID49IGVuZCkgewogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzU3RhcnQgPj0gdGhpc0VuZCkgewogICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPj0gZW5kKSB7CiAgICAgICAgICByZXR1cm4gMTsKICAgICAgICB9CiAgICAgICAgc3RhcnQgPj4+PSAwOwogICAgICAgIGVuZCA+Pj49IDA7CiAgICAgICAgdGhpc1N0YXJ0ID4+Pj0gMDsKICAgICAgICB0aGlzRW5kID4+Pj0gMDsKICAgICAgICBpZiAodGhpcyA9PT0gdGFyZ2V0KQogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgbGV0IHggPSB0aGlzRW5kIC0gdGhpc1N0YXJ0OwogICAgICAgIGxldCB5ID0gZW5kIC0gc3RhcnQ7CiAgICAgICAgY29uc3QgbGVuID0gTWF0aC5taW4oeCwgeSk7CiAgICAgICAgY29uc3QgdGhpc0NvcHkgPSB0aGlzLnNsaWNlKHRoaXNTdGFydCwgdGhpc0VuZCk7CiAgICAgICAgY29uc3QgdGFyZ2V0Q29weSA9IHRhcmdldC5zbGljZShzdGFydCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbjsgKytpKSB7CiAgICAgICAgICBpZiAodGhpc0NvcHlbaV0gIT09IHRhcmdldENvcHlbaV0pIHsKICAgICAgICAgICAgeCA9IHRoaXNDb3B5W2ldOwogICAgICAgICAgICB5ID0gdGFyZ2V0Q29weVtpXTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICh4IDwgeSkKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICBpZiAoeSA8IHgpCiAgICAgICAgICByZXR1cm4gMTsKICAgICAgICByZXR1cm4gMDsKICAgICAgfTsKICAgICAgZnVuY3Rpb24g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9mZnNldCA9IDA7CiAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgaWYgKHR5cGVvZiB2YWwgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICB2YWwgPSBCdWZmZXIxMC5mcm9tKHZhbCwgZW5jb2RpbmcpOwogICAgICAgIH0KICAgICAgICBpZiAoQnVmZmVyMTAuaXNCdWZmZXIodmFsKSkgewogICAgICAgICAgaWYgKHZhbC5sZW5ndGggPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGFycmF5SW5kZXhPZihidWZmZXIsIHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGRpcik7CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgdmFsID0gdmFsICYgMjU1OwogICAgICAgICAgaWYgKHR5cGVvZiBVaW50OEFycmF5LnByb3RvdHlwZS5pbmRleE9mID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgIGlmIChkaXIpIHsKICAgICAgICAgICAgICByZXR1cm4gVWludDhBcnJheS5wcm90b3R5cGUuaW5kZXhPZi5jYWxsKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0KTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICByZXR1cm4gVWludDhBcnJheS5wcm90b3R5cGUubGFzdEluZGV4T2YuY2FsbChidWZmZXIsIHZhbCwgYnl0ZU9mZnNldCk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBhcnJheUluZGV4T2YoYnVmZmVyLCBbdmFsXSwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGRpcik7CiAgICAgICAgfQogICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoInZhbCBtdXN0IGJlIHN0cmluZywgbnVtYmVyIG9yIEJ1ZmZlciIpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGFycmF5SW5kZXhPZihhcnIsIHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGRpcikgewogICAgICAgIGxldCBpbmRleFNpemUgPSAxOwogICAgICAgIGxldCBhcnJMZW5ndGggPSBhcnIubGVuZ3RoOwogICAgICAgIGxldCB2YWxMZW5ndGggPSB2YWwubGVuZ3RoOwogICAgICAgIGlmIChlbmNvZGluZyAhPT0gdm9pZCAwKSB7CiAgICAgICAgICBlbmNvZGluZyA9IFN0cmluZyhlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgIGlmIChlbmNvZGluZyA9PT0gInVjczIiIHx8IGVuY29kaW5nID09PSAidWNzLTIiIHx8IGVuY29kaW5nID09PSAidXRmMTZsZSIgfHwgZW5jb2RpbmcgPT09ICJ1dGYtMTZsZSIpIHsKICAgICAgICAgICAgaWYgKGFyci5sZW5ndGggPCAyIHx8IHZhbC5sZW5ndGggPCAyKSB7CiAgICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGluZGV4U2l6ZSA9IDI7CiAgICAgICAgICAgIGFyckxlbmd0aCAvPSAyOwogICAgICAgICAgICB2YWxMZW5ndGggLz0gMjsKICAgICAgICAgICAgYnl0ZU9mZnNldCAvPSAyOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiByZWFkKGJ1ZiwgaTIpIHsKICAgICAgICAgIGlmIChpbmRleFNpemUgPT09IDEpIHsKICAgICAgICAgICAgcmV0dXJuIGJ1ZltpMl07CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByZXR1cm4gYnVmLnJlYWRVSW50MTZCRShpMiAqIGluZGV4U2l6ZSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGxldCBpOwogICAgICAgIGlmIChkaXIpIHsKICAgICAgICAgIGxldCBmb3VuZEluZGV4ID0gLTE7CiAgICAgICAgICBmb3IgKGkgPSBieXRlT2Zmc2V0OyBpIDwgYXJyTGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgaWYgKHJlYWQoYXJyLCBpKSA9PT0gcmVhZCh2YWwsIGZvdW5kSW5kZXggPT09IC0xID8gMCA6IGkgLSBmb3VuZEluZGV4KSkgewogICAgICAgICAgICAgIGlmIChmb3VuZEluZGV4ID09PSAtMSkKICAgICAgICAgICAgICAgIGZvdW5kSW5kZXggPSBpOwogICAgICAgICAgICAgIGlmIChpIC0gZm91bmRJbmRleCArIDEgPT09IHZhbExlbmd0aCkKICAgICAgICAgICAgICAgIHJldHVybiBmb3VuZEluZGV4ICogaW5kZXhTaXplOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGlmIChmb3VuZEluZGV4ICE9PSAtMSkKICAgICAgICAgICAgICAgIGkgLT0gaSAtIGZvdW5kSW5kZXg7CiAgICAgICAgICAgICAgZm91bmRJbmRleCA9IC0xOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGlmIChieXRlT2Zmc2V0ICsgdmFsTGVuZ3RoID4gYXJyTGVuZ3RoKQogICAgICAgICAgICBieXRlT2Zmc2V0ID0gYXJyTGVuZ3RoIC0gdmFsTGVuZ3RoOwogICAgICAgICAgZm9yIChpID0gYnl0ZU9mZnNldDsgaSA+PSAwOyBpLS0pIHsKICAgICAgICAgICAgbGV0IGZvdW5kID0gdHJ1ZTsKICAgICAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCB2YWxMZW5ndGg7IGorKykgewogICAgICAgICAgICAgIGlmIChyZWFkKGFyciwgaSArIGopICE9PSByZWFkKHZhbCwgaikpIHsKICAgICAgICAgICAgICAgIGZvdW5kID0gZmFsc2U7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGZvdW5kKQogICAgICAgICAgICAgIHJldHVybiBpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gLTE7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLmluY2x1ZGVzID0gZnVuY3Rpb24gaW5jbHVkZXModmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiB0aGlzLmluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgIT09IC0xOwogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUuaW5kZXhPZiA9IGZ1bmN0aW9uIGluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiBiaWRpcmVjdGlvbmFsSW5kZXhPZih0aGlzLCB2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nLCB0cnVlKTsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLmxhc3RJbmRleE9mID0gZnVuY3Rpb24gbGFzdEluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiBiaWRpcmVjdGlvbmFsSW5kZXhPZih0aGlzLCB2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nLCBmYWxzZSk7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGhleFdyaXRlKGJ1Ziwgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCkgewogICAgICAgIG9mZnNldCA9IE51bWJlcihvZmZzZXQpIHx8IDA7CiAgICAgICAgY29uc3QgcmVtYWluaW5nID0gYnVmLmxlbmd0aCAtIG9mZnNldDsKICAgICAgICBpZiAoIWxlbmd0aCkgewogICAgICAgICAgbGVuZ3RoID0gcmVtYWluaW5nOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBsZW5ndGggPSBOdW1iZXIobGVuZ3RoKTsKICAgICAgICAgIGlmIChsZW5ndGggPiByZW1haW5pbmcpIHsKICAgICAgICAgICAgbGVuZ3RoID0gcmVtYWluaW5nOwogICAgIC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sIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpIHsKICAgICAgICByZXR1cm4gYmxpdEJ1ZmZlcih1dGYxNmxlVG9CeXRlcyhzdHJpbmcsIGJ1Zi5sZW5ndGggLSBvZmZzZXQpLCBidWYsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgfQogICAgICBCdWZmZXIxMC5wcm90b3R5cGUud3JpdGUgPSBmdW5jdGlvbiB3cml0ZShzdHJpbmcsIG9mZnNldCwgbGVuZ3RoLCBlbmNvZGluZykgewogICAgICAgIGlmIChvZmZzZXQgPT09IHZvaWQgMCkgewogICAgICAgICAgZW5jb2RpbmcgPSAidXRmOCI7CiAgICAgICAgICBsZW5ndGggPSB0aGlzLmxlbmd0aDsKICAgICAgICAgIG9mZnNldCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChsZW5ndGggPT09IHZvaWQgMCAmJiB0eXBlb2Ygb2Zmc2V0ID09PSAic3RyaW5nIikgewogICAgICAgICAgZW5jb2RpbmcgPSBvZmZzZXQ7CiAgICAgICAgICBsZW5ndGggPSB0aGlzLmxlbmd0aDsKICAgICAgICAgIG9mZnNldCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChpc0Zpbml0ZShvZmZzZXQpKSB7CiAgICAgICAgICBvZmZzZXQgPSBvZmZzZXQgPj4+IDA7CiAgICAgICAgICBpZiAoaXNGaW5pdGUobGVuZ3RoKSkgewogICAgICAgICAgICBsZW5ndGggPSBsZW5ndGggPj4+IDA7CiAgICAgICAgICAgIGlmIChlbmNvZGluZyA9PT0gdm9pZCAwKQogICAgICAgICAgICAgIGVuY29kaW5nID0gInV0ZjgiOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgZW5jb2RpbmcgPSBsZW5ndGg7CiAgICAgICAgICAgIGxlbmd0aCA9IHZvaWQgMDsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJCdWZmZXIud3JpdGUoc3RyaW5n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ogICAgICAgICAgICBjYXNlICJiYXNlNjQiOgogICAgICAgICAgICAgIHJldHVybiBiYXNlNjRXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAidWNzMiI6CiAgICAgICAgICAgIGNhc2UgInVjcy0yIjoKICAgICAgICAgICAgY2FzZSAidXRmMTZsZSI6CiAgICAgICAgICAgIGNhc2UgInV0Zi0xNmxlIjoKICAgICAgICAgICAgICByZXR1cm4gdWNzMldyaXRlKHRoaXMsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpOwogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgIGlmIChsb3dlcmVkQ2FzZSkKICAgICAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoIlVua25vd24gZW5jb2Rpbmc6ICIgKyBlbmNvZGluZyk7CiAgICAgICAgICAgICAgZW5jb2RpbmcgPSAoIiIgKyBlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgICAgICBsb3dlcmVkQ2FzZSA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUudG9KU09OID0gZnVuY3Rpb24gdG9KU09OKCkgewogICAgICAgIHJldHVybiB7CiAgICAgICAgICB0eXBlOiAiQnVmZmVyIiwKICAgICAgICAgIGRhdGE6IEFycmF5LnByb3RvdHlwZS5zbGljZS5jYWxsKHRoaXMuX2FyciB8fCB0aGlzLCAwKQogICAgICAgIH07CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGJhc2U2NFNsaWNlKGJ1Ziwgc3RhcnQsIGVuZCkgewogICAgICAgIGlmIChzdGFydCA9PT0gMCAmJiBlbmQgPT09IGJ1Zi5sZW5ndGgpIHsKICAgICAgICAgIHJldHVybiBiYXNlNjQuZnJvbUJ5dGVBcnJheShidWYpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICByZXR1cm4gYmF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UgJiAzMSkgPDwgNiB8IHNlY29uZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAxMjcpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIDM6CiAgICAgICAgICAgICAgICBzZWNvbmRCeXRlID0gYnVmW2kgKyAxXTsKICAgICAgICAgICAgICAgIHRoaXJkQnl0ZSA9IGJ1ZltpICsgMl07CiAgICAgICAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKHRoaXJkQnl0ZSAmIDE5MikgPT09IDEyOCkgewogICAgICAgICAgICAgICAgICB0ZW1wQ29kZVBvaW50ID0gKGZpcnN0Qnl0ZSAmIDE1KSA8PCAxMiB8IChzZWNvbmRCeXRlICYgNjMpIDw8IDYgfCB0aGlyZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAyMDQ3ICYmICh0ZW1wQ29kZVBvaW50IDwgNTUyOTYgfHwgdGVtcENvZGVQb2ludCA+IDU3MzQzKSkgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgICAgIHNlY29uZEJ5dGUgPSBidWZbaSArIDFdOwogICAgICAgICAgICAgICAgdGhpcmRCeXRlID0gYnVmW2kgKyAyXTsKICAgICAgICAgICAgICAgIGZvdXJ0aEJ5dGUgPSBidWZbaSArIDNdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmICh0aGlyZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKGZvdXJ0aEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAxNSkgPDwgMTggfCAoc2Vjb25kQnl0ZSAmIDYzKSA8PCAxMiB8ICh0aGlyZEJ5dGUgJiA2MykgPDwgNiB8IGZvdXJ0aEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiA2NTUzNSAmJiB0ZW1wQ29kZVBvaW50IDwgMTExNDExMikgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKGNvZGVQb2ludCA9PT0gbnVsbCkgewogICAgICAgICAgICBjb2RlUG9pbnQgPSA2NTUzMzsKICAgICAgICAgICAgYnl0ZXNQZXJTZXF1ZW5jZSA9IDE7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA+IDY1NTM1KSB7CiAgICAgICAgICAgIGNvZGVQb2ludCAtPSA2NTUzNjsKICAgICAgICAgICAgcmVzLnB1c2goY29kZVBvaW50ID4+PiAxMCAmIDEwMjMgfCA1NTI5Nik7CiAgICAgICAgICAgIGNvZGVQb2ludCA9IDU2MzIwIHwgY29kZVBvaW50ICYgMTAyMzsKICAgICAgICAgIH0KICAgICAgICAgIHJlcy5wdXNoKGNvZGVQb2ludCk7CiAgICAgICAgICBpICs9IGJ5dGVzUGVyU2VxdWVuY2U7CiAgICAgICAgfQogICAgICAgIHJldHVybiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkocmVzKTsKICAgICAgfQogICAgICB2YXIgTUFYX0FSR1VNRU5UU19MRU5HVEggPSA0MDk2OwogICAgICBmdW5jdGlvbiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkoY29kZVBvaW50cykgewogICAgICAgIGNvbnN0IGxlbiA9IGNvZGVQb2ludHMubGVuZ3RoOwogICAgICAgIGlmIChsZW4gPD0gTUFYX0FSR1VNRU5UU19MRU5HVEgpIHsKICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cyk7CiAgICAgICAgfQogICAgICAgIGxldCByZXMgPSAiIjsKICAgICAgICBsZXQgaSA9IDA7CiAgICAgICAgd2hpbGUgKGkgPCBsZW4pIHsKICAgICAgICAgIHJlcyArPSBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cy5zbGljZShpLCBpICs9IE1BWF9BUkdVTUVOVFNfTEVOR1RIKSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXNjaWlTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldICYgMTI3KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBsYXRpbjFTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBoZXhTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBjb25zdCBsZW4gPSBidWYubGVuZ3RoOwogICAgICAgIGlmICghc3RhcnQgfHwgc3RhcnQgPCAwKQogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIGlmICghZW5kIHx8IGVuZCA8IDAgfHwgZW5kID4gbGVuKQogICAgICAgICAgZW5kID0gbGVuOwogICAgICAgIGxldCBvdXQgPSAiIjsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgb3V0ICs9IGhleFNsaWNlTG9va3VwVGFibGVbYnVmW2ldXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG91dDsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGYxNmxlU2xpY2UoYnVmLCBzdGFydCwgZW5kKSB7CiAgICAgICAgY29uc3QgYnl0ZXMgPSBidWYuc2xpY2Uoc3RhcnQsIGVuZCk7CiAgICAgICAgbGV0IHJlcyA9ICIiOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgYnl0ZXMubGVuZ3RoIC0gMTsgaSArPSAyKSB7CiAgICAgICAgICByZXMgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShieXRlc1tpXSArIGJ5dGVzW2kgKyAxXSAqIDI1Nik7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnNsaWNlID0gZnVuY3Rpb24gc2xpY2Uoc3RhcnQsIGVuZCkgewogICAgICAgIGNvbnN0IGxlbiA9IHRoaXMubGVuZ3RoOwogICAgICAgIHN0YXJ0ID0gfn5zdGFydDsKICAgICAgICBlbmQgPSBlbmQgPT09IHZvaWQgMCA/IGxlbiA6IH5+ZW5kOwogICAgICAgIGlmIChzdGFydCA8IDApIHsKICAgICAgICAgIHN0YXJ0ICs9IG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AgICBidWZbb2Zmc2V0KytdID0gaGk7CiAgICAgICAgaGkgPSBoaSA+PiA4OwogICAgICAgIGJ1ZltvZmZzZXQrK10gPSBoaTsKICAgICAgICBoaSA9IGhpID4+IDg7CiAgICAgICAgYnVmW29mZnNldCsrXSA9IGhpOwogICAgICAgIHJldHVybiBvZmZzZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gd3J0QmlnVUludDY0QkUoYnVmLCB2YWx1ZSwgb2Zmc2V0LCBtaW4sIG1heCkgewogICAgICAgIGNoZWNrSW50QkkodmFsdWUsIG1pbiwgbWF4LCBidWYsIG9mZnNldCwgNyk7CiAgICAgICAgbGV0IGxvID0gTnVtYmVyKHZhbHVlICYgQmlnSW50KDQyOTQ5NjcyOTUpKTsKICAgICAgICBidWZbb2Zmc2V0ICsgN10gPSBsbzsKICAgICAgICBsbyA9IGxvID4+IDg7CiAgICAgICAgYnVmW29mZnNldCArIDZdID0gbG87CiAgICAgICAgbG8gPSBsbyA+PiA4OwogICAgICAgIGJ1ZltvZmZzZXQgKyA1XSA9IGxvOwogICAgICAgIGxvID0gbG8gPj4gODsKICAgICAgICBidWZbb2Zmc2V0ICsgNF0gPSBsbzsKICAgICAgICBsZXQgaGkgPSBOdW1iZXIodmFsdWUgPj4gQmlnSW50KDMyKSAmIEJpZ0ludCg0Mjk0OTY3Mjk1KSk7CiAgICAgICAgYnVmW29mZnNldCArIDNdID0gaGk7CiAgICAgICAgaGkgPSBoaSA+PiA4OwogICAgICAgIGJ1ZltvZmZzZXQgKyAyXSA9IGhpOwogICAgICAgIGhpID0gaGkgPj4gODsKICAgICAgICBidWZbb2Zmc2V0ICsgMV0gPSBoaTsKICAgICAgICBoaSA9IGhpID4+IDg7CiAgICAgICAgYnVmW29mZnNldF0gPSBoaTsKICAgICAgICByZXR1cm4gb2Zmc2V0ICsgODsKICAgICAgfQogICAgICBCdWZmZXIxMC5wcm90b3R5cGUud3JpdGVCaWdVSW50NjRMRSA9IGRlZmluZUJpZ0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iByYW5nZSIpOwogICAgICAgIGlmIChlbmQgPCAwKQogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoInNvdXJjZUVuZCBvdXQgb2YgYm91bmRzIik7CiAgICAgICAgaWYgKGVuZCA+IHRoaXMubGVuZ3RoKQogICAgICAgICAgZW5kID0gdGhpcy5sZW5ndGg7CiAgICAgICAgaWYgKHRhcmdldC5sZW5ndGggLSB0YXJnZXRTdGFydCA8IGVuZCAtIHN0YXJ0KSB7CiAgICAgICAgICBlbmQgPSB0YXJnZXQubGVuZ3RoIC0gdGFyZ2V0U3RhcnQgKyBzdGFydDsKICAgICAgICB9CiAgICAgICAgY29uc3QgbGVuID0gZW5kIC0gc3RhcnQ7CiAgICAgICAgaWYgKHRoaXMgPT09IHRhcmdldCAmJiB0eXBlb2YgVWludDhBcnJheS5wcm90b3R5cGUuY29weVdpdGhpbiA9PT0gImZ1bmN0aW9uIikgewogICAgICAgICAgdGhpcy5jb3B5V2l0aGluKHRhcmdldFN0YXJ0LCBzdGFydCwgZW5kKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgVWludDhBcnJheS5wcm90b3R5cGUuc2V0LmNhbGwodGFyZ2V0LCB0aGlzLnN1YmFycmF5KHN0YXJ0LCBlbmQpLCB0YXJnZXRTdGFydCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBsZW47CiAgICAgIH07CiAgICAgIEJ1ZmZlcjEwLnByb3RvdHlwZS5maWxsID0gZnVuY3Rpb24gZmlsbCh2YWwsIHN0YXJ0LCBlbmQsIGVuY29kaW5nKSB7CiAgICAgICAgaWYgKHR5cGVvZiB2YWwgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICBpZiAodHlwZW9mIHN0YXJ0ID09PSAic3RyaW5nIikgewogICAgICAgICAgICBlbmNvZGluZyA9IHN0YXJ0OwogICAgICAgICAgICBzdGFydCA9IDA7CiAgICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgZW5kID09PSAic3RyaW5nIikgewogICAgICAgICAgICBlbmNvZGluZyA9IGVuZDsKICAgICAgICAgICAgZW5kID0gdGhpcy5sZW5ndGg7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoZW5jb2RpbmcgIT09IHZvaWQgMCAmJiB0eXBlb2YgZW5jb2RpbmcgIT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoImVuY29kaW5nIG11c3QgYmUgYSBzdHJpbmciKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0eXBlb2YgZW5jb2RpbmcgPT09ICJzdHJpbmciICYmICFCdWZmZXIxMC5pc0VuY29kaW5nKGVuY29kaW5nKSkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHZhbC5sZW5ndGggPT09IDEpIHsKICAgICAgICAgICAgY29uc3QgY29kZSA9IHZhbC5jaGFyQ29kZUF0KDApOwogICAgICAgICAgICBpZiAoZW5jb2RpbmcgPT09ICJ1dGY4IiAmJiBjb2RlIDwgMTI4IHx8IGVuY29kaW5nID09PSAibGF0aW4xIikgewogICAgICAgICAgICAgIHZhbCA9IGNvZGU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiB2YWwgPT09ICJudW1iZXIiKSB7CiAgICAgICAgICB2YWwgPSB2YWwgJiAyNTU7CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFsID09PSAiYm9vbGVhbiIpIHsKICAgICAgICAgIHZhbCA9IE51bWJlcih2YWwpOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPCAwIHx8IHRoaXMubGVuZ3RoIDwgc3RhcnQgfHwgdGhpcy5sZW5ndGggPCBlbmQpIHsKICAgICAgICAgIHRocm93IG5ldyBSYW5nZ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ycm9yc1tzeW1dID0gY2xhc3MgTm9kZUVycm9yIGV4dGVuZHMgQmFzZSB7CiAgICAgICAgICBjb25zdHJ1Y3RvcigpIHsKICAgICAgICAgICAgc3VwZXIoKTsKICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJtZXNzYWdlIiwgewogICAgICAgICAgICAgIHZhbHVlOiBnZXRNZXNzYWdlLmFwcGx5KHRoaXMsIGFyZ3VtZW50cyksCiAgICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICAgIH0pOwogICAgICAgICAgICB0aGlzLm5hbWUgPSBgJHt0aGlzLm5hbWV9IFske3N5bX1dYDsKICAgICAgICAgICAgdGhpcy5zdGFjazsKICAgICAgICAgICAgZGVsZXRlIHRoaXMubmFtZTsKICAgICAgICAgIH0KICAgICAgICAgIGdldCBjb2RlKCkgewogICAgICAgICAgICByZXR1cm4gc3ltOwogICAgICAgICAgfQogICAgICAgICAgc2V0IGNvZGUodmFsdWUpIHsKICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJjb2RlIiwgewogICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICBlbnVtZXJhYmxlOiB0cnVlLAogICAgICAgICAgICAgIHZhbHVlLAogICAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlCiAgICAgICAgICAgIH0pOwogICAgICAgICAgfQogICAgICAgICAgdG9TdHJpbmcoKSB7CiAgICAgICAgICAgIHJldHVybiBgJHt0aGlzLm5hbWV9IFske3N5bX1dOiAke3RoaXMubWVzc2FnZX1gOwogICAgICAgICAgfQogICAgICAgIH07CiAgICAgIH0KICAgICAgRSgiRVJSX0JVRkZFUl9PVVRfT0ZfQk9VTkRTIiwgZnVuY3Rpb24obmFtZSkgewogICAgICAgIGlmIChuYW1lKSB7CiAgICAgICAgICByZXR1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biA9PT0gImJpZ2ludCIgPyAibiIgOiAiIjsKICAgICAgICAgIGxldCByYW5nZTsKICAgICAgICAgIGlmIChieXRlTGVuZ3RoMiA+IDMpIHsKICAgICAgICAgICAgaWYgKG1pbiA9PT0gMCB8fCBtaW4gPT09IEJpZ0ludCgwKSkgewogICAgICAgICAgICAgIHJhbmdlID0gYD49IDAke259IGFuZCA8IDIke259ICoqICR7KGJ5dGVMZW5ndGgyICsgMSkgKiA4fSR7bn1gOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHJhbmdlID0gYD49IC0oMiR7bn0gKiogJHsoYnl0ZUxlbmd0aDIgKyAxKSAqIDggLSAxfSR7bn0pIGFuZCA8IDIgKiogJHsoYnl0ZUxlbmd0aDIgKyAxKSAqIDggLSAxfSR7bn1gOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByYW5nZSA9IGA+PSAke21pbn0ke259IGFuZCA8PSAke21heH0ke259YDsKICAgICAgICAgIH0KICAgICAgICAgIHRocm93IG5ldyBlcnJvcnMuRVJSX09VVF9PRl9SQU5HRSgidmFsdWUiLCByYW5nZSwgdmFsdWUpOwogICAgICAgIH0KICAgICAgICBjaGVja0JvdW5kcyhidWYsIG9mZnNldCwgYnl0ZUxlbmd0aDIpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHZhbGlkYXRlTnVtYmVyKHZhbHVlLCBuYW1lKSB7CiAgICAgICAgaWYgKHR5cGVvZiB2YWx1ZSAhPT0gIm51bWJlciIpIHsKICAgICAgICAgIHRocm93IG5ldyBlcnJvcnMuRVJSX0lOVkFMSURfQVJHX1RZUEUobmFtZSwgIm51bWJlciIsIHZhbHVlKTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYm91bmRzRXJyb3IodmFsdWUsIGxlbmd0aCwgdHlwZSkgewogICAgICAgIGlmIChNYXRoLmZsb29yKHZhbHVlKSAhPT0gdmFsdWUpIHsKICAgICAgICAgI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Y29uc3QgYnl0ZXMgPSBbXTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbmd0aDsgKytpKSB7CiAgICAgICAgICBjb2RlUG9pbnQgPSBzdHJpbmcuY2hhckNvZGVBdChpKTsKICAgICAgICAgIGlmIChjb2RlUG9pbnQgPiA1NTI5NSAmJiBjb2RlUG9pbnQgPCA1NzM0NCkgewogICAgICAgICAgICBpZiAoIWxlYWRTdXJyb2dhdGUpIHsKICAgICAgICAgICAgICBpZiAoY29kZVBvaW50ID4gNTYzMTkpIHsKICAgICAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgIH0gZWxzZSBpZiAoaSArIDEgPT09IGxlbmd0aCkgewogICAgICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGxlYWRTdXJyb2dhdGUgPSBjb2RlUG9pbnQ7CiAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGNvZGVQb2ludCA8IDU2MzIwKSB7CiAgICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgICAgICBsZWFkU3Vycm9nYXRlID0gY29kZVBvaW50OwogICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGNvZGVQb2ludCA9IChsZWFkU3Vycm9nYXRlIC0gNTUyOTYgPDwgMTAgfCBjb2RlUG9pbnQgLSA1NjMyMCkgKyA2NTUzNjsKICAgICAgICAgIH0gZWxzZSBpZiAobGVhZFN1cnJvZ2F0ZSkgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgIH0KICAgICAgICAgIGxlYWRTdXJyb2dhdGUgPSBudWxsOwogICAgICAgICAgaWYgKGNvZGVQb2ludCA8IDEyOCkgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDEpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQpOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPCAyMDQ4KSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMikgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCA+PiA2IHwgMTkyLCBjb2RlUG9pbnQgJiA2MyB8IDEyOCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA8IDY1NTM2KSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCA+PiAxMiB8IDIyNCwgY29kZVBvaW50ID4+IDYgJiA2MyB8IDEyOCwgY29kZVBvaW50ICYgNjMgfCAxMjgpOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPCAxMTE0MTEyKSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gNCkgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCA+PiAxOCB8IDI0MCwgY29kZVBvaW50ID4+IDEyICYgNjMgfCAxMjgsIGNvZGVQb2ludCA+PiA2ICYgNjMgfCAxMjgsIGNvZGVQb2ludCAmIDYzIHwgMTI4KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcigiSW52YWxpZCBjb2RlIHBvaW50Iik7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBieXRlczsKICAgICAgfQogICAgICBmdW5jdGlvbiBhc2NpaVRvQnl0ZXMoc3RyKSB7CiAgICAgICAgY29uc3QgYnl0ZUFycmF5ID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBzdHIubGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGJ5dGVBcnJheS5wdXNoKHN0ci5jaGFyQ29kZUF0KGkpICYgMjU1KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ5dGVBcnJheTsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGYxNmxlVG9CeXRlcyhzdHIsIHVuaXRzKSB7CiAgICAgICAgbGV0IGMsIGhpLCBsbzsKICAgICAgICBjb25zdCBieXRlQXJyYXkgPSBbXTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHN0ci5sZW5ndGg7ICsraSkgewogICAgICAgICAgaWYgKCh1bml0cyAtPSAyKSA8IDApCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgYyA9IHN0ci5jaGFyQ29kZUF0KGkpOwogICAgICAgICAgaGkgPSBjID4+IDg7CiAgICAgICAgICBsbyA9IGMgJSAyNTY7CiAgICAgICAgICBieXRlQXJyYXkucHVzaChsbyk7CiAgICAgICAgICBieXRlQXJyYXkucHVzaChoaSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBieXRlQXJyYXk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYmFzZTY0VG9CeXRlcyhzdHIpIHsKICAgICAgICByZXR1cm4gYmFzZTY0LnRvQnl0ZUFycmF5KGJhc2U2NGNsZWFuKHN0cikpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJsaXRCdWZmZXIoc3JjLCBkc3QsIG9mZnNldCwgbGVuZ3RoKSB7CiAgICAgICAgbGV0IGk7CiAgICAgICAgZm9yIChpID0gMDsgaSA8IGxlbmd0aDsgKytpKSB7CiAgICAgICAgICBpZiAoaSArIG9mZnNldCA+PSBkc3QubGVuZ3RoIHx8IGkgPj0gc3JjLmxlbmd0aCkKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBkc3RbaSArIG9mZnNldF0gPSBzcmNbaV07CiAgICAgICAgfQogICAgICAgIHJldHVybiBpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGlzSW5zdGFuY2Uob2JqLCB0eXBlKSB7CiAgICAgICAgcmV0dXJuIG9iaiBpbnN0YW5jZW9mIHR5cGUgfHwgb2JqICE9IG51bGwgJiYgb2JqLmNvbnN0cnVjdG9yICE9IG51bGwgJiYgb2JqLmNvbnN0cnVjdG9yLm5hbWUgIT0gbnVsbCAmJiBvYmouY29uc3RydWN0b3IubmFtZSA9PT0gdHlwZS5uYW1lOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIG51bWJlcklzTmFOKG9iaikgewogICAgICAgIHJldHVybiBvYmogIT09IG9iajsKICAgICAgfQogICAgICB2YXIgaGV4U2xpY2VMb29rdXBUYWJsZSA9IGZ1bmN0aW9uKCkgewogICAgICAgIGNvbnN0IGFscGhhYmV0ID0gIjAxMjM0NTY3ODlhYmNkZWYiOwogICAgICAgIGNvbnN0IHRhYmxlID0gbmV3IEFycmF5KDI1Nik7CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCAxNjsgKytpKSB7CiAgICAgICAgICBjb25zdCBpMTYgPSBpICogMTY7CiAgICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IDE2OyArK2opIHsKICAgICAgICAgICAgdGFibGVbaTE2ICsgal0gPSBhbHBoYWJldFtpXSArIGFscGhhYmV0W2pdOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gdGFibGU7CiAgICAgIH0oKTsKICAgICAgZnVuY3Rpb24gZGVmaW5lQmlnSW50TWV0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b3RvdHlwZSIsIHsKICAgICAgICAgIHdyaXRhYmxlOiBmYWxzZQogICAgICAgIH0pOwogICAgICAgIHJldHVybiBDb25zdHJ1Y3RvcjsKICAgICAgfQogICAgICBmdW5jdGlvbiBfaW5oZXJpdHMoc3ViQ2xhc3MsIHN1cGVyQ2xhc3MpIHsKICAgICAgICBpZiAodHlwZW9mIHN1cGVyQ2xhc3MgIT09ICJmdW5jdGlvbiIgJiYgc3VwZXJDbGFzcyAhPT0gbnVsbCkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiU3VwZXIgZXhwcmVzc2lvbiBtdXN0IGVpdGhlciBiZSBudWxsIG9yIGEgZnVuY3Rpb24iKTsKICAgICAgICB9CiAgICAgICAgc3ViQ2xhc3MucHJvdG90eXBlID0gT2JqZWN0LmNyZWF0ZShzdXBlckNsYXNzICYmIHN1cGVyQ2xhc3MucHJvdG90eXBlLCB7CiAgICAgICAgICBjb25zdHJ1Y3RvcjogewogICAgICAgICAgICB2YWx1ZTogc3ViQ2xhc3MsCiAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlLAogICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUKICAgICAgICAgIH0KICAgICAgICB9KTsKICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoc3ViQ2xhc3MsICJwcm90b3R5cGUiLCB7CiAgICAgICAgICB3cml0YWJsZTogZmFsc2UKICAgICAgICB9KTsKICAgICAgICBpZiAoc3VwZXJDbGFzcykKICAgICAgICAgIF9zZXRQcm90b3R5cGVPZihzdWJDbGFzcywgc3VwZXJDbGFzcyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mKG8pIHsKICAgICAgICBfZ2V0UHJvdG90eXBlT2YgPSBPYmplY3Quc2V0UHJvdG90eXBlT2YgPyBPYmplY3QuZ2V0UHJvdG90eXBlT2YuYmluZCgpIDogZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mMihvMikgewogICAgICAgICAgcmV0dXJuIG8yLl9fcHJvdG9fXyB8fCBPYmplY3QuZ2V0UHJvdG90eXBlT2YobzIpOwogICAgICAgIH07CiAgICAgICAgcmV0dXJuIF9nZXRQcm90b3R5cGVPZihvKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YobywgcCkgewogICAgICAgIF9zZXRQcm90b3R5cGVPZiA9IE9iamVjdC5zZXRQcm90b3R5cGVPZiA/IE9iamVjdC5zZXRQcm90b3R5cGVPZi5iaW5kKCkgOiBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YyKG8yLCBwMikgewogICAgICAgICAgbzIuX19wcm90b19fID0gcDI7CiAgICAgICAgICByZXR1cm4gbzI7CiAgICAgICAgfTsKICAgICAgICByZXR1cm4gX3NldFByb3RvdHlwZU9mKG8sIHApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9pc05hdGl2ZVJlZmxlY3RDb25zdHJ1Y3QoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ID09PSAidW5kZWZpbmVkIiB8fCAhUmVmbGVjdC5jb25zdHJ1Y3QpCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKFJlZmxlY3QuY29uc3RydWN0LnNoYW0pCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKHR5cGVvZiBQcm94eSA9PT0gImZ1bmN0aW9uIikKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIHRyeSB7CiAgICAgICAgICBCb29sZWFuLnByb3RvdHlwZS52YWx1ZU9mLmNhbGwoUmVmbGVjdC5jb25zdHJ1Y3QoQm9vbGVhbiwgW10sIGZ1bmN0aW9uKCkgewogICAgICAgICAgfSkpOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBfYXNz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dldFByb3RvdHlwZU9mKHRoaXMpLmNvbnN0cnVjdG9yOwogICAgICAgICAgICByZXN1bHQgPSBSZWZsZWN0LmNvbnN0cnVjdChTdXBlciwgYXJndW1lbnRzLCBOZXdUYXJnZXQpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmVzdWx0ID0gU3VwZXIuYXBwbHkodGhpcywgYXJndW1lbnRzKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBfcG9zc2libGVDb25zdHJ1Y3RvclJldHVybih0aGlzLCByZXN1bHQpOwogICAgICAgIH07CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX3N1cGVyUHJvcEJhc2Uob2JqZWN0LCBwcm9wZXJ0eSkgewogICAgICAgIHdoaWxlICghT2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eS5jYWxsKG9iamVjdCwgcHJvcGVydHkpKSB7CiAgICAgICAgICBvYmplY3QgPSBfZ2V0UHJvdG90eXBlT2Yob2JqZWN0KTsKICAgICAgICAgIGlmIChvYmplY3QgPT09IG51bGwpCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICByZXR1cm4gb2JqZWN0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9nZXQoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ICE9PSAidW5kZWZpbmVkIiAmJiBSZWZsZWN0LmdldCkgewogICAgICAgICAgX2dldCA9IFJlZmxlY3QuZ2V0LmJpbmQoKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgX2dldCA9IGZ1bmN0aW9uIF9nZXQyKHRhcmdldCwgcHJvcGVydHksIHJlY2VpdmVyKSB7CiAgICAgICAgICAgIHZhciBiYXNlID0gX3N1cGVyUHJvcEJhc2UodGFyZ2V0LCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmICghYmFzZSkKICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIHZhciBkZXNjID0gT2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcihiYXNlLCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmIChkZXNjLmdldCkgewogICAgICAgICAgICAgIHJldHVybiBkZXNjLmdldC5jYWxsKGFyZ3VtZW50cy5sZW5ndGggPCAzID8gdGFyZ2V0IDogcmVjZWl2ZXIpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBkZXNjLnZhbHVlOwogICAgICAgICAgfTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIF9nZXQuYXBwbHkodGhpcywgYXJndW1lbnRzKTsKICAgICAgfQogICAgICB2YXIgRW1pdHRlciA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbigpIHsKICAgICAgICBmdW5jdGlvbiBFbWl0dGVyMigpIHsKICAgICAgICAgIF9jbGFzc0NhbGxDaGVjayh0aGlzLCBFbWl0dGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgImxpc3RlbmVycyIsIHsKICAgICAgICAgICAgdmFsdWU6IHt9LAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEVtaXR0ZXIyLCBbewogICAgICAgICAga2V5OiAiYWRkRXZlbnRMaXN0ZW5lciIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWRkRXZlbnRMaXN0ZW5lcih0eXBlLCBjYWxsYmFjaywgb3B0aW9ucykgewogICAgICAgICAgICBpZiAoISh0eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHRoaXMubGlzdGVuZXJzW3R5cGVdID0gW107CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5saXN0ZW5lcnNbdHlwZV0ucHVzaCh7CiAgICAgICAgICAgICAgY2FsbGJhY2ssCiAgICAgICAgICAgICAgb3B0aW9ucwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJyZW1vdmVFdmVudExpc3RlbmVyIiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiByZW1vdmVFdmVudExpc3RlbmVyKHR5cGUsIGNhbGxiYWNrKSB7CiAgICAgICAgICAgIGlmICghKHR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW3R5cGVdOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIGlmIChzdGFja1tpXS5jYWxsYmFjayA9PT0gY2FsbGJhY2spIHsKICAgICAgICAgICAgICAgIHN0YWNrLnNwbGljZShpLCAxKTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJkaXNwYXRjaEV2ZW50IiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiBkaXNwYXRjaEV2ZW50KGV2ZW50KSB7CiAgICAgICAgICAgIGlmICghKGV2ZW50LnR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW2V2ZW50LnR5cGVdOwogICAgICAgICAgICB2YXIgc3RhY2tUb0NhbGwgPSBzdGFjay5zbGljZSgpOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrVG9DYWxsLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIHZhciBsaXN0ZW5lciA9IHN0YWNrVG9DYWxsW2ldOwogICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICBsaXN0ZW5lci5jYWxsYmFjay5jYWxsKHRoaXMsIGV2ZW50KTsKICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICBQcm9taXNlLnJlc29sdmUoKS50aGVuKGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChsaXN0ZW5lci5vcHRpb25zICYmIGxpc3RlbmVyLm9wdGlvbnMub25jZSkgewogICAgICAgICAgICAgICAgdGhpcy5yZW1vdmVFdmVudExpc3RlbmVyKGV2ZW50LnR5cGUsIGxpc3RlbmVyLmNhbGxiYWNrKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuICFldmVudC5kZWZhdWx0UHJldmVudGVkOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gRW1pdHRlcjI7CiAgICAgIH0oKTsKICAgICAgdmFyIEFib3J0U2lnbmFsID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKF9FbWl0dGVyKSB7CiAgICAgICAgX2luaGVyaXRzKEFib3J0U2lnbmFsMiwgX0VtaXR0ZXIpOwogICAgICAgIHZhciBfc3VwZXIgPSBfY3JlYXRlU3VwZXIoQWJvcnRTaWduYWwyKTsKICAgICAgICBmdW5jdGlvbiBBYm9ydFNpZ25hbDIoKSB7CiAgICAgICAgICB2YXIgX3RoaXM7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRTaWduYWwyKTsKICAgICAgICAgIF90aGlzID0gX3N1cGVyLmNhbGwodGhpcyk7CiAgICAgICAgICBpZiAoIV90aGlzLmxpc3RlbmVycykgewogICAgICAgICAgICBFbWl0dGVyLmNhbGwoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcykpOwogICAgICAgICAgfQogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KF9hc3NlcnRUaGlzSW5pdGlhbGl6ZWQoX3RoaXMpLCAiYWJvcnRlZCIsIHsKICAgICAgICAgICAgdmFsdWU6IGZhbHNlLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgIm9uYWJvcnQiLCB7CiAgICAgICAgICAgIHZhbHVlOiBudWxsLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgInJlYXNvbiIsIHsKICAgICAgICAgICAgdmFsdWU6IHZvaWQgMCwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICByZXR1cm4gX3RoaXM7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhBYm9ydFNpZ25hbDIsIFt7CiAgICAgICAgICBrZXk6ICJ0b1N0cmluZyIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gdG9TdHJpbmcoKSB7CiAgICAgICAgICAgIHJldHVybiAiW29iamVjdCBBYm9ydFNpZ25hbF0iOwogICAgICAgICAgfQogICAgICAgIH0sIHsKICAgICAgICAgIGtleTogImRpc3BhdGNoRXZlbnQiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGRpc3BhdGNoRXZlbnQoZXZlbnQpIHsKICAgICAgICAgICAgaWYgKGV2ZW50LnR5cGUgPT09ICJhYm9ydCIpIHsKICAgICAgICAgICAgICB0aGlzLmFib3J0ZWQgPSB0cnVlOwogICAgICAgICAgICAgIGlmICh0eXBlb2YgdGhpcy5vbmFib3J0ID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgICAgICB0aGlzLm9uYWJvcnQuY2FsbCh0aGlzLCBldmVudCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIF9nZXQoX2dldFByb3RvdHlwZU9mKEFib3J0U2lnbmFsMi5wcm90b3R5cGUpLCAiZGlzcGF0Y2hFdmVudCIsIHRoaXMpLmNhbGwodGhpcywgZXZlbnQpOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gQWJvcnRTaWduYWwyOwogICAgICB9KEVtaXR0ZXIpOwogICAgICB2YXIgQWJvcnRDb250cm9sbGVyID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKCkgewogICAgICAgIGZ1bmN0aW9uIEFib3J0Q29udHJvbGxlcjIoKSB7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRDb250cm9sbGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgInNpZ25hbCIsIHsKICAgICAgICAgICAgdmFsdWU6IG5ldyBBYm9ydFNpZ25hbCgpLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEFib3J0Q29udHJvbGxlcjIsIFt7CiAgICAgICAgICBrZXk6ICJhYm9ydCIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWJvcnQocmVhc29uKSB7CiAgICAgICAgICAgIHZhciBldmVudDsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBldmVudCA9IG5ldyBFdmVudCgiYWJvcnQiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIGlmICh0eXBlb2YgZG9jdW1lbnQgIT09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICBpZiAoIWRvY3VtZW50LmNyZWF0ZUV2ZW50KSB7CiAgICAgICAgICAgICAgICAgIGV2ZW50ID0gZG9jdW1lbnQuY3JlYXRlRXZlbnRPYmplY3QoKTsKICAgICAgICAgICAgICAgICAgZXZlbnQudHlwZSA9ICJhYm9ydCI7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBldmVudCA9IGRvY3VtZW50LmNyZWF0ZUV2ZW50KCJFdmVudCIpOwogICAgICAgICAgICAgICAgICBldmVudC5pbml0RXZlbnQoImFib3J0IiwgZmFsc2UsIGZhbHNlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZXZlbnQgPSB7CiAgICAgICAgICAgICAgICAgIHR5cGU6ICJhYm9ydCIsCiAgICAgICAgICAgICAgICAgIGJ1YmJsZXM6IGZhbHNlLAogICAgICAgICAgICAgICAgICBjYW5jZWxhYmxlOiBmYWxzZQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIHNpZ25hbFJlYXNvbiA9IHJlYXNvbjsKICAgICAgICAgICAgaWYgKHNpZ25hbFJlYXNvbiA9PT0gdm9pZCAwKSB7CiAgICAgICAgICAgICAgaWYgKHR5cGVvZiBkb2N1bWVudCA9PT0gInVuZGVmaW5lZCIpIHsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbi5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRE9NRXhjZXB0aW9uKCJzaWduYWwgaXMgYWJvcnRlZCB3aXRob3V0IHJlYXNvbiIpOwogICAgICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgICAgc2lnbmFsUmVhc29uLm5hbWUgPSAiQWJvcnRFcnJvciI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuc2lnbmFsLnJlYXNvbiA9IHNpZ25hbFJlYXNvbjsKICAgICAgICAgICAgdGhpcy5zaWduYWwuZGlzcGF0Y2hFdmVudChldmVudCk7CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAidG9TdHJpbmciLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gIltvYmplY3QgQWJvcnRDb250cm9sbGVyXSI7CiAgICAgICAgICB9CiAgICAgICAgfV0pOwogICAgICAgIHJldHVybiBBYm9ydENvbnRyb2xsZXIyOwogICAgICB9KCk7CiAgICAgIGlmICh0eXBlb2YgU3ltYm9sICE9PSAidW5kZWZpbmVkIiAmJiBTeW1ib2wudG9TdHJpbmdUYWcpIHsKICAgICAgICBBYm9ydENvbnRyb2xsZXIucHJvdG90eXBlW1N5bWJvbC50b1N0cmluZ1RhZ10gPSAiQWJvcnRDb250cm9sbGVyIjsKICAgICAgICBBYm9ydFNpZ25hbC5wcm90b3R5cGVbU3ltYm9sLnRvU3RyaW5nVGFnXSA9ICJBYm9ydFNpZ25hbCI7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcG9seWZpbGxOZWVkZWQoc2VsZjIpIHsKICAg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F0aXZlUmVxdWVzdChpbnB1dCwgaW5pdDIpOwogICAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHJlcXVlc3QsICJzaWduYWwiLCB7CiAgICAgICAgICAgICAgICB3cml0YWJsZTogZmFsc2UsCiAgICAgICAgICAgICAgICBlbnVtZXJhYmxlOiBmYWxzZSwKICAgICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICAgIHZhbHVlOiBzaWduYWwKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gcmVxdWVzdDsKICAgICAgICAgIH07CiAgICAgICAgICBSZXF1ZXN0LnByb3RvdHlwZSA9IE5hdGl2ZVJlcXVlc3QucHJvdG90eXBlOwogICAgICAgIH0KICAgICAgICB2YXIgcmVhbEZldGNoID0gZmV0Y2g7CiAgICAgICAgdmFyIGFib3J0YWJsZUZldGNoID0gZnVuY3Rpb24gYWJvcnRhYmxlRmV0Y2gyKGlucHV0LCBpbml0MikgewogICAgICAgICAgdmFyIHNpZ25hbCA9IFJlcXVlc3QgJiYgUmVxdWVzdC5wcm90b3R5cGUuaXNQcm90b3R5cGVPZihpbnB1dCkgPyBpbnB1dC5zaWduYWwgOiBpbml0MiA/IGluaXQyLnNpZ25hbCA6IHZvaWQgMDsKICAgICAgICAgIGlmIChzaWduYWwpIHsKICAgICAgICAgICAgdmFyIGFib3J0RXJyb3I7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgYWJvcnRFcnJvciA9IG5ldyBET01FeGNlcHRpb24oIkFib3J0ZWQiLCAiQWJvcnRFcnJvciIpOwogICAgICAgICAgICB9IGNhdGNoIChlcnIpIHsKICAgICAgICAgICAgICBhYm9ydEVycm9yID0gbmV3IEVycm9yKCJBYm9ydGVkIik7CiAgICAgICAgICAgICAgYWJvcnRFcnJvci5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzaWduYWwuYWJvcnRlZCkgewogICAgICAgICAgICAgIHJldHVybiBQcm9taXNlLnJlamVjdChhYm9ydEVycm9yKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB2YXIgY2FuY2VsbGF0aW9uID0gbmV3IFByb21pc2UoZnVuY3Rpb24oXywgcmVqZWN0KSB7CiAgICAgICAgICAgICAgc2lnbmFsLmFkZEV2ZW50TGlzdGVuZXIoImFib3J0IiwgZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gcmVqZWN0KGFib3J0RXJyb3IpOwogICAgICAgICAgICAgIH0sIHsKICAgICAgICAgICAgICAgIG9uY2U6IHRydWUKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIGlmIChpbml0MiAmJiBpbml0Mi5zaWduYWwpIHsKICAgICAgICAgICAgICBkZWxldGUgaW5pdDIuc2lnbmFsOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBQcm9taXNlLnJhY2UoW2NhbmNlbGxhdGlvbiwgcmVhbEZldGNoKGlucHV0LCBpbml0MildKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiByZWFsRmV0Y2goaW5wdXQsIGluaXQyKTsKICAgICAgICB9OwogICAgICAgIHJldHVybiB7CiAgICAgICAgICBmZXRjaDogYWJvcnRhYmxlRmV0Y2gsCiAgICAgICAgICBSZXF1ZXN0CiAgICAgICAgfTsKICAgICAgfQogICAgICBleHBvcnRzMi5BYm9ydENvbnRyb2xsZXIgPSBBYm9ydENvbnRyb2xsZXI7CiAgICAgIGV4cG9ydHMyLkFib3J0U2lnbmFsID0gQWJvcnRTaWduYWw7CiAgICAgIGV4cG9ydHMyLmFib3J0YWJsZUZldGNoID0gYWJvcnRhYmxlRmV0Y2hEZWNvcmF0b3I7CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9hYm9ydGF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7CiAgICAgIHZhciBhYm9ydGNvbnRyb2xsZXJfcG9ueWZpbGxfMSA9IHJlcXVpcmVfYWJvcnRjb250cm9sbGVyX3BvbnlmaWxsKCk7CiAgICAgIHZhciBOdWxsU2lnbmFsID0gY2xhc3MgewogICAgICB9OwogICAgICB2YXIgQWdncmVnYXRlQWJvcnRDb250cm9sbGVyID0gY2xhc3MgewogICAgICAgIGNvbnN0cnVjdG9yKCkgewogICAgICAgICAgdGhpcy5zaWduYWxzID0gbmV3IFNldCgpOwogICAgICAgICAgdGhpcy5hYm9ydENvbnRyb2xsZXIgPSBuZXcgYWJvcnRjb250cm9sbGVyX3BvbnlmaWxsXzEuQWJvcnRDb250cm9sbGVyKCk7CiAgICAgICAgfQogICAgICAgIGFkZFNpZ25hbChzaWduYWwgPSBuZXcgTnVsbFNpZ25hbCgpKSB7CiAgICAgICAgICBpZiAodGhpcy5zaWduYWwuYWJvcnRlZCkgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImNhbm5vdCBhZGQgYSBzaWduYWwsIGFscmVhZHkgYWJvcnRlZCEiKTsKICAgICAgICAgIH0KICAgICAgICAgIHRoaXMuc2lnbmFscy5hZGQoc2lnbmFsKTsKICAgICAgICAgIGlmIChzaWduYWwuYWJvcnRlZCkgewogICAgICAgICAgICB0aGlzLmhhbmRsZUFib3J0ZWQoc2lnbmFsKTsKICAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHNpZ25hbC5hZGRFdmVudExpc3RlbmVyID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgIHNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsICgpID0+IHsKICAgICAgICAgICAgICB0aGlzLmhhbmRsZUFib3J0ZWQoc2lnbmFsKTsKICAgICAgICAgICAgfSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGhhbmRsZUFib3J0ZWQoc2lnbmFsKSB7CiAgICAgICAgICB0aGlzLnNpZ25hbHMuZGVsZXRl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1c0NhbGxiYWNrKTsKICAgICAgICAgIGNvbnN0IG5ld0VudHJ5ID0gewogICAgICAgICAgICBhYm9ydGVyLAogICAgICAgICAgICBwcm9taXNlOiB0aGlzLmZpbGxDYWxsYmFjayhkYXRhLCBhYm9ydGVyLnNpZ25hbCwgKG1lc3NhZ2UpID0+IHsKICAgICAgICAgICAgICBzdGF0dXNSZXBvcnRlci5jYWxsYmFjayhtZXNzYWdlKTsKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIHNldHRsZWQ6IGZhbHNlLAogICAgICAgICAgICBzdGF0dXNSZXBvcnRlciwKICAgICAgICAgICAgZ2V0IGFib3J0ZWQoKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuYWJvcnRlci5zaWduYWwuYWJvcnRlZDsKICAgICAgICAgICAgfQogICAgICAgICAgfTsKICAgICAgICAgIG5ld0VudHJ5LmFib3J0ZXIuYWRkU2lnbmFsKHNpZ25hbCk7CiAgICAgICAgICBuZXdFbnRyeS5hYm9ydGVyLnNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsICgpID0+IHsKICAgICAgICAgICAgaWYgKCFuZXdFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgdGhpcy5ldmljdChrZXksIG5ld0VudHJ5KTsKICAgICAgICAgICAgfQogICAgICAgICAgfSk7CiAgICAgICAgICBuZXdFbnRyeS5wcm9taXNlLnRoZW4oKCkgPT4gewogICAgICAgICAgICBuZXdFbnRyeS5zZXR0bGVkID0gdHJ1ZTsKICAgICAgICAgIH0sICgpID0+IHsKICAgICAgICAgICAgbmV3RW50cnkuc2V0dGxlZCA9IHRydWU7CiAgICAgICAgICAgIHRoaXMuZXZpY3Qoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgICB9KS5jYXRjaCgoZSkgPT4gewogICAgICAgICAgICBjb25zb2xlLmVycm9yKGUpOwogICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgfSk7CiAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIG5ld0VudHJ5KTsKICAgICAgICB9CiAgICAgICAgc3RhdGljIGNoZWNrU2luZ2xlUHJvbWlzZShwcm9taXNlLCBzaWduYWwpIHsKICAgICAgICAgIGZ1bmN0aW9uIGNoZWNrRm9yU2luZ2xlQWJvcnQoKSB7CiAgICAgICAgICAgIGlmIChzaWduYWwgJiYgc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICB0aHJvdyBPYmplY3QuYXNzaWduKG5ldyBFcnJvcigiYWJvcnRlZCIpLCB7IGNvZGU6ICJFUlJfQUJPUlRFRCIgfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBwcm9taXNlLnRoZW4oKHJlc3VsdCkgPT4gewogICAgICAgICAgICBjaGVja0ZvclNpbmdsZUFib3J0KCk7CiAgICAgICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgICAgICB9LCAoZXJyb3IpID0+IHsKICAgICAgICAgICAgY2hlY2tGb3JTaW5nbGVBYm9ydCgpOwogICAgICAgICAgICB0aHJvdyBlcnJvcjsKICAgICAgICAgIH0pOwogICAgICAgIH0KICAgICAgICBoYXMoa2V5KSB7CiAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5oYXMoa2V5KTsKICAgICAgICB9CiAgICAgICAgZ2V0KGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjaykgewogICAgICAgICAgaWYgKCFzaWduYWwgJiYgZGF0YSBpbnN0YW5jZW9mIGFib3J0Y29udHJvbGxlcl9wb255ZmlsbF8xLkFib3J0U2lnbmFsKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoInNlY29uZCBnZXQgYXJndW1lbnQgYXBwZWFycyB0byBiZSBhbiBBYm9ydFNpZ25hbCwgcGVyaGFwcyB5b3UgbWVhbnQgdG8gcGFzcyBgbnVsbGAgZm9yIHRoZSBmaWxsIGRhdGE/Iik7CiAgICAgICAgIC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ICAgdGhpcy5tYXhTaXplID0gb3B0aW9ucy5tYXhTaXplOwogICAgICAgICAgdGhpcy5jYWNoZSA9IG5ldyBNYXAoKTsKICAgICAgICAgIHRoaXMub2xkQ2FjaGUgPSBuZXcgTWFwKCk7CiAgICAgICAgICB0aGlzLl9zaXplID0gMDsKICAgICAgICB9CiAgICAgICAgX3NldChrZXksIHZhbHVlKSB7CiAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIHZhbHVlKTsKICAgICAgICAgIHRoaXMuX3NpemUrKzsKICAgICAgICAgIGlmICh0aGlzLl9zaXplID49IHRoaXMubWF4U2l6ZSkgewogICAgICAgICAgICB0aGlzLl9zaXplID0gMDsKICAgICAgICAgICAgdGhpcy5vbGRDYWNoZSA9IHRoaXMuY2FjaGU7CiAgICAgICAgICAgIHRoaXMuY2FjaGUgPSBuZXcgTWFwKCk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGdldChrZXkpIHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzLmNhY2hlLmdldChrZXkpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHRoaXMub2xkQ2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgY29uc3QgdmFsdWUgPSB0aGlzLm9sZENhY2hlLmdldChrZXkpOwogICAgICAgICAgICB0aGlzLm9sZENhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgICB0aGlzLl9zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICAgIHJldHVybiB2YWx1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgc2V0KGtleSwgdmFsdWUpIHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHRoaXMuY2FjaGUuc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdGhpcy5fc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgfQogICAgICAgIGhhcyhrZXkpIHsKICAgICAgICAgIHJldHVybiB0aGlzLmNhY2hlLmhhcyhrZXkpIHx8IHRoaXMub2xkQ2FjaGUuaGFzKGtleSk7CiAgICAgICAgfQogICAgICAgIHBlZWsoa2V5KSB7CiAgICAgICAgICBpZiAodGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5nZXQoa2V5KTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0aGlzLm9sZENhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzLm9sZENhY2hlLmdldChrZXkpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBkZWxldGUoa2V5KSB7CiAgICAgICAgICBjb25zdCBkZWxldGVkID0gdGhpcy5jYWNoZS5kZWxldGUoa2V5KTsKICAgICAgICAgIGlmIChkZWxldGVkKSB7CiAgICAgICAgICAgIHRoaXMuX3NpemUtLTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiB0aGlzLm9sZENhY2hlLmRlbGV0ZShrZXkpIHx8IGRlbGV0ZWQ7CiAgICAgICAgfQogICAgICAgIGNsZWFyKCkgewogICAgICAgICAgdGhpcy5jYWNoZS5jbGVhcigpOwogICAgICAgICAgdGhpcy5vbGRDYWNoZS5jbGVhcigpOwogICAgICAgICAgdGhpcy5fc2l6ZSA9IDA7CiAgICAgICAgfQogICAgICAgICprZXlzKCkgewogICAgICAgICAgZm9yIChjb25zdCBba2V5XSBvZiB0aGlzKSB7CiAgICAgICAgICAgIHlpZWxkIGtleTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgKnZhbHVlcygpIHsKICAgICAgICAgIGZvciAoY29uc3QgWywgdmFsdWVdIG9mIHRoaXMpIHsKICAgICAgICAgICAgeWllbGQgdmFsdWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgICpbU3ltYm9sLml0ZXJhdG9yXSgpIHsKICAgICAgICAgIGZvciAoY29uc3QgaXRlbSBvZiB0aGlzLmNhY2hlKSB7CiAgICAgICAgICAgIHlpZWxkIGl0ZW07CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKGNvbnN0IGl0ZW0gb2YgdGhpcy5vbGRDYWNoZSkgewogICAgICAgICAgICBjb25zdCBba2V5XSA9IGl0ZW07CiAgICAgICAgICAgIGlmICghdGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICAgIHlpZWxkIGl0ZW07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZ2V0IHNpemUoKSB7CiAgICAgICAgICBsZXQgb2xkQ2FjaGVTaXplID0gMDsKICAgICAgICAgIGZvciAoY29uc3Qga2V5IG9mIHRoaXMub2xkQ2FjaGUua2V5cygpKSB7CiAgICAgICAgICAgIGlmICghdGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICAgIG9sZENhY2hlU2l6ZSsrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gdGhpcy5fc2l6ZSArIG9sZENhY2hlU2l6ZTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIG1vZHVsZTIuZXhwb3J0cyA9IFF1aWNrTFJVOwogICAgfQogIH0pOwoKICAvLyAoZGlzYWJsZWQpOm5vZGVfbW9kdWxlcy8ucG5wbS9nZW5lcmljLWZpbGVoYW5kbGVAMy4xLjEvbm9kZV9tb2R1bGVzL2dlbmVyaWMtZmlsZWhhbmRsZS9lc20vbG9jYWxGaWxlCiAgdmFyIHJlcXVpcmVfbG9jYWxGaWxlID0gX19jb21tb25KUyh7CiAgICAiKGRpc2FibGVkKTpub2RlX21vZHVsZXMvLnBucG0vZ2VuZXJpYy1maWxlaGFuZGxlQDMuMS4xL25vZGVfbW9kdWxlcy9nZW5lcmljLWZpbGVoYW5kbGUvZXNtL2xvY2FsRmlsZSIoKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi91dGlscy9jb21tb24uanMKICB2YXIgcmVxdWlyZV9jb21tb24gPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3V0aWxzL2NvbW1vbi5qcyIoZXhwb3J0czIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIHZhciBUWVBFRF9PSyA9IHR5cGVvZiBVaW50OEFycmF5ICE9PSAidW5kZWZpbmVkIiAmJiB0eXBlb2YgVWludDE2QXJyYXkgIT09ICJ1bmRlZmluZWQiICYmIHR5cGVvZiBJbnQzMkFycmF5ICE9PSAidW5kZWZpbmVkIjsKICAgICAgZnVuY3Rpb24gX2hhcyhvYmosIGtleSkgewogICAgICAgIHJldHVybiBPYmplY3QucHJvdG90eXBlLmhhc093blByb3BlcnR5LmNhbGwob2JqLCBrZXkpOwogICAgICB9CiAgICAgIGV4cG9ydHMyLmFzc2lnbiA9IGZ1bmN0aW9uKG9iaikgewogICAgICAgIHZhciBzb3VyY2VzID0gQXJyYXkucHJvdG90eXBlLnNsaWNlLmNhbGwoYXJndW1lbnRzLCAxKTsKICAgICAgICB3aGlsZSAoc291cmNlcy5sZW5ndGgpIHsKICAgICAgICAgIHZhciBzb3VyY2UgPSBzb3VyY2VzLnNoaWZ0KCk7CiAgICAgICAgICBpZiAoIXNvdXJjZSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0eXBlb2Ygc291cmNlICE9PSAib2JqZWN0IikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKHNvdXJjZSArICJtdXN0IGJlIG5vbi1vYmplY3QiKTsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAodmFyIHAgaW4gc291cmNlKSB7CiAgICAgICAgICAgIGlmIChfaGFzKHNvdXJjZSwgcCkpIHsKICAgICAgICAgICAgICBvYmpbcF0gPSBzb3VyY2VbcF07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIG9iajsKICAgICAgfTsKICAgICAgZXhwb3J0czIuc2hyaW5rQnVmID0gZnVuY3Rpb24oYnVmLCBzaXplKSB7CiAgICAgICAgaWYgKGJ1Zi5sZW5ndGggPT09IHNpemUpIHsKICAgICAgICAgIHJldHVybiBidWY7CiAgICAgICAgfQogICAgICAgIGlmIChidWYuc3ViYXJyYXkpIHsKICAgICAgICAgIHJldHVybiBidWYuc3ViYXJyYXkoMCwgc2l6ZSk7CiAgICAgICAgfQogICAgICAgIGJ1Zi5sZW5ndGggPSBzaXplOwogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIHZhciBmblR5cGVkID0gewogICAgICAgIGFycmF5U2V0OiBmdW5jdGlvbihkZXN0LCBzcmMsIHNyY19vZmZzLCBsZW4sIGRlc3Rfb2ZmcykgewogICAgICAgICAgaWYgKHNyYy5zdWJhcnJheSAmJiBkZXN0LnN1YmFycmF5KSB7CiAgICAgICAgICAgIGRlc3Quc2V0KHNyYy5zdWJhcnJheShzcmNfb2Zmcywgc3JjX29mZnMgKyBsZW4pLCBkZXN0X29mZnMpOwogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgICAgIGRlc3RbZGVzdF9vZmZzICsgaV0gPSBzcmNbc3JjX29mZnMgKyBpXTsKICAgICAgICAgIH0KICAgICAgICB9LAogICAgICAgIGZsYXR0ZW5DaHVua3M6IGZ1bmN0aW9uKGNodW5rcykgewogICAgICAgICAgdmFyIGksIGwsIGxlbiwgcG9zLCBjaHVuaywgcmVzdWx0OwogICAgICAgICAgbGVuID0gMDsKICAgICAgICAgIGZvciAoaSA9IDAsIGwgPSBjaHVua3MubGVuZ3RoOyBpIDwgbDsgaSsrKSB7CiAgICAgICAgICAgIGxlbiArPSBjaHVua3NbaV0ubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgICAgcmVzdWx0ID0gbmV3IFVpbnQ4QXJyYXkobGVuKTsKICAgICAgICAgIHBvcyA9IDA7CiAgICAgICAgICBmb3IgKGkgPSAwLCBsID0gY2h1bmtzLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICBjaHVuayA9IGNodW5rc1tpXTsKICAgICAgICAgICAgcmVzdWx0LnNldChjaHVuaywgcG9zKTsKICAgICAgICAgICAgcG9zICs9IGNodW5rLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgICAgfQogICAgICB9OwogICAgICB2YXIgZm5VbnR5cGVkID0gewogICAgICAgIGFycmF5U2V0OiBmdW5jdGlvbihkZXN0LCBzcmMsIHNyY19vZmZzLCBsZW4sIGRlc3Rfb2ZmcykgewogICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgICBkZXN0W2Rlc3Rfb2ZmcyArIGldID0gc3JjW3NyY19vZmZzICsgaV07CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBmbGF0dGVuQ2h1bmtzOiBmdW5jdGlvbihjaHVua3MpIHsKICAgICAgICAgIHJldHVybiBbXS5jb25jYXQuYXBwbHkoW10sIGNodW5rcyk7CiAgICAgICAgfQogICAgICB9OwogICAgICBleHBvcnRzMi5zZXRUeXBlZCA9IGZ1bmN0aW9uKG9uKSB7CiAgICAgICAgaWYgKG9uKSB7CiAgICAgICAgICBleHBvcnRzMi5CdWY4ID0gVWludDhBcnJheTsKICAgICAgICAgIGV4cG9ydHMyLkJ1ZjE2ID0gVWludDE2QXJyYXk7CiAgICAgICAgICBleHBvcnRzMi5CdWYzMiA9IEludDMyQXJyYXk7CiAgICAgICAgICBleHBvcnRzMi5hc3NpZ24oZXhwb3J0czIsIGZuVHlwZWQpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBleHBvcnRzMi5CdWY4ID0gQXJyYXk7CiAgICAgICAgICBleHBvcnRzMi5CdWYxNiA9IEFycmF5OwogICAgICAgICAgZXhwb3J0czIuQnVmMzIgPSBBcnJheTsKICAgICAgICAgIGV4cG9ydHMyLmFzc2lnbihleHBvcnRzMiwgZm5VbnR5cGVkKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLnNldFR5cGVkKFRZUEVEX09LKTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL3RyZWVzLmpzCiAgdmFyIHJlcXVpcmVfdHJlZXMgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvdHJlZXMuanMiKGV4cG9ydHMyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgdXRpbHMgPSByZXF1aXJlX2NvbW1vbigpOwogICAgICB2YXIgWl9GSVhFRCA9IDQ7CiAgICAgIHZhciBaX0JJTkFSWSA9IDA7CiAgICAgIHZhciBaX1RFWFQgPSAxOwogICAgICB2YXIgWl9VTktOT1dOID0gMjsKICAgICAgZnVuY3Rpb24gemVybyhidWYpIHsKICAgICAgICB2YXIgbGVuID0gYnVmLmxlbmd0aDsKICAgICAgICB3aGlsZSAoLS1sZW4gPj0gMCkgewogICAgICAgICAgYnVmW2xlbl0gPSAwOwogICAgICAgIH0KICAgICAgfQogICAgICB2YXIgU1RPUkVEX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iAgICAgICAgICBzLmJpX2J1ZiB8PSB2YWx1ZSA8PCBzLmJpX3ZhbGlkICYgNjU1MzU7CiAgICAgICAgICBzLmJpX3ZhbGlkICs9IGxlbmd0aDsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2VuZF9jb2RlKHMsIGMsIHRyZWUpIHsKICAgICAgICBzZW5kX2JpdHMocywgdHJlZVtjICogMl0sIHRyZWVbYyAqIDIgKyAxXSk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYmlfcmV2ZXJzZShjb2RlLCBsZW4pIHsKICAgICAgICB2YXIgcmVzID0gMDsKICAgICAgICBkbyB7CiAgICAgICAgICByZXMgfD0gY29kZSAmIDE7CiAgICAgICAgICBjb2RlID4+Pj0gMTsKICAgICAgICAgIHJlcyA8PD0gMTsKICAgICAgICB9IHdoaWxlICgtLWxlbiA+IDApOwogICAgICAgIHJldHVybiByZXMgPj4+IDE7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYmlfZmx1c2gocykgewogICAgICAgIGlmIChzLmJpX3ZhbGlkID09PSAxNikgewogICAgICAgICAgcHV0X3Nob3J0KHMsIHMuYmlfYnVmKTsKICAgICAgICAgIHMuYmlfYnVmID0gMDsKICAgICAgICAgIHMuYmlfdmFsaWQgPSAwOwogICAgICAgIH0gZWxzZSBpZiAocy5iaV92YWxpZCA+PSA4KSB7CiAgICAgICAgICBzLnBlbmRpbmdfYnVmW3MucGVuZGluZysrXSA9IHMuYmlfYnVmICYgMjU1OwogICAgICAgICAgcy5iaV9idWYgPj49IDg7CiAgICAgICAgICBzLmJpX3ZhbGlkIC09IDg7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGdlbl9iaXRsZW4ocywgZGVzYykgewogICAgICAgIHZhciB0cmVlID0gZGVzYy5keW5fdHJlZTsKICAgICAgICB2YXIgbWF4X2NvZGUgPSBkZXNjLm1heF9jb2RlOwogICAgICAgIHZhciBzdHJlZSA9IGRlc2Muc3RhdF9kZXNjLnN0YXRpY190cmVlOwogICAgICAgIHZhciBoYXNfc3RyZWUgPSBkZXNjLnN0YXRfZGVzYy5oYXNfc3RyZWU7CiAgICAgICAgdmFyIGV4dHJhID0gZGVzYy5zdGF0X2Rlc2MuZXh0cmFfYml0czsKICAgICAgICB2YXIgYmFzZSA9IGRlc2Muc3RhdF9kZXNjLmV4dHJhX2Jhc2U7CiAgICAgICAgdmFyIG1heF9sZW5ndGggPSBkZXNjLnN0YXRfZGVzYy5tYXhfbGVuZ3RoOwogICAgICAgIHZhciBoOwogICAgICAgIHZhciBuLCBtOwogICAgICAgIHZhciBiaXRzOwogICAgICAgIHZhciB4Yml0czsKICAgICAgICB2YXIgZjsKICAgICAgICB2YXIgb3ZlcmZsb3cgPSAwOwogICAgICAgIGZvciAoYml0cyA9IDA7IGJpdHMgPD0gTUFYX0JJVFM7IGJpdHMrKykgewogICAgICAgICAgcy5ibF9jb3VudFtiaXRzXSA9IDA7CiAgICAgICAgfQogICAgICAgIHRyZWVbcy5oZWFwW3MuaGVhcF9tYXhdICogMiArIDFdID0gMDsKICAgICAgICBmb3IgKGggPSBzLmhlYXBfbWF4ICsgMTsgaCA8IEhFQVBfU0laRTsgaCsrKSB7CiAgICAgICAgICBuID0gcy5oZWFwW2hdOwogICAgICAgICAgYml0cyA9IHRyZWVbdHJlZVtuICogMiArIDFdICogMiArIDFdICsgMTsKICAgICAgICAgIGlmIChiaXRzID4gbWF4X2xlbmd0aCkgewogICAgICAgICAgICBiaXRzID0gbWF4X2xlbmd0aDsKICAgICAgICAgICAgb3ZlcmZsb3crKzsKICAgICAgICAgIH0KICAgICAgICAgIHRyZWVbbiAqIDIgKyAxXSA9IGJpdHM7CiAgICAgICAgICBpZiAobiA+IG1heF9jb2RlKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgcy5ibF9jb3VudFtiaXRzXSsrOwogICAgICAgICAgeGJpdHMgPSAwOwogICAgICAgICAgaWYgKG4gPj0gYmFzZSkgewogICAgICAgICAgICB4Yml0cyA9IGV4dHJhW24gLSBiYXNlXTsKICAgICAgICAgIH0KICAgICAgICAgIGYgPSB0cmVlW24gKiAyXTsKICAgICAgICAgIHMub3B0X2xlbiArPSBmICogKGJpdHMgKyB4Yml0cyk7CiAgICAgICAgICBpZiAoaGFzX3N0cmVlKSB7CiAgICAgICAgICAgIHMuc3RhdGljX2xlbiArPSBmICogKHN0cmVlW24gKiAyICsgMV0gKyB4Yml0cyk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChvdmVyZmxvdyA9PT0gMCkgewogICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KICAgICAgICBkbyB7CiAgICAgICAgICBiaXRzID0gbWF4X2xlbmd0aCAtIDE7CiAgICAgICAgICB3aGlsZSAocy5ibF9jb3VudFtiaXRzXSA9PT0gMCkgewogICAgICAgICAgICBiaXRzLS07CiAgICAgICAgICB9CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHNdLS07CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHMgKyAxXSArPSAyOwogICAgICAgICAgcy5ibF9jb3VudFttYXhfbGVuZ3RoXS0tOwogICAgICAgICAgb3ZlcmZsb3cgLT0gMjsKICAgICAgICB9IHdoaWxlIChvdmVyZmxvdyA+IDApOwogICAgICAgIGZvciAoYml0cyA9IG1heF9sZW5ndGg7IGJpdHMgIT09IDA7IGJpdHMtLSkgewogICAgICAgICAgbiA9IHMuYmxfY291bnRbYml0c107CiAgICAgICAgICB3aGlsZSAobiAhPT0gMCkgewogICAgICAgICAgICBtID0gcy5oZWFwWy0taF07CiAgICAgICAgICAgIGlmIChtID4gbWF4X2NvZGUpIHsKICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodHJlZVttICogMiArIDFdICE9PSBiaXRzKSB7CiAgICAgICAgICAgICAgcy5vcHRfbGVuICs9IChiaXRzIC0gdHJlZVttICogMiArIDFdKSAqIHRyZWVbbSAqIDJdOwogICAgICAgICAgICAgIHRyZWVbbSAqIDIgKyAxXSA9IGJpdHM7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbi0tOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBnZW5fY29kZXModHJlZSwgbWF4X2NvZGUsIGJsX2NvdW50KSB7CiAgICAgICAgdmFyIG5leHRfY29kZSA9IG5ldyBBcnJheShNQVhfQklUUyArIDEpOwogICAgICAgIHZhciBjb2RlID0gMDsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgbjsKICAgICAgICBmb3IgKGJpdHMgPSAxOyBiaXRzIDw9IE1BWF9CSVRTOyBiaXRzKyspIHsKICAgICAgICAgIG5leHRfY29kZVtiaXRzXSA9IGNvZGUgPSBjb2RlICsgYmxfY291bnRbYml0cyAtIDFdIDw8IDE7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPD0gbWF4X2NvZGU7IG4rKykgewogICAgICAgICAgdmFyIGxlbiA9IHRyZWVbbiAqIDIgKyAxXTsKICAgICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICB0cmVlW24gKiAyXSA9IGJpX3JldmVyc2UobmV4dF9jb2RlW2xlbl0rKywgbGVuKTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdHJfc3RhdGljX2luaXQoKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIGxlbmd0aDsKICAgICAgICB2YXIgY29kZTsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgYmxfY291bnQgPSBuZXcgQXJyYXkoTUFYX0JJVFMgKyAxKTsKICAgICAgICBsZW5ndGggPSAwOwogICAgICAgIGZvciAoY29kZSA9IDA7IGNvZGUgPCBMRU5HVEhfQ09ERVMgLSAxOyBjb2RlKyspIHsKICAgICAgICAgIGJhc2VfbGVuZ3RoW2NvZGVdID0gbGVuZ3RoOwogICAgICAgICAgZm9yIChuID0gMDsgbiA8IDEgPDwgZXh0cmFfbGJpdHNbY29kZV07IG4rKykgewogICAgICAgICAgICBfbGVuZ3RoX2NvZGVbbGVuZ3RoKytdID0gY29kZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgX2xlbmd0aF9jb2RlW2xlbmd0aCAtIDFdID0gY29kZTsKICAgICAgICBkaXN0ID0gMDsKICAgICAgICBmb3IgKGNvZGUgPSAwOyBjb2RlIDwgMTY7IGNvZGUrKykgewogICAgICAgICAgYmFzZV9kaXN0W2NvZGVdID0gZGlzdDsKICAgICAgICAgIGZvciAobiA9IDA7IG4gPCAxIDw8IGV4dHJhX2RiaXRzW2NvZGVdOyBuKyspIHsKICAgICAgICAgICAgX2Rpc3RfY29kZVtkaXN0KytdID0gY29kZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZGlzdCA+Pj0gNzsKICAgICAgICBmb3IgKDsgY29kZSA8IERfQ09ERVM7IGNvZGUrKykgewogICAgICAgICAgYmFzZV9kaXN0W2NvZGVdID0gZGlzdCA8PCA3OwogICAgICAgICAgZm9yIChuID0gMDsgbiA8IDEgPDwgZXh0cmFfZGJpdHNbY29kZV0gLSA3OyBuKyspIHsKICAgICAgICAgICAgX2Rpc3RfY29kZVsyNTYgKyBkaXN0KytdID0gY29kZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZm9yIChiaXRzID0gMDsgYml0cyA8PSBNQVhfQklUUzsgYml0cysrKSB7CiAgICAgICAgICBibF9jb3VudFtiaXRzXSA9IDA7CiAgICAgICAgfQogICAgICAgIG4gPSAwOwogICAgICAgIHdoaWxlIChuIDw9IDE0MykgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA4OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbOF0rKzsKICAgICAgICB9CiAgICAgICAgd2hpbGUgKG4gPD0gMjU1KSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDk7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs5XSsrOwogICAgICAgIH0KICAgICAgICB3aGlsZSAobiA8PSAyNzkpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gNzsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzddKys7CiAgICAgICAgfQogICAgICAgIHdoaWxlIChuIDw9IDI4NykgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA4OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbOF0rKzsKICAgICAgICB9CiAgICAgICAgZ2VuX2NvZGVzKHN0YXRpY19sdHJlZSwgTF9DT0RFUyArIDEsIGJsX2NvdW50KTsKICAgICAgICBmb3IgKG4gPSAwOyBuIDwgRF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzdGF0aWNfZHRyZWVbbiAqIDIgKyAxXSA9IDU7CiAgICAgICAgICBzdGF0aWNfZHRyZWVbbiAqIDJdID0gYmlfcmV2ZXJzZShuLCA1KTsKICAgICAgICB9CiAgICAgICAgc3RhdGljX2xfZGVzYyA9IG5ldyBTdGF0aWNUcmVlRGVzYyhzdGF0aWNfbHRyZWUsIGV4dHJhX2xiaXRzLCBMSVRFUkFMUyArIDEsIExfQ09ERVMsIE1BWF9CSVRTKTsKICAgICAgICBzdGF0aWNfZF9kZXNjID0gbmV3IFN0YXRpY1RyZWVEZXNjKHN0YXRpY19kdHJlZSwgZXh0cmFfZGJpdHMsIDAsIERfQ09ERVMsIE1BWF9CSVRTKTsKICAgICAgICBzdGF0aWNfYmxfZGVzYyA9IG5ldyBTdGF0aWNUcmVlRGVzYyhuZXcgQXJyYXkoMCksIGV4dHJhX2JsYml0cywgMCwgQkxfQ09ERVMsIE1BWF9CTF9CSVRTKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbml0X2Jsb2NrKHMpIHsKICAgICAgICB2YXIgbjsKICAgICAgICBmb3IgKG4gPSAwOyBuIDwgTF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzLmR5bl9sdHJlZVtuICogMl0gPSAwOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDwgRF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzLmR5bl9kdHJlZVtuICogMl0gPSAwOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDwgQkxfQ09ERVM7IG4rKykgewogICAgICAgICAgcy5ibF90cmVlW24gKiAyXSA9IDA7CiAgICAgICAgfQogICAgICAgIHMuZHluX2x0cmVlW0VORF9CTE9DSyAqIDJdID0gMTsKICAgICAgICBzLm9wdF9sZW4gPSBzLnN0YXRpY19sZW4gPSAwOwogICAgICAgIHMubGFzdF9saXQgPSBzLm1hdGNoZXMgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJpX3dpbmR1cChzKSB7CiAgICAgICAgaWYgKHMuYmlfdmFsaWQgPiA4KSB7CiAgICAgICAgICBwdXRfc2hvcnQocywgcy5iaV9idWYpOwogICAgICAgIH0gZWxzZSBpZiAocy5iaV92YWxpZCA+IDApIHsKICAgICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gcy5iaV9idWY7CiAgICAgICAgfQogICAgICAgIHMuYmlfYnVmID0gMDsKICAgICAgICBzLmJpX3ZhbGlkID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBjb3B5X2Jsb2NrKHMsIGJ1ZiwgbGVuLCBoZWFkZXIpIHsKICAgICAgICBiaV93aW5kdXAocyk7CiAgICAgICAgaWYgKGhlYWRlcikgewogICAgICAgICAgcHV0X3Nob3J0KHMsIGxlbik7CiAgICAgICAgICBwdXRfc2hvcnQocywgfmxlbik7CiAgICAgICAgfQogICAgICAgIHV0aWxzLmFycmF5U2V0KHMucGVuZGluZ19idWYsIHMud2luZG93LCBidWYsIGxlbiwgcy5wZW5kaW5nKTsKICAgICAgICBzLnBlbmRpbmcgKz0gbGVuOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNtYWxsZXIodHJlZSwgbiwgbSwgZGVwdGgpIHsKICAgICAgICB2YXIgX24yID0gbiAqIDI7CiAgICAgICAgdmFyIF9tMiA9IG0gKiAyOwogICAgICAgIHJldHVybiB0cmVlW19uMl0gPCB0cmVlW19tMl0gfHwgdHJlZVtfbjJdID09PSB0cmVlW19tMl0gJiYgZGVwdGhbbl0gPD0gZGVwdGhbbV07CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcHFkb3duaGVhcChzLCB0cmVlLCBrKSB7CiAgICAgICAgdmFyIHYgPSBzLmhlYXBba107CiAgICAgICAgdmFyIGogPSBrIDw8IDE7CiAgICAgICAgd2hpbGUgKGogPD0gcy5oZWFwX2xlbikgewogICAgICAgICAgaWYgKGogPCBzLmhlYXBfbGVuICYmIHNtYWxsZXIodHJlZSwgcy5oZWFwW2ogKyAxXSwgcy5oZWFwW2pdLCBzLmRlcHRoKSkgewogICAgICAgICAgICBqKys7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc21hbGxlcih0cmVlLCB2LCBzLmhlYXBbal0sIHMuZGVwdGgpKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgcy5oZWFwW2tdID0gcy5oZWFwW2pdOwogICAgICAgICAgayA9IGo7CiAgICAgICAgICBqIDw8PSAxOwogICAgICAgIH0KICAgICAgICBzLmhlYXBba10gPSB2OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGNvbXByZXNzX2Jsb2NrKHMsIGx0cmVlLCBkdHJlZSkgewogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBsYzsKICAgICAgICB2YXIgbHggPSAwOwogICAgICAgIHZhciBjb2RlOwogICAgICAgIHZhciBleHRyYTsKICAgICAgICBpZiAocy5sYXN0X2xpdCAhPT0gMCkgewogICAgICAgICAgZG8gewogICAgICAgICAgICBkaXN0ID0gcy5wZW5kaW5nX2J1ZltzLmRfYnVmICsgbHggKiAyXSA8PCA4IHwgcy5wZW5kaW5nX2J1ZltzLmRfYnVmICsgbHggKiAyICsgMV07CiAgICAgICAgICAgIGxjID0gcy5wZW5kaW5nX2J1ZltzLmxfYnVmICsgbHhdOwogICAgICAgICAgICBseCsrOwogICAgICAgICAgICBpZiAoZGlzdCA9PT0gMCkgewogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBsYywgbHRyZWUpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGNvZGUgPSBfbGVuZ3RoX2NvZGVbbGNdOwogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjb2RlICsgTElURVJBTFMgKyAxLCBsdHJlZSk7CiAgICAgICAgICAgICAgZXh0cmEgPSBleHRyYV9sYml0c1tjb2RlXTsKICAgICAgICAgICAgICBpZiAoZXh0cmEgIT09IDApIHsKICAgICAgICAgICAgICAgIGxjIC09IGJhc2VfbGVuZ3RoW2NvZGVdOwogICAgICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGxjLCBleHRyYSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGRpc3QtLTsKICAgICAgICAgICAgICBjb2RlID0gZF9jb2RlKGRpc3QpOwogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjb2RlLCBkdHJlZSk7CiAgICAgICAgICAgICAgZXh0cmEgPSBleHRyYV9kYml0c1tjb2RlXTsKICAgICAgICAgICAgICBpZiAoZXh0cmEgIT09IDApIHsKICAgICAgICAgICAgICAgIGRpc3QgLT0gYmFzZV9kaXN0W2NvZGVdOwogICAgICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGRpc3QsIGV4dHJhKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gd2hpbGUgKGx4IDwgcy5sYXN0X2xpdCk7CiAgICAgICAgfQogICAgICAgIHNlbmRfY29kZShzLCBFTkRfQkxPQ0ssIGx0cmVlKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBidWlsZF90cmVlKHMsIGRlc2MpIHsKICAgICAgICB2YXIgdHJlZSA9IGRlc2MuZHluX3RyZWU7CiAgICAgICAgdmFyIHN0cmVlID0gZGVzYy5zdGF0X2Rlc2Muc3RhdGljX3RyZWU7CiAgICAgICAgdmFyIGhhc19zdHJlZSA9IGRlc2Muc3RhdF9kZXNjLmhhc19zdHJlZTsKICAgICAgICB2YXIgZWxlbXMgPSBkZXNjLnN0YXRfZGVzYy5lbGVtczsKICAgICAgICB2YXIgbiwgbTsKICAgICAgICB2YXIgbWF4X2NvZGUgPSAtMTsKICAgICAgICB2YXIgbm9kZTsKICAgICAgICBzLmhlYXBfbGVuID0gMDsKICAgICAgICBzLmhlYXBfbWF4ID0gSEVBUF9TSVpFOwogICAgICAgIGZvciAobiA9IDA7IG4gPCBlbGVtczsgbisrKSB7CiAgICAgICAgICBpZiAodHJlZVtuICogMl0gIT09IDApIHsKICAgICAgICAgICAgcy5oZWFwWysrcy5oZWFwX2xlbl0gPSBtYXhfY29kZSA9IG47CiAgICAgICAgICAgIHMuZGVwdGhbbl0gPSAwOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdHJlZVtuICogMiArIDFdID0gMDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgd2hpbGUgKHMuaGVhcF9sZW4gPCAyKSB7CiAgICAgICAgICBub2RlID0gcy5oZWFwWysrcy5oZWFwX2xlbl0gPSBtYXhfY29kZSA8IDIgPyArK21heF9jb2RlIDogMDsKICAgICAgICAgIHRyZWVbbm9kZSAqIDJdID0gMTsKICAgICAgICAgIHMuZGVwdGhbbm9kZV0gPSAwOwogICAgICAgICAgcy5vcHRfbGVuLS07CiAgICAgICAgICBpZiAoaGFzX3N0cmVlKSB7CiAgICAgICAgICAgIHMuc3RhdGljX2xlbiAtPSBzdHJlZVtub2RlICogMiArIDFdOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBkZXNjLm1heF9jb2RlID0gbWF4X2NvZGU7CiAgICAgICAgZm9yIChuID0gcy5oZWFwX2xlbiA+PiAxOyBuID49IDE7IG4tLSkgewogICAgICAgICAgcHFkb3duaGVhcChzLCB0cmVlLCBuKTsKICAgICAgICB9CiAgICAgICAgbm9kZSA9IGVsZW1zOwogICAgICAgIGRvIHsKICAgICAgICAgIG4gPSBzLmhlYXBbMV07CiAgICAgICAgICBzLmhlYXBbMV0gPSBzLmhlYXBbcy5oZWFwX2xlbi0tXTsKICAgICAgICAgIHBxZG93bmhlYXAocywgdHJlZSwgMSk7CiAgICAgICAgICBtID0gcy5oZWFwWzFdOwogICAgICAgICAgcy5oZWFwWy0tcy5oZWFwX21heF0gPSBuOwogICAgICAgICAgcy5oZWFwWy0tcy5oZWFwX21heF0gPSBtOwogICAgICAgICAgdHJlZVtub2RlICogMl0gPSB0cmVlW24gKiAyXSArIHRyZWVbbSAqIDJdOwogICAgICAgICAgcy5kZXB0aFtub2RlXSA9IChzLmRlcHRoW25dID49IHMuZGVwdGhbbV0gPyBzLmRlcHRoW25dIDogcy5kZXB0aFttXSkgKyAxOwogICAgICAgICAgdHJlZVtuICogMiArIDFdID0gdHJlZVttICogMiArIDFdID0gbm9kZTsKICAgICAgICAgIHMuaGVhcFsxXSA9IG5vZGUrKzsKICAgICAgICAgIHBxZG93bmhlYXAocywgdHJlZSwgMSk7CiAgICAgICAgfSB3aGlsZSAocy5oZWFwX2xlbiA+PSAyKTsKICAgICAgICBzLmhlYXBbLS1zLmhlYXBfbWF4XSA9IHMuaGVhcFsxXTsKICAgICAgICBnZW5fYml0bGVuKHMsIGRlc2MpOwogICAgICAgIGdlbl9jb2Rlcyh0cmVlLCBtYXhfY29kZSwgcy5ibF9jb3VudCk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2Nhbl90cmVlKHMsIHRyZWUsIG1heF9jb2RlKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIHByZXZsZW4gPSAtMTsKICAgICAgICB2YXIgY3VybGVuOwogICAgICAgIHZhciBuZXh0bGVuID0gdHJlZVswICogMiArIDFdOwogICAgICAgIHZhciBjb3VudCA9IDA7CiAgICAgICAgdmFyIG1heF9jb3VudCA9IDc7CiAgICAgICAgdmFyIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgfQogICAgICAgIHRyZWVbKG1heF9jb2RlICsgMSkgKiAyICsgMV0gPSA2NTUzNTsKICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IG1heF9jb2RlOyBuKyspIHsKICAgICAgICAgIGN1cmxlbiA9IG5leHRsZW47CiAgICAgICAgICBuZXh0bGVuID0gdHJlZVsobiArIDEpICogMiArIDFdOwogICAgICAgICAgaWYgKCsrY291bnQgPCBtYXhfY291bnQgJiYgY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8IG1pbl9jb3VudCkgewogICAgICAgICAgICBzLmJsX3RyZWVbY3VybGVuICogMl0gKz0gY291bnQ7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiAhPT0gMCkgewogICAgICAgICAgICBpZiAoY3VybGVuICE9PSBwcmV2bGVuKSB7CiAgICAgICAgICAgICAgcy5ibF90cmVlW2N1cmxlbiAqIDJdKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcy5ibF90cmVlW1JFUF8zXzYgKiAyXSsrOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8PSAxMCkgewogICAgICAgICAgICBzLmJsX3RyZWVbUkVQWl8zXzEwICogMl0rKzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuYmxfdHJlZVtSRVBaXzExXzEzOCAqIDJdKys7CiAgICAgICAgICB9CiAgICAgICAgICBjb3VudCA9IDA7CiAgICAgICAgICBwcmV2bGVuID0gY3VybGVuOwogICAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNjsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDc7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNlbmRfdHJlZShzLCB0cmVlLCBtYXhfY29kZSkgewogICAgICAgIHZhciBuOwogICAgICAgIHZhciBwcmV2bGVuID0gLTE7CiAgICAgICAgdmFyIGN1cmxlbjsKICAgICAgICB2YXIgbmV4dGxlbiA9IHRyZWVbMCAqIDIgKyAxXTsKICAgICAgICB2YXIgY291bnQgPSAwOwogICAgICAgIHZhciBtYXhfY291bnQgPSA3OwogICAgICAgIHZhciBtaW5fY291bnQgPSA0OwogICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IG1heF9jb2RlOyBuKyspIHsKICAgICAgICAgIGN1cmxlbiA9IG5leHRsZW47CiAgICAgICAgICBuZXh0bGVuID0gdHJlZVsobiArIDEpICogMiArIDFdOwogICAgICAgICAgaWYgKCsrY291bnQgPCBtYXhfY291bnQgJiYgY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8IG1pbl9jb3VudCkgewogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGN1cmxlbiwgcy5ibF90cmVlKTsKICAgICAgICAgICAgfSB3aGlsZSAoLS1jb3VudCAhPT0gMCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiAhPT0gMCkgewogICAgICAgICAgICBpZiAoY3VybGVuICE9PSBwcmV2bGVuKSB7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGN1cmxlbiwgcy5ibF90cmVlKTsKICAgICAgICAgICAgICBjb3VudC0tOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHNlbmRfY29kZShzLCBSRVBfM182LCBzLmJsX3RyZWUpOwogICAgICAgICAgICBzZW5kX2JpdHMocywgY291bnQgLSAzLCAyKTsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPD0gMTApIHsKICAgICAgICAgICAgc2VuZF9jb2RlKHMsIFJFUFpfM18xMCwgcy5ibF90cmVlKTsKICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGNvdW50IC0gMywgMyk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzZW5kX2NvZGUocywgUkVQWl8xMV8xMzgsIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIHNlbmRfYml0cyhzLCBjb3VudCAtIDExLCA3KTsKICAgICAgICAgIH0KICAgICAgICAgIGNvdW50ID0gMDsKICAgICAgICAgIHByZXZsZW4gPSBjdXJsZW47CiAgICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBtYXhfY291bnQgPSA2OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNzsKICAgICAgICAgICAgbWluX2NvdW50ID0gNDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYnVpbGRfYmxfdHJlZShzKSB7CiAgICAgICAgdmFyIG1heF9ibGluZGV4OwogICAgICAgIHNjYW5fdHJlZShzLCBzLmR5bl9sdHJlZSwgcy5sX2Rlc2MubWF4X2NvZGUpOwogICAgICAgIHNjYW5fdHJlZShzLCBzLmR5bl9kdHJlZSwgcy5kX2Rlc2MubWF4X2NvZGUpOwogICAgICAgIGJ1aWxkX3RyZWUocywgcy5ibF9kZXNjKTsKICAgICAgICBmb3IgKG1heF9ibGluZGV4ID0gQkxfQ09ERVMgLSAxOyBtYXhfYmxpbmRleCA+PSAzOyBtYXhfYmxpbmRleC0tKSB7CiAgICAgICAgICBpZiAocy5ibF90cmVlW2JsX29yZGVyW21heF9ibGluZGV4XSAqIDIgKyAxXSAhPT0gMCkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5vcHRfbGVuICs9IDMgKiAobWF4X2JsaW5kZXggKyAxKSArIDUgKyA1ICsgNDsKICAgICAgICByZXR1cm4gbWF4X2JsaW5kZXg7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2VuZF9hbGxfdHJlZXMocywgbGNvZGVzLCBkY29kZXMsIGJsY29kZXMpIHsKICAgICAgICB2YXIgcmFuazsKICAgICAgICBzZW5kX2JpdHMocywgbGNvZGVzIC0gMjU3LCA1KTsKICAgICAgICBzZW5kX2JpdHMocywgZGNvZGVzIC0gMSwgNSk7CiAgICAgICAgc2VuZF9iaXRzKHMsIGJsY29kZXMgLSA0LCA0KTsKICAgICAgICBmb3IgKHJhbmsgPSAwOyByYW5rIDwgYmxjb2RlczsgcmFuaysrKSB7CiAgICAgICAgICBzZW5kX2JpdHMocywgcy5ibF90cmVlW2JsX29yZGVyW3JhbmtdICogMiArIDFdLCAzKTsKICAgICAgICB9CiAgICAgICAgc2VuZF90cmVlKHMsIHMuZHluX2x0cmVlLCBsY29kZXMgLSAxKTsKICAgICAgICBzZW5kX3RyZWUocywgcy5keW5fZHRyZWUsIGRjb2RlcyAtIDEpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRldGVjdF9kYXRhX3R5cGUocykgewogICAgICAgIHZhciBibGFja19tYXNrID0gNDA5MzYyNDQ0NzsKICAgICAgICB2YXIgbjsKICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IDMxOyBuKyssIGJsYWNrX21hc2sgPj4+PSAxKSB7CiAgICAgICAgICBpZiAoYmxhY2tfbWFzayAmIDEgJiYgcy5keW5fbHRyZWVbbiAqIDJdICE9PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBaX0JJTkFSWTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuZHluX2x0cmVlWzkgKiAyXSAhPT0gMCB8fCBzLmR5bl9sdHJlZVsxMCAqIDJdICE9PSAwIHx8IHMuZHluX2x0cmVlWzEzICogMl0gIT09IDApIHsKICAgICAgICAgIHJldHVybiBaX1RFWFQ7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDMyOyBuIDwgTElURVJBTFM7IG4rKykgewogICAgICAgICAgaWYgKHMuZHluX2x0cmVlW24gKiAyXSAhPT0gMCkgewogICAgICAgICAgICByZXR1cm4gWl9URVhUOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gWl9CSU5BUlk7CiAgICAgIH0KICAgICAgdmFyIHN0YXRpY19pbml0X2RvbmUgPSBmYWxzZTsKICAgICAgZnVuY3Rpb24gX3RyX2luaXQocykgewogICAgICAgIGlmICghc3RhdGljX2luaXRfZG9uZSkgewogICAgICAgICAgdHJfc3RhdGljX2luaXQoKTsKICAgICAgICAgIHN0YXRpY19pbml0X2RvbmUgPSB0cnVlOwogICAgICAgIH0KICAgICAgICBzLmxfZGVzYyA9IG5ldyBUcmVlRGVzYyhzLmR5bl9sdHJlZSwgc3RhdGljX2xfZGVzYyk7CiAgICAgICAgcy5kX2R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pOwogICAgICAgIH0KICAgICAgICBpbml0X2Jsb2NrKHMpOwogICAgICAgIGlmIChsYXN0KSB7CiAgICAgICAgICBiaV93aW5kdXAocyk7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIF90cl90YWxseShzLCBkaXN0LCBsYykgewogICAgICAgIHMucGVuZGluZ19idWZbcy5kX2J1ZiArIHMubGFzdF9saXQgKiAyXSA9IGRpc3QgPj4+IDggJiAyNTU7CiAgICAgICAgcy5wZW5kaW5nX2J1ZltzLmRfYnVmICsgcy5sYXN0X2xpdCAqIDIgKyAxXSA9IGRpc3QgJiAyNTU7CiAgICAgICAgcy5wZW5kaW5nX2J1ZltzLmxfYnVmICsgcy5sYXN0X2xpdF0gPSBsYyAmIDI1NTsKICAgICAgICBzLmxhc3RfbGl0Kys7CiAgICAgICAgaWYgKGRpc3QgPT09IDApIHsKICAgICAgICAgIHMuZHluX2x0cmVlW2xjICogMl0rKzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgcy5tYXRjaGVzKys7CiAgICAgICAgICBkaXN0LS07CiAgICAgICAgICBzLmR5bl9sdHJlZVsoX2xlbmd0aF9jb2RlW2xjXSArIExJVEVSQUxTICsgMSkgKiAyXSsrOwogICAgICAgICAgcy5keW5fZHRyZWVbZF9jb2RlKGRpc3QpICogMl0rKzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHMubGFzdF9saXQgPT09IHMubGl0X2J1ZnNpemUgLSAxOwogICAgICB9CiAgICAgIGV4cG9ydHMyLl90cl9pbml0ID0gX3RyX2luaXQ7CiAgICAgIGV4cG9ydHMyLl90cl9zdG9yZWRfYmxvY2sgPSBfdHJfc3RvcmVkX2Jsb2NrOwogICAgICBleHBvcnRzMi5fdHJfZmx1c2hfYmxvY2sgPSBfdHJfZmx1c2hfYmxvY2s7CiAgICAgIGV4cG9ydHMyLl90cl90YWxseSA9IF90cl90YWxseTsKICAgICAgZXhwb3J0czIuX3RyX2FsaWduID0gX3RyX2FsaWduOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvYWRsZXIzMi5qcwogIHZhciByZXF1aXJlX2FkbGVyMzIgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvYWRsZXIzMi5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIGZ1bmN0aW9uIGFkbGVyMzIoYWRsZXIsIGJ1ZiwgbGVuLCBwb3MpIHsKICAgICAgICB2YXIgczEgPSBhZGxlciAmIDY1NTM1IHwgMCwgczIgPSBhZGxlciA+Pj4gMTYgJiA2NTUzNSB8IDAsIG4gPSAwOwogICAgICAgIHdoaWxlIChsZW4gIT09IDApIHsKICAgICAgICAgIG4gPSBsZW4gPiAyZTMgPyAyZTMgOiBsZW47CiAgICAgICAgICBsZW4gLT0gbjsKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgczEgPSBzMSArIGJ1Zltwb3MrK10gfCAwOwogICAgICAgICAgICBzMiA9IHMyICsgczEgfCAwOwogICAgICAgICAgfSB3aGlsZSAoLS1uKTsKICAgICAgICAgIHMxICU9IDY1NTIxOwogICAgICAgICAgczIgJT0gNjU1MjE7CiAgICAgICAgfQogICAgICAgIHJldHVybiBzMSB8IHMyIDw8IDE2IHwgMDsKICAgICAgfQogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBhZGxlcjMyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvY3JjMzIuanMKICB2YXIgcmVxdWlyZV9jcmMzMiA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9k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KHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvbWVzc2FnZXMuanMiKGV4cG9ydHMyLCBtb2R1bGUyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSB7CiAgICAgICAgMjogIm5lZWQgZGljdGlvbmFyeSIsCiAgICAgICAgMTogInN0cmVhbSBlbmQiLAogICAgICAgIDA6ICIiLAogICAgICAgICItMSI6ICJmaWxlIGVycm9yIiwKICAgICAgICAiLTIiOiAic3RyZWFtIGVycm9yIiwKICAgICAgICAiLTMiOiAiZGF0YSBlcnJvciIsCiAgICAgICAgIi00IjogImluc3VmZmljaWVudCBtZW1vcnkiLAogICAgICAgICItNSI6ICJidWZmZXIgZXJyb3IiLAogICAgICAgICItNiI6ICJpbmNvbXBhdGlibGUgdmVyc2lvbiIKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2RlZmxhdGUuanMKICB2YXIgcmVxdWlyZV9kZWZsYXRlID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2RlZmxhdGUuanMiKGV4cG9ydHMyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgdXRpbHMgPSByZXF1aXJlX2NvbW1vbigpOwogICAgICB2YXIgdHJlZXMgPSByZXF1aXJlX3RyZWVzKCk7CiAgICAgIHZhciBhZGxlcjMyID0gcmVxdWlyZV9hZGxlcjMyKCk7CiAgICAgIHZhciBjcmMzMiA9IHJlcXVpcmVfY3JjMzIoKTsKICAgICA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Tl9NQVRDSCA9IDM7CiAgICAgIHZhciBNQVhfTUFUQ0ggPSAyNTg7CiAgICAgIHZhciBNSU5fTE9PS0FIRUFEID0gTUFYX01BVENIICsgTUlOX01BVENIICsgMTsKICAgICAgdmFyIFBSRVNFVF9ESUNUID0gMzI7CiAgICAgIHZhciBJTklUX1NUQVRFID0gNDI7CiAgICAgIHZhciBFWFRSQV9TVEFURSA9IDY5OwogICAgICB2YXIgTkFNRV9TVEFURSA9IDczOwogICAgICB2YXIgQ09NTUVOVF9TVEFURSA9IDkxOwogICAgICB2YXIgSENSQ19TVEFURSA9IDEwMzsKICAgICAgdmFyIEJVU1lfU1RBVEUgPSAxMTM7CiAgICAgIHZhciBGSU5JU0hfU1RBVEUgPSA2NjY7CiAgICAgIHZhciBCU19ORUVEX01PUkUgPSAxOwogICAgICB2YXIgQlNfQkxPQ0tfRE9ORSA9IDI7CiAgICAgIHZhciBCU19GSU5JU0hfU1RBUlRFRCA9IDM7CiAgICAgIHZhciBCU19GSU5JU0hfRE9ORSA9IDQ7CiAgICAgIHZhciBPU19DT0RFID0gMzsKICAgICAgZnVuY3Rpb24gZXJyKHN0cm0sIGVycm9yQ29kZSkgewogICAgICAgIHN0cm0ubXNnID0gbXNnW2Vycm9yQ29kZV07CiAgICAgICAgcmV0dXJuIGVycm9yQ29kZTsKICAgICAgfQogICAgICBmdW5jdGlvbiByYW5rKGYpIHsKICAgICAgICByZXR1cm4gKGYgPDwgMSkgLSAoZiA+IDQgPyA5IDogMCk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gemVybyhidWYpIHsKICAgICAgICB2YXIgbGVuID0gYnVmLmxlbmd0aDsKICAgICAgICB3aGlsZSAoLS1sZW4gPj0gMCkgewogICAgICAgICAgYnVmW2xlbl0gPSAwOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBmbHVzaF9wZW5kaW5nKHN0cm0pIHsKICAgICAgICB2YXIgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgdmF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cy5wcmV2X2xlbmd0aDsKICAgICAgICB2YXIgbmljZV9tYXRjaCA9IHMubmljZV9tYXRjaDsKICAgICAgICB2YXIgbGltaXQgPSBzLnN0cnN0YXJ0ID4gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEID8gcy5zdHJzdGFydCAtIChzLndfc2l6ZSAtIE1JTl9MT09LQUhFQUQpIDogMDsKICAgICAgICB2YXIgX3dpbiA9IHMud2luZG93OwogICAgICAgIHZhciB3bWFzayA9IHMud19tYXNrOwogICAgICAgIHZhciBwcmV2ID0gcy5wcmV2OwogICAgICAgIHZhciBzdHJlbmQgPSBzLnN0cnN0YXJ0ICsgTUFYX01BVENIOwogICAgICAgIHZhciBzY2FuX2VuZDEgPSBfd2luW3NjYW4gKyBiZXN0X2xlbiAtIDFdOwogICAgICAgIHZhciBzY2FuX2VuZCA9IF93aW5bc2NhbiArIGJlc3RfbGVuXTsKICAgICAgICBpZiAocy5wcmV2X2xlbmd0aCA+PSBzLmdvb2RfbWF0Y2gpIHsKICAgICAgICAgIGNoYWluX2xlbmd0aCA+Pj0gMjsKICAgICAgICB9CiAgICAgICAgaWYgKG5pY2VfbWF0Y2ggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgbmljZV9tYXRjaCA9IHMubG9va2FoZWFkOwogICAgICAgIH0KICAgICAgICBkbyB7CiAgICAgICAgICBtYXRjaCA9IGN1cl9tYXRjaDsKICAgICAgICAgIGlmIChfd2luW21hdGNoICsgYmVzdF9sZW5dICE9PSBzY2FuX2VuZCB8fCBfd2luW21hdGNoICsgYmVzdF9sZW4gLSAxXSAhPT0gc2Nhbl9lbmQxIHx8IF93aW5bbWF0Y2hdICE9PSBfd2luW3NjYW5dIHx8IF93aW5bKyttYXRjaF0gIT09IF93aW5bc2NhbiArIDFdKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgc2NhbiArPSAyOwogICAgICAgICAgbWF0Y2grKzsKICAgICAgICAgIGRvIHsKICAgICAgICAgIH0gd2hpbGUgKF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgc2NhbiA8IHN0cmVuZCk7CiAgICAgICAgICBsZW4gPSBNQVhfTUFUQ0ggLSAoc3RyZW5kIC0gc2Nhbik7CiAgICAgICAgICBzY2FuID0gc3RyZW5kIC0gTUFYX01BVENIOwogICAgICAgICAgaWYgKGxlbiA+IGJlc3RfbGVuKSB7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgPSBjdXJfbWF0Y2g7CiAgICAgICAgICAgIGJlc3RfbGVuID0gbGVuOwogICAgICAgICAgICBpZiAobGVuID49IG5pY2VfbWF0Y2gpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBzY2FuX2VuZDEgPSBfd2luW3NjYW4gKyBiZXN0X2xlbiAtIDFdOwogICAgICAgICAgICBzY2FuX2VuZCA9IF93aW5bc2NhbiArIGJlc3RfbGVuXTsKICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlICgoY3VyX21hdGNoID0gcHJldltjdXJfbWF0Y2ggJiB3bWFza10pID4gbGltaXQgJiYgLS1jaGFpbl9sZW5ndGggIT09IDApOwogICAgICAgIGlmIChiZXN0X2xlbiA8PSBzLmxvb2thaGVhZCkgewogICAgICAgICAgcmV0dXJuIGJlc3RfbGVuOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcy5sb29rYWhlYWQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZmlsbF93aW5kb3cocykgewogICAgICAgIHZhciBfd19zaXplID0gcy53X3NpemU7CiAgICAgICAgdmFyIHAsIG4sIG0sIG1vcmUsIHN0cjsKICAgICAgICBkbyB7CiAgICAgICAgICBtb3JlID0gcy53aW5kb3dfc2l6ZSAtIHMubG9va2FoZWFkIC0gcy5zdHJzdGFydDsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID49IF93X3NpemUgKyAoX3dfc2l6ZSAtIE1JTl9MT09LQUhFQUQpKSB7CiAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHMud2luZG93LCBzLndpbmRvdywgX3dfc2l6ZSwgX3dfc2l6ZSwgMCk7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgLT0gX3dfc2l6ZTsKICAgICAgICAgICAgcy5zdHJzdGFydCAtPSBfd19zaXplOwogICAgICAgICAgICBzLmJsb2NrX3N0YXJ0IC09IF93X3NpemU7CiAgICAgICAgICAgIG4gPSBzLmhhc2hfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5oZWFkWy0tcF07CiAgICAgICAgICAgICAgcy5oZWFkW3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBuID0gX3dfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5wcmV2Wy0tcF07CiAgICAgICAgICAgICAgcy5wcmV2W3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBtb3JlICs9IF93X3NpemU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX2luID09PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgbiA9IHJlYWRfYnVmKHMuc3RybSwgcy53aW5kb3csIHMuc3Ryc3RhcnQgKyBzLmxvb2thaGVhZCwgbW9yZSk7CiAgICAgICAgICBzLmxvb2thaGVhZCArPSBuOwogICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHN0ciA9IHMuc3Ryc3RhcnQgLSBzLmluc2VydDsKICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3N0cl07CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgd2hpbGUgKHMuaW5zZXJ0KSB7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3N0ciArIE1JTl9NQVRDSCAtIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gc3RyOwogICAgICAgICAgICAgIHN0cisrOwogICAgICAgICAgICAgIHMuaW5zZXJ0LS07CiAgICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPCBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBzLnN0cm0uYXZhaWxfaW4gIT09IDApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfc3RvcmVkKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIG1heF9ibG9ja19zaXplID0gNjU1MzU7CiAgICAgICAgaWYgKG1heF9ibG9ja19zaXplID4gcy5wZW5kaW5nX2J1Zl9zaXplIC0gNSkgewogICAgICAgICAgbWF4X2Jsb2NrX3NpemUgPSBzLnBlbmRpbmdfYnVmX3NpemUgLSA1OwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSAxKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDAgJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubG9va2FoZWFkOwogICAgICAgICAgcy5sb29rYWhlYWQgPSAwOwogICAgICAgICAgdmFyIG1heF9zdGFydCA9IHMuYmxvY2tfc3RhcnQgKyBtYXhfYmxvY2tfc2l6ZTsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID09PSAwIHx8IHMuc3Ryc3RhcnQgPj0gbWF4X3N0YXJ0KSB7CiAgICAgICAgICAgIHMubG9va2FoZWFkID0gcy5zdHJzdGFydCAtIG1heF9zdGFydDsKICAgICAgICAgICAgcy5zdHJzdGFydCA9IG1heF9zdGFydDsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgLSBzLmJsb2NrX3N0YXJ0ID49IHMud19zaXplIC0gTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5zdHJzdGFydCA+IHMuYmxvY2tfc3RhcnQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX2Zhc3QocywgZmx1c2gpIHsKICAgICAgICB2YXIgaGFzaF9oZWFkOwogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEICYmIGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaGFzaF9oZWFkID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgaGFzaF9oZWFkID0gcy5wcmV2W3Muc3Ryc3RhcnQgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaGFzaF9oZWFkICE9PSAwICYmIHMuc3Ryc3RhcnQgLSBoYXNoX2hlYWQgPD0gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gbG9uZ2VzdF9tYXRjaChzLCBoYXNoX2hlYWQpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHMubWF0Y2hfbGVuZ3RoID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgcy5zdHJzdGFydCAtIHMubWF0Y2hfc3RhcnQsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA8PSBzLm1heF9sYXp5X21hdGNoICYmIHMubG9va2FoZWFkID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoLS07CiAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9IHdoaWxlICgtLXMubWF0Y2hfbGVuZ3RoICE9PSAwKTsKICAgICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcy5zdHJzdGFydCArPSBzLm1hdGNoX2xlbmd0aDsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3Muc3Ryc3RhcnRdOwogICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IHMuc3Ryc3RhcnQgPCBNSU5fTUFUQ0ggLSAxID8gcy5zdHJzdGFydCA6IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9zbG93KHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGhhc2hfaGVhZDsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIHZhciBtYXhfaW5zZXJ0OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAg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ubWF0Y2hfc3RhcnQgPiA0MDk2KSkgewogICAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gTUlOX01BVENIIC0gMTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMucHJldl9sZW5ndGggPj0gTUlOX01BVENIICYmIHMubWF0Y2hfbGVuZ3RoIDw9IHMucHJldl9sZW5ndGgpIHsKICAgICAgICAgICAgbWF4X2luc2VydCA9IHMuc3Ryc3RhcnQgKyBzLmxvb2thaGVhZCAtIE1JTl9NQVRDSDsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIHMuc3Ryc3RhcnQgLSAxIC0gcy5wcmV2X21hdGNoLCBzLnByZXZfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5wcmV2X2xlbmd0aCAtIDE7CiAgICAgICAgICAgIHMucHJldl9sZW5ndGggLT0gMjsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIGlmICgrK3Muc3Ryc3RhcnQgPD0gbWF4X2luc2VydCkgewogICAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gd2hpbGUgKC0tcy5wcmV2X2xlbmd0aCAhPT0gMCk7CiAgICAgICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMDsKICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAocy5tYXRjaF9hdmFpbGFibGUpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5tYXRjaF9hdmFpbGFibGUgPSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLm1hdGNoX2F2YWlsYWJsZSkgewogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gcy5zdHJzdGFydCA8IE1JTl9NQVRDSCAtIDEgPyBzLnN0cnN0YXJ0IDogTUlOX01BVENIIC0gMTsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5sYXN0X2xpdCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gQlNfQkxPQ0tfRE9ORTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX3JsZShzLCBmbHVzaCkgewogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgdmFyIHByZXY7CiAgICAgICAgdmFyIHNjYW4sIHN0cmVuZDsKICAgICAgICB2YXIgX3dpbiA9IHMud2luZG93OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0ggJiYgcy5zdHJzdGFydCA+IDApIHsKICAgICAgICAgICAgc2NhbiA9IHMuc3Ryc3RhcnQgLSAxOwogICAgICAgICAgICBwcmV2ID0gX3dpbltzY2FuXTsKICAgICAgICAgICAgaWYgKHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dKSB7CiAgICAgICAgICAgICAgc3RyZW5kID0gcy5zdHJzdGFydCArIE1BWF9NQVRDSDsKICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgfSB3aGlsZSAocHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBzY2FuIDwgc3RyZW5kKTsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IE1BWF9NQVRDSCAtIChzdHJlbmQgLSBzY2FuKTsKICAgICAgICAgICAgICBpZiAocy5tYXRjaF9sZW5ndGggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBzLmxvb2thaGVhZDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDEsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgKz0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9odWZmKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGJmbHVzaDsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSAwOwogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnRdKTsKICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAg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ICAgdGhpcy5wZW5kaW5nX2J1Zl9zaXplID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmcgPSAwOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5nemhlYWQgPSBudWxsOwogICAgICAgIHRoaXMuZ3ppbmRleCA9IDA7CiAgICAgICAgdGhpcy5tZXRob2QgPSBaX0RFRkxBVEVEOwogICAgICAgIHRoaXMubGFzdF9mbHVzaCA9IC0xOwogICAgICAgIHRoaXMud19zaXplID0gMDsKICAgICAgICB0aGlzLndfYml0cyA9IDA7CiAgICAgICAgdGhpcy53X21hc2sgPSAwOwogICAgICAgIHRoaXMud2luZG93ID0gbnVsbDsKICAgICAgICB0aGlzLndpbmRvd19zaXplID0gMDsKICAgICAgICB0aGlzLnByZXYgPSBudWxsOwogICAgICAgIHRoaXMuaGVhZCA9IG51bGw7CiAgICAgICAgdGhpcy5pbnNfaCA9IDA7CiAgICAgICAgdGhpcy5oYXNoX3NpemUgPSAwOwogICAgICAgIHRoaXMuaGFzaF9iaXRzID0gMDsKICAgICAgICB0aGlzLmhhc2hfbWFzayA9IDA7CiAgICAgICAgdGhpcy5oYXNoX3NoaWZ0ID0gMDsKICAgICAgICB0aGlzLmJsb2NrX3N0YXJ0ID0gMDsKICAgICAgICB0aGlzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgdGhpcy5wcmV2X21hdGNoID0gMDsKICAgICAgICB0aGlzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgdGhpcy5zdHJzdGFydCA9IDA7CiAgICAgICAgdGhpcy5tYXRjaF9zdGFydCA9IDA7CiAgICAgICAgdGhpcy5sb29rYWhlYWQgPSAwOwogICAgICAgIHRoaXMucHJldl9sZW5ndGggPSAwOwogICAgICAgIHRoaXMubWF4X2NoYWluX2xlbmd0aCA9IDA7CiAgICAgICAgdGhpcy5tYXhfbGF6eV9tYXRjaCA9IDA7CiAgICAgICAgdGhpcy5sZXZlbCA9IDA7CiAgICAgICAgdGhpcy5zdHJhdGVneSA9IDA7CiAgICAgICAgdGhpcy5nb29kX21hdGNoID0gMDsKICAgICAgICB0aGlzLm5pY2VfbWF0Y2ggPSAwOwogICAgICAgIHRoaXMuZHluX2x0cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KEhFQVBfU0laRSAqIDIpOwogICAgICAgIHRoaXMuZHluX2R0cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KCgyICogRF9DT0RFUyArIDEpICogMik7CiAgICAgICAgdGhpcy5ibF90cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KCgyICogQkxfQ09ERVMgKyAxKSAqIDIpOwogICAgICAgIHplcm8odGhpcy5keW5fbHRyZWUpOwogICAgICAgIHplcm8odGhpcy5keW5fZHRyZWUpOwogICAgICAgIHplcm8odGhpcy5ibF90cmVlKTsKICAgICAgICB0aGlzLmxfZGVzYyA9IG51bGw7CiAgICAgICAgdGhpcy5kX2Rlc2MgPSBudWxsOwogICAgICAgIHRoaXMuYmxfZGVzYyA9IG51bGw7CiAgICAgICAgdGhpcy5ibF9jb3VudCA9IG5ldyB1dGlscy5CdWYxNihNQVhfQklUUyArIDEpOwogICAgICAgIHRoaXMuaGVhcCA9IG5ldyB1dGlscy5CdWYxNigyICogTF9DT0RFUyArIDEpOwogICAgICAgIHplcm8odGhpcy5oZWFwKTsKICAgICAgICB0aGlzLmhlYXBfbGVuID0gMDsKICAgICAgICB0aGlzLmhlYXBfbWF4ID0gMDsKICAgICAgICB0aGlzLmRlcHRoID0gbmV3IHV0aWxzLkJ1ZjE2KDIgKiBMX0NPREVTICsgMSk7CiAgICAgICAgemVybyh0aGlzLmRlcHRoKTsKICAgICAgICB0aGlzLmxfYnVmID0gMDsKICAgICAgICB0aGlzLmxpdF9idWZzaXplID0gMDsKICAgICAgICB0aGlzLmxhc3RfbGl0ID0gMDsKICAgICAgICB0aGlzLmRfYnVmID0gMDsKICAgICAgICB0aGlzLm9wdF9sZW4gPSAwOwogICAgICAgIHRoaXMuc3RhdGljX2xlbiA9IDA7CiAgICAgICAgdGhpcy5tYXRjaGVzID0gMDsKICAgICAgICB0aGlzLmluc2VydCA9IDA7CiAgICAgICAgdGhpcy5iaV9idWYgPSAwOwogICAgICAgIHRoaXMuYmlfdmFsaWQgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVSZXNldEtlZXAoc3RybSkgewogICAgICAgIHZhciBzOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBaX1NUUkVBTV9FUlJPUik7CiAgICAgICAgfQogICAgICAgIHN0cm0udG90YWxfaW4gPSBzdHJtLnRvdGFsX291dCA9IDA7CiAgICAgICAgc3RybS5kYXRhX3R5cGUgPSBaX1VOS05PV047CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgcy5wZW5kaW5nID0gMDsKICAgICAgICBzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICBpZiAocy53cmFwIDwgMCkgewogICAgICAgICAgcy53cmFwID0gLXMud3JhcDsKICAgICAgICB9CiAgICAgICAgcy5zdGF0dXMgPSBzLndyYXAgPyBJTklUX1NUQVRFIDogQlVTWV9TVEFURTsKICAgICAgICBzdHJtLmFkbGVyID0gcy53cmFwID09PSAyID8gMCA6IDE7CiAgICAgICAgcy5sYXN0X2ZsdXNoID0gWl9OT19GTFVTSDsKICAgICAgICB0cmVlcy5fdHJfaW5pdChzKTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmVzZXQoc3RybSkgewogICAgICAgIHZhciByZXQgPSBkZWZsYXRlUmVzZXRLZWVwKHN0cm0pOwogICAgICAgIGlmIChyZXQgPT09IFpfT0spIHsKICAgICAgICAgIGxtX2luaXQoc3RybS5zdGF0ZSk7CiAgICAgICAgfQogICAgICAgIHJldH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AgfHwgbGV2ZWwgPiA5IHx8IHN0cmF0ZWd5IDwgMCB8fCBzdHJhdGVneSA+IFpfRklYRUQpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyA9PT0gOCkgewogICAgICAgICAgd2luZG93Qml0cyA9IDk7CiAgICAgICAgfQogICAgICAgIHZhciBzID0gbmV3IERlZmxhdGVTdGF0ZSgpOwogICAgICAgIHN0cm0uc3RhdGUgPSBzOwogICAgICAgIHMuc3RybSA9IHN0cm07CiAgICAgICAgcy53cmFwID0gd3JhcDsKICAgICAgICBzLmd6aGVhZCA9IG51bGw7CiAgICAgICAgcy53X2JpdHMgPSB3aW5kb3dCaXRzOwogICAgICAgIHMud19zaXplID0gMSA8PCBzLndfYml0czsKICAgICAgICBzLndfbWFzayA9IHMud19zaXplIC0gMTsKICAgICAgICBzLmhhc2hfYml0cyA9IG1lbUxldmVsICsgNzsKICAgICAgICBzLmhhc2hfc2l6ZSA9IDEgPDwgcy5oYXNoX2JpdHM7CiAgICAgICAgcy5oYXNoX21hc2sgPSBzLmhhc2hfc2l6ZSAtIDE7CiAgICAgICAgcy5oYXNoX3NoaWZ0ID0gfn4oKHMuaGFzaF9iaXRzICsgTUlOX01BVENIIC0gMSkgLyBNSU5fTUFUQ0gpOwogICAgICAgIHMud2luZG93ID0gbmV3IHV0aWxzLkJ1Zjgocy53X3NpemUgKiAyKTsKICAgICAgICBzLmhlYWQgPSBuZXcgdXRpbHMuQnVmMTYocy5oYXNoX3NpemUpOwogICAgICAgIHMucHJldiA9IG5ldyB1dGlscy5CdWYxNihzLndfc2l6ZSk7CiAgICAgICAgcy5saXRfYnVmc2l6ZSA9IDEgPDwgbWVtTGV2ZWwgKyA2OwogICAgICAgIHMucGVuZGluZ19idWZfc2l6ZSA9IHMubGl0X2J1ZnNpemUgKiA0OwogICAgICAgIHMucGVuZGluZ19idWYgPSBuZXcgdX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QU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBzLnN0cm0gPSBzdHJtOwogICAgICAgIG9sZF9mbHVzaCA9IHMubGFzdF9mbHVzaDsKICAgICAgICBzLmxhc3RfZmx1c2ggPSBmbHVzaDsKICAgICAgICBpZiAocy5zdGF0dXMgPT09IElOSVRfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLndyYXAgPT09IDIpIHsKICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgIHB1dF9ieXRlKHMsIDMxKTsKICAgICAgICAgICAgcHV0X2J5dGUocywgMTM5KTsKICAgICAgICAgICAgcHV0X2J5dGUocywgOCk7CiAgICAgICAgICAgIGlmICghcy5nemhlYWQpIHsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgT1NfQ09ERSk7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIChzLmd6aGVhZC50ZXh0ID8gMSA6IDApICsgKHMuZ3poZWFkLmhjcmMgPyAyIDogMCkgKyAoIXMuZ3poZWFkLmV4dHJhID8gMCA6IDQpICsgKCFzLmd6aGVhZC5uYW1lID8gMCA6IDgpICsgKCFzLmd6aGVhZC5jb21tZW50ID8gMCA6IDE2KSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiA4ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDE2ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDI0ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQub3MgJiAyNTUpOwogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5leHRyYSAmJiBzLmd6aGVhZC5leHRyYS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLmV4dHJhLmxlbmd0aCAmIDI1NSk7CiAgICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYS5sZW5ndGggPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjKSB7CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nLCAwKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcy5nemluZGV4ID0gMDsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IEVYVFJBX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB2YXIgaGVhZGVyID0gWl9ERUZMQVRFRCArIChzLndfYml0cyAtIDggPDwgNCkgPDwgODsKICAgICAgICAgICAgdmFyIGxldmVsX2ZsYWdzID0gLTE7CiAgICAgICAgICAgIGlmIChzLnN0cmF0ZWd5ID49IFpfSFVGRk1BTl9PTkxZIHx8IHMubGV2ZWwgPCAyKSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAwOwogICAgICAgICAgICB9IGVsc2UgaWYgKHMubGV2ZWwgPCA2KSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAxOwogICAgICAgICAgICB9IGVsc2UgaWYgKHMubGV2ZWwgPT09IDYpIHsKICAgICAgICAgICAgICBsZXZlbF9mbGFncyA9IDI7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAzOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGhlYWRlciB8PSBsZXZlbF9mbGFncyA8PCA2OwogICAgICAgICAgICBpZiAocy5zdHJzdGFydCAhPT0gMCkgewogICAgICAgICAgICAgIGhlYWRlciB8PSBQUkVTRVRfRElDVDsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZWFkZXIgKz0gMzEgLSBoZWFkZXIgJSAzMTsKICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBoZWFkZXIpOwogICAgICAgICAgICBpZiAocy5zdHJzdGFydCAhPT0gMCkgewogICAgICAgICAgICAgIHB1dFNob3J0TVNCKHMsIHN0cm0uYWRsZXIgPj4+IDE2KTsKICAgICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBzdHJtLmFkbGVyICYgNjU1MzUpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHN0cm0uYWRsZXIgPSAxOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IEVYVFJBX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy5nemhlYWQuZXh0cmEpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICB3aGlsZSAocy5nemluZGV4IDwgKHMuZ3poZWFkLmV4dHJhLmxlbmd0aCAmIDY1NTM1KSkgewogICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYVtzLmd6aW5kZXhdICYgMjU1KTsKICAgICAgICAgICAgICBzLmd6aW5kZXgrKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPT09IHMuZ3poZWFkLmV4dHJhLmxlbmd0aCkgewogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBOQU1FX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IE5BTUVfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gTkFNRV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLm5hbWUpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgICAgdmFsID0gMTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPCBzLmd6aGVhZC5uYW1lLmxlbmd0aCkgewogICAgICAgICAgICAgICAgdmFsID0gcy5nemhlYWQubmFtZS5jaGFyQ29kZUF0KHMuZ3ppbmRleCsrKSAmIDI1NTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdmFsID0gMDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgdmFsKTsKICAgICAgICAgICAgfSB3aGlsZSAodmFsICE9PSAwKTsKICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodmFsID09PSAwKSB7CiAgICAgICAgICAgICAgcy5nemluZGV4ID0gMDsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IENPTU1FTlRfU1RBVEU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQ09NTUVOVF9TVEFURTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBDT01NRU5UX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy5nemhlYWQuY29tbWVudCkgewogICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgICB2YWwgPSAxOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHMuZ3ppbmRleCA8IHMuZ3poZWFkLmNvbW1lbnQubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICB2YWwgPSBzLmd6aGVhZC5jb21tZW50LmNoYXJDb2RlQXQocy5nemluZGV4KyspICYgMjU1OwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB2YWwgPSAwOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBwdXRfYnl0ZShzLCB2YWwpOwogICAgICAgICAgICB9IHdoaWxlICh2YWwgIT09IDApOwogICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh2YWwgPT09IDApIHsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IEhDUkNfU1RBVEU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gSENSQ19TVEFURTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBIQ1JDX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYykgewogICAgICAgICAgICBpZiAocy5wZW5kaW5nICsgMiA+IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMucGVuZGluZyArIDIgPD0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciA+PiA4ICYgMjU1KTsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gMDsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IEJVU1lfU1RBVEU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMucGVuZGluZyAhPT0gMCkgewogICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIGlmIChzdHJtLmF2YWlsX2luID09PSAwICYmIHJhbmsoZmx1c2gpIDw9IHJhbmsob2xkX2ZsdXNoKSAmJiBmbHVzaCAhPT0gWl9GSU5JU0gpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9CVUZfRVJST1IpOwogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IEZJTklTSF9TVEFURSAmJiBzdHJtLmF2YWlsX2luICE9PSAwKSB7CiAgICAgICAgICByZXR1cm4gZXJyKHN0cm0sIFpfQlVGX0VSUk9SKTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0cm0uYXZhaWxfaW4gIT09IDAgfHwgcy5sb29rYWhlYWQgIT09IDAgfHwgZmx1c2ggIT09IFpfTk9fRkxVU0ggJiYgcy5zdGF0dXMgIT09IEZJTklTSF9TVEFURSkgewogICAgICAgICAgdmFyIGJzdGF0ZSA9IHMuc3RyYXRlZ3kgPT09IFpfSFVGRk1BTl9PTkxZID8gZGVmbGF0ZV9odWZmKHMsIGZsdXNoKSA6IHMuc3RyYXRlZ3kgPT09IFpfUkxFID8gZGVmbGF0ZV9ybGUocywgZmx1c2gpIDogY29uZmlndXJhdGlvbl90YWJsZVtzLmxldmVsXS5mdW5jKHMsIGZsdXNoKTsKICAgICAgICAgIGlmIChic3RhdGUgPT09IEJTX0ZJTklTSF9TVEFSVEVEIHx8IGJzdGF0ZSA9PT0gQlNfRklOSVNIX0RPTkUpIHsKICAgICAgICAgICAgcy5zdGF0dXMgPSBGSU5JU0hfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYnN0YXRlID09PSBCU19ORUVEX01PUkUgfHwgYnN0YXRlID09PSBCU19GSU5JU0hfU1RBUlRFRCkgewogICAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICBzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChic3RhdGUgPT09IEJTX0JMT0NLX0RPTkUpIHsKICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX1BBUlRJQUxfRkxVU0gpIHsKICAgICAgICAgICAgICB0cmVlcy5fdHJfYWxpZ24ocyk7CiAgICAgICAgICAgIH0gZWxzZSBpZiAoZmx1c2ggIT09IFpfQkxPQ0spIHsKICAgICAgICAgICAgICB0cmVlcy5fdHJfc3RvcmVkX2Jsb2NrKHMsIDAsIDAsIGZhbHNlKTsKICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfRlVMTF9GTFVTSCkgewogICAgICAgICAgICAgICAgemVybyhzLmhlYWQpOwogICAgICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHMuc3Ryc3RhcnQgPSAwOwogICAgICAgICAgICAgICAgICBzLmJsb2NrX3N0YXJ0ID0gMDsKICAgICAgICAgICAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICBzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoZmx1c2ggIT09IFpfRklOSVNIKSB7CiAgICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKHMud3JhcCA8PSAwKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRU5EOwogICAgICAgIH0KICAgICAgICBpZiAocy53cmFwID09PSAyKSB7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gOCAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDE2ICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gMjQgJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLnRvdGFsX2luID4+IDggJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiA+PiAxNiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLnRvdGFsX2luID4+IDI0ICYgMjU1KTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxlciA+Pj4gMTYpOwogICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxlciAmIDY1NTM1KTsKICAgICAgICB9CiAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICBpZiAocy53cmFwID4gMCkgewogICAgICAgICAgcy53cmFwID0gLXMud3JhcDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHMucGVuZGluZyAhPT0gMCA/IFpfT0sgOiBaX1NUUkVBTV9FTkQ7CiAgICAgIH0KICA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S5zdGF0ZTsKICAgICAgICB3cmFwID0gcy53cmFwOwogICAgICAgIGlmICh3cmFwID09PSAyIHx8IHdyYXAgPT09IDEgJiYgcy5zdGF0dXMgIT09IElOSVRfU1RBVEUgfHwgcy5sb29rYWhlYWQpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgaWYgKHdyYXAgPT09IDEpIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBhZGxlcjMyKHN0cm0uYWRsZXIsIGRpY3Rpb25hcnksIGRpY3RMZW5ndGgsIDApOwogICAgICAgIH0KICAgICAgICBzLndyYXAgPSAwOwogICAgICAgIGlmIChkaWN0TGVuZ3RoID49IHMud19zaXplKSB7CiAgICAgICAgICBpZiAod3JhcCA9PT0gMCkgewogICAgICAgICAgICB6ZXJvKHMuaGVhZCk7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgPSAwOwogICAgICAgICAgICBzLmJsb2NrX3N0YXJ0ID0gMDsKICAgICAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgICAgfQogICAgICAgICAgdG1wRGljdCA9IG5ldyB1dGlscy5CdWY4KHMud19zaXplKTsKICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHRtcERpY3QsIGRpY3Rpb25hcnksIGRpY3RMZW5ndGggLSBzLndfc2l6ZSwgcy53X3NpemUsIDApOwogICAgICAgICAgZGljdGlvbmFyeSA9IHRtcERpY3Q7CiAgICAgICAgICBkaWN0TGVuZ3RoID0gcy53X3NpemU7CiAgICAgICAgfQogICAgICAgIGF2YWlsID0gc3RybS5hdmFpbF9pbjsKICAgICAgICBuZXh0ID0gc3RybS5uZXh0X2luOwogICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gZGljdExlbmd0aDsKICAgICAgICBzdHJtLm5leHRfaW4gPSAwOwogICAgICAgIHN0cm0uaW5wdXQgPSBkaWN0aW9uYXJ5OwogICAgICA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SA1NTI5NiA8PCAxMCkgKyAoYzIgLSA1NjMyMCk7CiAgICAgICAgICAgICAgbV9wb3MrKzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgYnVmX2xlbiArPSBjIDwgMTI4ID8gMSA6IGMgPCAyMDQ4ID8gMiA6IGMgPCA2NTUzNiA/IDMgOiA0OwogICAgICAgIH0KICAgICAgICBidWYgPSBuZXcgdXRpbHMuQnVmOChidWZfbGVuKTsKICAgICAgICBmb3IgKGkgPSAwLCBtX3BvcyA9IDA7IGkgPCBidWZfbGVuOyBtX3BvcysrKSB7CiAgICAgICAgICBjID0gc3RyLmNoYXJDb2RlQXQobV9wb3MpOwogICAgICAgICAgaWYgKChjICYgNjQ1MTIpID09PSA1NTI5NiAmJiBtX3BvcyArIDEgPCBzdHJfbGVuKSB7CiAgICAgICAgICAgIGMyID0gc3RyLmNoYXJDb2RlQXQobV9wb3MgKyAxKTsKICAgICAgICAgICAgaWYgKChjMiAmIDY0NTEyKSA9PT0gNTYzMjApIHsKICAgICAgICAgICAgICBjID0gNjU1MzYgKyAoYyAtIDU1Mjk2IDw8IDEwKSArIChjMiAtIDU2MzIwKTsKICAgICAgICAgICAgICBtX3BvcysrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDEyOCkgewogICAgICAgICAgICBidWZbaSsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCAyMDQ4KSB7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTkyIHwgYyA+Pj4gNjsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCA2NTUzNikgewogICAgICAgICAgICBidWZbaSsrXSA9IDIyNCB8IGMgPj4+IDEyOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDYgJiA2MzsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBidWZbaSsrXSA9IDI0MCB8IGMgPj4+IDE4OwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDEyICYgNjM7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyA+Pj4gNiAmIDYzOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgJiA2MzsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gYnVmMmJpbnN0cmluZyhidWYsIGxlbikgewogICAgICAgIGlmIChsZW4gPCA2NTUzNCkgewogICAgICAgICAgaWYgKGJ1Zi5zdWJhcnJheSAmJiBTVFJfQVBQTFlfVUlBX09LIHx8ICFidWYuc3ViYXJyYXkgJiYgU1RSX0FQUExZX09LKSB7CiAgICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KG51bGwsIHV0aWxzLnNocmlua0J1ZihidWYsIGxlbikpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgcmVzdWx0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgfQogICAgICBleHBvcnRzMi5idWYyYmluc3RyaW5nID0gZnVuY3Rpb24oYnVmKSB7CiAgICAgICAgcmV0dXJuIGJ1ZjJiaW5zdHJpbmcoYnVmLCBidWYubGVuZ3RoKTsKICAgICAgfTsKICAgICAgZXhwb3J0czIuYmluc3RyaW5nMmJ1ZiA9IGZ1bmN0aW9uKHN0cikgewogICAgICAgIHZhciBidWYgPSBuZXcgdXRpbHMuQnVmOChzdHIubGVuZ3RoKTsKICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gYnVmLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgICBidWZbaV0gPSBzdHIuY2hhckNvZGVBdChpKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgZXhwb3J0czIuYnVmMnN0cmluZyA9IGZ1bmN0aW9uKGJ1ZiwgbWF4KSB7CiAgICAgICAgdmFyIGksIG91dCwgYywgY19sZW47CiAgICAgICAgdmFyIGxlbiA9IG1heCB8fCBidWYubGVuZ3RoOwogICAgICAgIHZhciB1dGYxNmJ1ZiA9IG5ldyBBcnJheShsZW4gKiAyKTsKICAgICAgICBmb3IgKG91dCA9IDAsIGkgPSAwOyBpIDwgbGVuOyApIHsKICAgICAgICAgIGMgPSBidWZbaSsrXTsKICAgICAgICAgIGlmIChjIDwgMTI4KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgY19sZW4gPSBfdXRmOGxlbltjXTsKICAgICAgICAgIGlmIChjX2xlbiA+IDQpIHsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNjU1MzM7CiAgICAgICAgICAgIGkgKz0gY19sZW4gLSAxOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGMgJj0gY19sZW4gPT09IDIgPyAzMSA6IGNfbGVuID09PSAzID8gMTUgOiA3OwogICAgICAgICAgd2hpbGUgKGNfbGVuID4gMSAmJiBpIDwgbGVuKSB7CiAgICAgICAgICAgIGMgPSBjIDw8IDYgfCBidWZbaSsrXSAmIDYzOwogICAgICAgICAgICBjX2xlbi0tOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGNfbGVuID4gMSkgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA2NTUzMzsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDY1NTM2KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjIC09IDY1NTM2OwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NTI5NiB8IGMgPj4gMTAgJiAxMDIzOwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NjMyMCB8IGMgJiAxMDIzOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gYnVmMmJpbnN0cmluZyh1dGYxNmJ1Ziwgb3V0KTsKICAgICAgfTsKICAgICAgZXhwb3J0czIudXRmOGJvcmRlciA9IGZ1bmN0aW9uKGJ1ZiwgbWF4KSB7CiAgICAgICAgdmFyIHBvczsKICAgICAgICBtYXggPSBtYXggfHwgYnVmLmxlbmd0aDsKICAgICAgICBpZiAobWF4ID4gYnVmLmxlbmd0aCkgewogICAgICAgICAgbWF4ID0gYnVmLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgcG9zID0gbWF4IC0gMTsKICAgICAgICB3aGlsZSAocG9zID49IDAgJiYgKGJ1Zltwb3NdICYgMTkyKSA9PT0gMTI4KSB7CiAgICAgICAgICBwb3MtLTsKICAgICAgICB9CiAgICAgICAgaWYgKHBvcyA8IDApIHsKICAgICAgICAgIHJldHVybiBtYXg7CiAgICAgICAgfQogICAgICAgIGlmIChwb3MgPT09IDApIHsKICAgICAgICAgIHJldHVybiBtYXg7CiAgICAgICAgfQogICAgICAgIHJldHVybiBwb3MgKyBfdXRmOGxlbltidWZbcG9zXV0gPiBtYXggPyBwb3MgOiBtYXg7CiAgICAgIH07CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi96c3RyZWFtLmpzCiAgdmFyIHJlcXVpcmVfenN0cmVhbSA9IF9fY29tbW9uSlMoewogICAgIm5vZG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JlX2NvbW1vbigpOwogICAgICB2YXIgc3RyaW5ncyA9IHJlcXVpcmVfc3RyaW5ncygpOwogICAgICB2YXIgbXNnID0gcmVxdWlyZV9tZXNzYWdlcygpOwogICAgICB2YXIgWlN0cmVhbSA9IHJlcXVpcmVfenN0cmVhbSgpOwogICAgICB2YXIgdG9TdHJpbmcgPSBPYmplY3QucHJvdG90eXBlLnRvU3RyaW5nOwogICAgICB2YXIgWl9OT19GTFVTSCA9IDA7CiAgICAgIHZhciBaX0ZJTklTSCA9IDQ7CiAgICAgIHZhciBaX09LID0gMDsKICAgICAgdmFyIFpfU1RSRUFNX0VORCA9IDE7CiAgICAgIHZhciBaX1NZTkNfRkxVU0gyID0gMjsKICAgICAgdmFyIFpfREVGQVVMVF9DT01QUkVTU0lPTiA9IC0xOwogICAgICB2YXIgWl9ERUZBVUxUX1NUUkFURUdZID0gMDsKICAgICAgdmFyIFpfREVGTEFURUQgPSA4OwogICAgICBmdW5jdGlvbiBEZWZsYXRlKG9wdGlvbnMpIHsKICAgICAgICBpZiAoISh0aGlzIGluc3RhbmNlb2YgRGVmbGF0ZSkpCiAgICAgICAgICByZXR1cm4gbmV3IERlZmxhdGUob3B0aW9ucyk7CiAgICAgICAgdGhpcy5vcHRpb25zID0gdXRpbHMuYXNzaWduKHsKICAgICAgICAgIGxldmVsOiBaX0RFRkFVTFRfQ09NUFJFU1NJT04sCiAgICAgICAgICBtZXRob2Q6IFpfREVGTEFURUQsCiAgICAgICAgICBjaHVua1NpemU6IDE2Mzg0LAogICAgICAgICAgd2luZG93Qml0czogMTUsCiAgICAgICAgICBtZW1MZXZlbDogOCwKICAgICAgICAgIHN0cmF0ZWd5OiBaX0RFRkFVTFRfU1RSQVRFR1ksCiAgICAgICAgICB0bzogIiIKICAgICAgICB9LCBvcHRpb25zIHx8IHt9KTsKICAgICAgICB2YXIgb3B0ID0gdGhpcy5vcHRpb25zOwogICAgICAgIGlmIChvcHQucmF3ICYmIG9wdC53aW5kb3dCaXRzID4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ZGljdGlvbmFyeSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgICAgZGljdCA9IG5ldyBVaW50OEFycmF5KG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGRpY3QgPSBvcHQuZGljdGlvbmFyeTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlU2V0RGljdGlvbmFyeSh0aGlzLnN0cm0sIGRpY3QpOwogICAgICAgICAgaWYgKHN0YXR1cyAhPT0gWl9PSykgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IobXNnW3N0YXR1c10pOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5fZGljdF9zZXQgPSB0cnVlOwogICAgICAgIH0KICAgICAgfQogICAgICBEZWZsYXRlLnByb3RvdHlwZS5wdXNoID0gZnVuY3Rpb24oZGF0YSwgbW9kZSkgewogICAgICAgIHZhciBzdHJtID0gdGhpcy5zdHJtOwogICAgICAgIHZhciBjaHVua1NpemUgPSB0aGlzLm9wdGlvbnMuY2h1bmtTaXplOwogICAgICAgIHZhciBzdGF0dXMsIF9tb2RlOwogICAgICAgIGlmICh0aGlzLmVuZGVkKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICAgIF9tb2RlID0gbW9kZSA9PT0gfn5tb2RlID8gbW9kZSA6IG1vZGUgPT09IHRydWUgPyBaX0ZJTklTSCA6IFpfTk9fRkxVU0g7CiAgICAgICAgaWYgKHR5cGVvZiBkYXRhID09PSAic3RyaW5nIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IHN0cmluZ3Muc3RyaW5nMmJ1ZihkYXRhKTsKICAgICAgICB9IGVsc2UgaWYgKHRvU3RyaW5nLmNhbGwoZGF0YSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBuZXcgVWludDhBcnJheShkYXRhKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgc3RybS5pbnB1dCA9IGRhdGE7CiAgICAgICAgfQogICAgICAgIHN0cm0ubmV4dF9pbiA9IDA7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IHN0cm0uaW5wdXQubGVuZ3RoOwogICAgICAgIGRvIHsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzdHJtLm91dHB1dCA9IG5ldyB1dGlscy5CdWY4KGNodW5rU2l6ZSk7CiAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSAwOwogICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlKHN0cm0sIF9tb2RlKTsKICAgICAgICAgIGlmIChzdGF0dXMgIT09IFpfU1RSRUFNX0VORCAmJiBzdGF0dXMgIT09IFpfT0spIHsKICAgICAgICAgICAgdGhpcy5vbkVuZChzdGF0dXMpOwogICAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwIHx8IHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgKF9tb2RlID09PSBaX0ZJTklTSCB8fCBfbW9kZSA9PT0gWl9TWU5DX0ZMVVNIMikpIHsKICAgICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICB0aGlzLm9uRGF0YShzdHJpbmdzLmJ1ZjJiaW5zdHJpbmcodXRpbHMuc2hyaW5rQnVmKHN0cm0ub3V0cHV0LCBzdHJtLm5leHRfb3V0KSkpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKHN0cm0uYXZhaWxfaW4gPiAwIHx8IHN0cm0uYXZhaWxfb3V0ID09PSAwKSAmJiBzdGF0dXMgIT09IFpfU1RSRUFNX0VORCk7CiAgICAgICAgaWYgKF9tb2RlID09PSBaX0ZJTklTSCkgewogICAgICAgICAgc3RhdHVzID0gemxpYl9kZWZsYXRlLmRlZmxhdGVFbmQodGhpcy5zdHJtKTsKICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgcmV0dXJuIHN0YXR1cyA9PT0gWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBaX1NZTkNfRkxVU0gyKSB7CiAgICAgICAgICB0aGlzLm9uRW5kKFpfT0spOwogICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0cnVlOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkRhdGEgPSBmdW5jdGlvbihjaHVuaykgewogICAgICAgIHRoaXMuY2h1bmtzLnB1c2goY2h1bmspOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkVuZCA9IGZ1bmN0aW9uKHN0YXR1cykgewogICAgICAgIGlmIChzdGF0dXMgPT09IFpfT0spIHsKICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdGhpcy5jaHVua3Muam9pbigiIik7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHV0aWxzLmZsYXR0ZW5DaHVua3ModGhpcy5jaHVua3MpOwogICAgIC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EuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9pbmZmYXN0LmpzCiAgdmFyIHJlcXVpcmVfaW5mZmFzdCA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9pbmZmYXN0LmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIEJBRCA9IDMwOwogICAgICB2YXIgVFlQRSA9IDEyOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBmdW5jdGlvbiBpbmZsYXRlX2Zhc3Qoc3RybSwgc3RhcnQpIHsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgdmFyIF9pbjsKICAgICAgICB2YXIgbGFzdDsKICAgICAgICB2YXIgX291dDsKICAgICAgICB2YXIgYmVnOwogICAgICAgIHZhciBlbmQ7CiAgICAgICAgdmFyIGRtYXg7CiAgICAgICAgdmFyIHdzaXplOwogICAgICAgIHZhciB3aGF2ZTsKICAgICAgICB2YXIgd25leHQ7CiAgICAgICAgdmFyIHNfd2luZG93OwogICAgICAgIHZhciBob2xkOwogICAgICAgIHZhciBiaXRzOwogICAgICAgIHZhciBsY29kZTsKICAgICAgICB2YXIgZGNvZGU7CiAgICAgICAgdmFyIGxtYXNrOwogICAgICAgIHZhciBkbWFzazsKICAgICAgICB2YXIgaGVyZTsKICAgICAgICB2YXIgb3A7CiAgICAgICAgdmFyIGxlbjsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgZnJvbTsKICAgICAgICB2YXIgZnJvbV9zb3VyY2U7CiAgICAgICAgdmFyIGlucHV0LCBvdXRwdXQ7CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIF9pbiA9IHN0cm0ubmV4dF9pbjsKICAgICAgICBpbnB1dCA9IHN0cm0uaW5wdXQ7CiAgICAgICAgbGFzdCA9IF9pbiArIChzdHJtLmF2YWlsX2luIC0gNSk7CiAgICAgICAgX291dCA9IHN0cm0ubmV4dF9vdXQ7CiAgICAgICAgb3V0cHV0ID0gc3RybS5vdXRwdXQ7CiAgICAgICAgYmVnID0gX291dCAtIChzdGFydCAtIHN0cm0uYXZhaWxfb3V0KTsKICAgICAgICBlbmQgPSBfb3V0ICsgKHN0cm0uYXZhaWxfb3V0IC0gMjU3KTsKICAgICAgICBkbWF4ID0gc3RhdGUuZG1heDsKICAgICAgICB3c2l6ZSA9IHN0YXRlLndzaXplOwogICAgICAgIHdoYXZlID0gc3RhdGUud2hhdmU7CiAgICAgICAgd25leHQgPSBzdGF0ZS53bmV4dDsKICAgICAgICBzX3dpbmRvdyA9IHN0YXRlLndpbmRvdzsKICAgICAgICBob2xkID0gc3RhdGUuaG9sZDsKICAgICAgICBiaXRzID0gc3RhdGUuYml0czsKICAgICAgICBsY29kZSA9IHN0YXRlLmxlbmNvZGU7CiAgICAgICAgZGNvZGUgPSBzdGF0ZS5kaXN0Y29kZTsKICAgICAgICBsbWFzayA9ICgxIDw8IHN0YXRlLmxlbmJpdHMpIC0gMTsKICAgICAgICBkbWFzayA9ICgxIDw8IHN0YXRlLmRpc3RiaXRzKSAtIDE7CiAgICAgICAgdG9wOgogICAgICAgICAgZG8gewogICAgICAgICAgICBpZiAoYml0cyA8IDE1KSB7CiAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaGVyZSA9IGxjb2RlW2hvbGQgJiBsbWFza107CiAgICAgICAgICAgIGRvbGVuOgogICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAyNDsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgaWYgKG9wID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChvcCAmIDE2KSB7CiAgICAgICAgICAgICAgICAgIGxlbiA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgb3AgJj0gMTU7CiAgICAgICAgICAgICAgICAgIGlmIChvcCkgewogICAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGxlbiArPSBob2xkICYgKDEgPDwgb3ApIC0gMTsKICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IDE1KSB7CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGVyZSA9IGRjb2RlW2hvbGQgJiBkbWFza107CiAgICAgICAgICAgICAgICAgIGRvZGlzdDoKICAgICAgICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCAmIDE2KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGRpc3QgPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICAgICAgICAgIG9wICY9IDE1OwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgZGlzdCArPSBob2xkICYgKDEgPDwgb3ApIC0gMTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGRpc3QgPiBkbWF4KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2siOwogICAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgb3AgPSBfb3V0IC0gYmVnOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZGlzdCA+IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgb3AgPSBkaXN0IC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wID4gd2hhdmUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5zYW5lKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgdG9vIGZhciBiYWNrIjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IHNfd2luZG93OwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh3bmV4dCA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSArPSB3c2l6ZSAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wIDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmICh3bmV4dCA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tICs9IHdzaXplICsgd25leHQgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9wIC09IHduZXh0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wIDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSAwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAod25leHQgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvcCA9IHduZXh0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gKz0gd25leHQgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAobGVuID4gMikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IDM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4gPiAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSAzOwogICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKGxlbiA+IDIpOwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuID4gMSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmICgob3AgJiA2NCkgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgaGVyZSA9IGRjb2RlWyhoZXJlICYgNjU1MzUpICsgKGhvbGQgJiAoMSA8PCBvcCkgLSAxKV07CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlIGRvZGlzdDsKICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgY29kZSI7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoKG9wICYgNjQpID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGhlcmUgPSBsY29kZVsoaGVyZSAmIDY1NTM1KSArIChob2xkICYgKDEgPDwgb3ApIC0gMSldOwogICAgICAgICAgICAgICAgICBjb250aW51ZSBkb2xlbjsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAob3AgJiAzMikgewogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBsaXRlcmFsL2xlbmd0aCBjb2RlIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgfQogICAgICAgICAgfSB3aGlsZSAoX2luIDwgbGFzdCAmJiBfb3V0IDwgZW5kKTsKICAgICAgICBsZW4gPSBiaXRzID4+IDM7CiAgICAgICAgX2luIC09IGxlbjsKICAgICAgICBiaXRzIC09IGxlbiA8PCAzOwogICAgICAgIGhvbGQgJj0gKDEgPDwgYml0cykgLSAxOwogICAgICAgIHN0cm0ubmV4dF9pbiA9IF9pbjsKICAgICAgICBzdHJtLm5leHRfb3V0ID0gX291dDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gX2luIDwgbGFzdCA/IDUgKyAobGFzdCAtIF9pbikgOiA1IC0gKF9pbiAtIGxhc3QpOwogICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gX291dCA8IGVuZCA/IDI1NyArIChlbmQgLSBfb3V0KSA6IDI1NyAtIChfb3V0IC0gZW5kKTsKICAgICAgICBzdGF0ZS5ob2xkID0gaG9sZDsKICAgICAgICBzdGF0ZS5iaXRzID0gYml0czsKICAgICAgICByZXR1cm47CiAgICAgIH07CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9pbmZ0cmVlcy5qcwogIHZhciByZXF1aXJlX2luZnRyZWVzID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZnRyZWVzLmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24oKTsKICAgICAgdmFyIE1BWEJJVFMgPSAxNTsKICAgICAgdmFyIEVOT1VHSF9MRU5TID0gODUyOwogICAgICB2YXIgRU5PVUdIX0RJU1RTID0gNTkyOwogICAgICB2YXIgQ09ERVMgPSAwOwogICAgICB2YXIgTEVOUyA9IDE7CiAgICAgIHZhciBESVNUUyA9IDI7CiAgICAgIHZhciBsYmFzZSA9IFsKICAgICAgICAzLAogICAgICAgIDQsCiAgICAgICAgNSwKICAgICAgICA2LAogICAgICAgIDcsCiAgICAgICAgOCwKICAgICAgICA5LAogICAgICAgIDEwLAogICAgICAgIDExLAogICAgICAgIDEzLAogICAgICAgIDE1LAogICAgICAgIDE3LAogICAgICAgIDE5LAogICAgICAgIDIzLAogICAgICAgIDI3LAogICAgICAgIDMxLAogICAgICAgIDM1LAogICAgICAgIDQzLAogICAgICAgIDUxLAogICAgICAgIDU5LAogICAgICAgIDY3LAogICAgICAgIDgzLAogICAgICAgIDk5LAogICAgICAgIDExNSwKICAgICAgICAxMzEsCiAgICAgICAgMTYzLAogICAgICAgIDE5NSwKICAgICAgICAyMjcsCiAgICAgICAgMjU4LAogICAgICAgIDAsCiAgICAgICAgMAogICAgICBdOwogICAgICB2YXIgbGV4dCA9IFsKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAxNiwKICAgICAgICA3MiwKICAgICAgICA3OAogICAgICBdOwogICAgICB2YXIgZGJhc2UgPSBbCiAgICAgICAgMSwKICAgICAgICAyLAogICAgICAgIDMsCiAgICAgICAgNCwKICAgICAgICA1LAogICAgICAgIDcsCiAgICAgICAgOSwKICAgICAgICAxMywKICAgICAgICAxNywKICAgICAgICAyNSwKICAgICAgICAzMywKICAgICAgICA0OSwKICAgICAgICA2NSwKICAgICAgICA5NywKICAgICAgICAxMjksCiAgICAgICAgMTkzLAogICAgICAgIDI1NywKICAgICAgICAzODUsCiAgICAgICAgNTEzLAogICAgICAgIDc2OSwKICAgICAgICAxMDI1LAogICAgICAgIDE1MzcsCiAgICAgICAgMjA0OSwKICAgICAgICAzMDczLAogICAgICAgIDQwOTcsCiAgICAgICAgNjE0NSwKICAgICAgICA4MTkzLAogICAgICAgIDEyMjg5LAogICAgICAgIDE2Mzg1LAogICAgICAgIDI0NTc3LAogICAgICAgIDAsCiAgICAgICAgMAogICAgICBdOwogICAgICB2YXIgZGV4dCA9IFsKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAyMiwKICAgICAgICAyMiwKICAgICAgICAyMywKICAgICAgICAyMywKICAgICAgICAyNCwKICAgICAgICAyNCwKICAgICAgICAyNSwKICAgICAgICAyNSwKICAgICAgICAyNiwKICAgICAgICAyNiwKICAgICAgICAyNywKICAgICAgICAyNywKICAgICAgICAyOCwKICAgICAgICAyOCwKICAgICAgICAyOSwKICAgICAgICAyOSwKICAgICAgICA2NCwKICAgICAgICA2NAogICAgICBdOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBmdW5jdGlvbiBpbmZsYXRlX3RhYmxlKHR5cGUsIGxlbnMsIGxlbnNfaW5kZXgsIGNvZGVzLCB0YWJsZSwgdGFibGVfaW5kZXgsIHdvcmssIG9wdHMpIHsKICAgICAgICB2YXIgYml0cyA9IG9wdHMuYml0czsKICAgICAgICB2YXIgbGVuID0gMDsKICAgICAgICB2YXIgc3ltID0gMDsKICAgICAgICB2YXIgbWluID0gMCwgbWF4ID0gMDsKICAgICAgICB2YXIgcm9vdDIgPSAwOwogICAgICAgIHZhciBjdXJyID0gMDsKICAgICAgICB2YXIgZHJvcCA9IDA7CiAgICAgICAgdmFyIGxlZnQgPSAwOwogICAgICAgIHZhciB1c2VkID0gMDsKICAgICAgICB2YXIgaHVmZiA9IDA7CiAgICAgICAgdmFyIGluY3I7CiAgICAgICAgdmFyIGZpbGw7CiAgICAgICAgdmFyIGxvdzsKICAgICAgICB2YXIgbWFzazsKICAgICAgICB2YXIgbmV4dDsKICAgICAgICB2YXIgYmFzZSA9IG51bGw7CiAgICAgICAgdmFyIGJhc2VfaW5kZXggPSAwOwogICAgICAgIHZhciBlbmQ7CiAgICAgICAgdmFyIGNvdW50ID0gbmV3IHV0aWxzLkJ1ZjE2KE1BWEJJVFMgKyAxKTsKICAgICAgICB2YXIgb2ZmcyA9IG5ldyB1dGlscy5CdWYxNihNQVhCSVRTICsgMSk7CiAgICAgICAgdmFyIGV4dHJhID0gbnVsbDsKICAgICAgICB2YXIgZXh0cmFfaW5kZXggPSAwOwogICAgICAgIHZhciBoZXJlX2JpdHMsIGhlcmVfb3AsIGhlcmVfdmFsOwogICAgICAgIGZvciAobGVuID0gMDsgbGVuIDw9IE1BWEJJVFM7IGxlbisrKSB7CiAgICAgICAgICBjb3VudFtsZW5dID0gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChzeW0gPSAwOyBzeW0gPCBjb2Rlczsgc3ltKyspIHsKICAgICAgICAgIGNvdW50W2xlbnNbbGVuc19pbmRleCArIHN5bV1dKys7CiAgICAgICAgfQogICAgICAgIHJvb3QyID0gYml0czsKICAgICAgICBmb3IgKG1heCA9IE1BWEJJVFM7IG1heCA+PSAxOyBtYXgtLSkgewogICAgICAgICAgaWYgKGNvdW50W21heF0gIT09IDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChyb290MiA+IG1heCkgewogICAgICAgICAgcm9vdDIgPSBtYXg7CiAgICAgICAgfQogICAgICAgIGlmIChtYXggPT09IDApIHsKICAgICAgICAgIHRhYmxlW3RhYmxlX2luZGV4KytdID0gMSA8PCAyNCB8IDY0IDw8IDE2IHwgMDsKICAgICAgICAgIHRhYmxlW3RhYmxlX2luZGV4KytdID0gMSA8PCAyNCB8IDY0IDw8IDE2IHwgMDsKICAgICAgICAgIG9wdHMuYml0cyA9IDE7CiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChtaW4gPSAxOyBtaW4gPCBtYXg7IG1pbisrKSB7CiAgICAgICAgICBpZiAoY291bnRbbWluXSAhPT0gMCkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHJvb3QyIDwgbWluKSB7CiAgICAgICAgICByb290MiA9IG1pbjsKICAgICAgICB9CiAgICAgICAgbGVmdCA9IDE7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPD0gTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIGxlZnQgPDw9IDE7CiAgICAgICAgICBsZWZ0IC09IGNvdW50W2xlbl07CiAgICAgICAgICBpZiAobGVmdCA8IDApIHsKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAobGVmdCA+IDAgJiYgKHR5cGUgPT09IENPREVTIHx8IG1heCAhPT0gMSkpIHsKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgb2Zmc1sxXSA9IDA7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPCBNQVhCSVRTOyBsZW4rKykgewogICAgICAgICAgb2Zmc1tsZW4gKyAxXSA9IG9mZnNbbGVuXSArIGNvdW50W2xlbl07CiAgICAgICAgfQogICAgICAgIGZvciAoc3ltID0gMDsgc3ltIDwgY29kZXM7IHN5bSsrKSB7CiAgICAgICAgICBpZiAobGVuc1tsZW5zX2luZGV4ICsgc3ltXSAhPT0gMCkgewogICAgICAgICAgICB3b3JrW29mZnNbbGVuc1tsZW5zX2luZGV4ICsgc3ltXV0rK10gPSBzeW07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlID09PSBDT0RFUykgewogICAgICAgICAgYmFzZSA9IGV4dHJhID0gd29yazsKICAgICAgICAgIGVuZCA9IDE5OwogICAgICAgIH0gZWxzZSBpZiAodHlwZSA9PT0gTEVOUykgewogICAgICAgICAgYmFzZSA9IGxiYXNlOwogICAgICAgICAgYmFzZV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBleHRyYSA9IGxleHQ7CiAgICAgICAgICBleHRyYV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBlbmQgPSAyNTY7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGJhc2UgPSBkYmFzZTsKICAgICAgICAgIGV4dHJhID0gZGV4dDsKICAgICAgICAgIGVuZCA9IC0xOwogICAgICAgIH0KICAgICAgICBodWZmID0gMDsKICAgICAgICBzeW0gPSAwOwogICAgICAgIGxlbiA9IG1pbjsKICAgICAgICBuZXh0ID0gdGFibGVfaW5kZXg7CiAgICAgICAgY3VyciA9IHJvb3QyOwogICAgICAgIGRyb3AgPSAwOwogICAgICAgIGxvdyA9IC0xOwogICAgICAgIHVzZWQgPSAxIDw8IHJvb3QyOwogICAgICAgIG1hc2sgPSB1c2VkIC0gMTsKICAgICAgICBpZiAodHlwZSA9PT0gTEVOUyAmJiB1c2VkID4gRU5PVUdIX0xFTlMgfHwgdHlwZSA9PT0gRElTVFMgJiYgdXNlZCA+IEVOT1VHSF9ESVNUUykgewogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgfQogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaGVyZV9iaXRzID0gbGVuIC0gZHJvcDsKICAgICAgICAgIGlmICh3b3JrW3N5bV0gPCBlbmQpIHsKICAgICAgICAgICAgaGVyZV9vcCA9IDA7CiAgICAgICAgICAgIGhlcmVfdmFsID0gd29ya1tzeW1dOwogICAgICAgICAgfSBlbHNlIGlmICh3b3JrW3N5bV0gPiBlbmQpIHsKICAgICAgICAgICAgaGVyZV9vcCA9IGV4dHJhW2V4dHJhX2luZGV4ICsgd29ya1tzeW1dXTsKICAgICAgICAgICAgaGVyZV92YWwgPSBiYXNlW2Jhc2VfaW5kZXggKyB3b3JrW3N5bV1dOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaGVyZV9vcCA9IDMyICsgNjQ7CiAgICAgICAgICAgIGhlcmVfdmFsID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIGluY3IgPSAxIDw8IGxlbiAtIGRyb3A7CiAgICAgICAgICBmaWxsID0gMSA8PCBjdXJyOwogICAgICAgICAgbWluID0gZmlsbDsKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgZmlsbCAtPSBpbmNyOwogICAgICAgICAgICB0YWJsZVtuZXh0ICsgKGh1ZmYgPj4gZHJvcCkgKyBmaWxsXSA9IGhlcmVfYml0cyA8PCAyNCB8IGhlcmVfb3AgPDwgMTYgfCBoZXJlX3ZhbCB8IDA7CiAgICAgICAgICB9IHdoaWxlIChmaWxsICE9PSAwKTsKICAgICAgICAgIGluY3IgPSAxIDw8IGxlbiAtIDE7CiAgICAgICAgICB3aGlsZSAoaHVmZiAmIGluY3IpIHsKICAgICAgICAgICAgaW5jciA+Pj0gMTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChpbmNyICE9PSAwKSB7CiAgICAgICAgICAgIGh1ZmYgJj0gaW5jciAtIDE7CiAgICAgICAgICAgIGh1ZmYgKz0gaW5jcjsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGh1ZmYgPSAwOwogICAgICAgICAgfQogICAgICAgICAgc3ltKys7CiAgICAgICAgICBpZiAoLS1jb3VudFtsZW5dID09PSAwKSB7CiAgICAgICAgICAgIGlmIChsZW4gPT09IG1heCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxlbiA9IGxlbnNbbGVuc19pbmRleCArIHdvcmtbc3ltXV07CiAgICAgICAgICB9CiAgICAgICAgICBpZiAobGVuID4gcm9vdDIgJiYgKGh1ZmYgJiBtYXNrKSAhPT0gbG93KSB7CiAgICAgICAgICAgIGlmIChkcm9wID09PSAwKSB7CiAgICAgICAgICAgICAgZHJvcCA9IHJvb3QyOwogICAgICAgICAgICB9CiAgICAgICAgICAgIG5leHQgKz0gbWluOwogICAgICAgICAgICBjdXJyID0gbGVuIC0gZHJvcDsKICAgICAgICAgICAgbGVmdCA9IDEgPDwgY3VycjsKICAgICAgICAgICAgd2hpbGUgKGN1cnIgKyBkcm9wIDwgbWF4KSB7CiAgICAgICAgICAgICAgbGVmdCAtPSBjb3VudFtjdXJyICsgZHJvcF07CiAgICAgICAgICAgICAgaWYgKGxlZnQgPD0gMCkgewogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGN1cnIrKzsKICAgICAgICAgICAgICBsZWZ0IDw8PSAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHVzZWQgKz0gMSA8PCBjdXJyOwogICAgICAgICAgICBpZiAodHlwZSA9PT0gTEVOUyAmJiB1c2VkID4gRU5PVUdIX0xFTlMgfHwgdHlwZSA9PT0gRElTVFMgJiYgdXNlZCA+IEVOT1VHSF9ESVNUUykgewogICAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxvdyA9IGh1ZmYgJiBtYXNrOwogICAgICAgICAgICB0YWJsZVtsb3ddID0gcm9vdDIgPDwgMjQgfCBjdXJyIDw8IDE2IHwgbmV4dCAtIHRhYmxlX2luZGV4IHwgMDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGh1ZmYgIT09IDApIHsKICAgICAgICAgIHRhYmxlW25leHQgKyBodWZmXSA9IGxlbiAtIGRyb3AgPDwgMjQgfCA2NCA8PCAxNiB8IDA7CiAgICAgICAgfQogICAgICAgIG9wdHMuYml0cyA9IHJvb3QyOwogICAgICAgIHJldHVybiAwOwogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZ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YXIgRVhMRU4gPSA1OwogICAgICB2YXIgRVhUUkEgPSA2OwogICAgICB2YXIgTkFNRSA9IDc7CiAgICAgIHZhciBDT01NRU5UID0gODsKICAgICAgdmFyIEhDUkMgPSA5OwogICAgICB2YXIgRElDVElEID0gMTA7CiAgICAgIHZhciBESUNUID0gMTE7CiAgICAgIHZhciBUWVBFID0gMTI7CiAgICAgIHZhciBUWVBFRE8gPSAxMzsKICAgICAgdmFyIFNUT1JFRCA9IDE0OwogICAgICB2YXIgQ09QWV8gPSAxNTsKICAgICAgdmFyIENPUFkgPSAxNjsKICAgICAgdmFyIFRBQkxFID0gMTc7CiAgICAgIHZhciBMRU5MRU5TID0gMTg7CiAgICAgIHZhciBDT0RFTEVOUyA9IDE5OwogICAgICB2YXIgTEVOXyA9IDIwOwogICAgICB2YXIgTEVOID0gMjE7CiAgICAgIHZhciBMRU5FWFQgPSAyMjsKICAgICAgdmFyIERJU1QgPSAyMzsKICAgICAgdmFyIERJU1RFWFQgPSAyNDsKICAgICAgdmFyIE1BVENIID0gMjU7CiAgICAgIHZhciBMSVQgPSAyNjsKICAgICAgdmFyIENIRUNLID0gMjc7CiAgICAgIHZhciBMRU5HVEggPSAyODsKICAgICAgdmFyIERPTkUgPSAyOTsKICAgICAgdmFyIEJBRCA9IDMwOwogICAgICB2YXIgTUVNID0gMzE7CiAgICAgIHZhciBTWU5DID0gMzI7CiAgICAgIHZhciBFTk9VR0hfTEVOUyA9IDg1MjsKICAgICAgdmFyIEVOT1VHSF9ESVNUUyA9IDU5MjsKICAgICAgdmFyIE1BWF9XQklUUyA9IDE1OwogICAgICB2YXIgREVGX1dCSVRTID0gTUFYX1dCSVRTOwogICAgICBmdW5jdGlvbiB6c3dhcDMyKHEpIHsKICAgICAgICByZXR1cm4gKHEgPj4+IDI0ICYgMjU1KSArIChxID4+PiA4ICYgNjUyODApICsgKChxICYgNjUyODApIDw8IDgpICsgKChxICYgMjU1KSA8PCAyNCk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gSW5mbGF0ZVN0YXRlKCkgewogICAgICAgIHRoaXMubW9kZSA9IDA7CiAgICAgICAgdGhpcy5sYXN0ID0gZmFsc2U7CiAgICAgICAgdGhpcy53cmFwID0gMDsKICAgICAgICB0aGlzLmhhdmVkaWN0ID0gZmFsc2U7CiAgICAgICAgdGhpcy5mbGFncyA9IDA7CiAgICAgICAgdGhpcy5kbWF4ID0gMDsKICAgICAgICB0aGlzLmNoZWNrID0gMDsKICAgICAgICB0aGlzLnRvdGFsID0gMDsKICAgICAgICB0aGlzLmhlYWQgPSBudWxsOwogICAgICAgIHRoaXMud2JpdHMgPSAwOwogICAgICAgIHRoaXMud3NpemUgPSAwOwogICAgICAgIHRoaXMud2hhdmUgPSAwOwogICAgICAgIHRoaXMud25leHQgPSAwOwogICAgICAgIHRoaXMud2luZG93ID0gbnVsbDsKICAgICAgICB0aGlzLmhvbGQgPSAwOwogICAgICAgIHRoaXMuYml0cyA9IDA7CiAgICAgICAgdGhpcy5sZW5ndGggPSAwOwogICAgICAgIHRoaXMub2Zmc2V0ID0gMDsKICAgICAgICB0aGlzLmV4dHJhID0gMDsKICAgICAgICB0aGlzLmxlbmNvZGUgPSBudWxsOwogICAgICAgIHRoaXMuZGlzdGNvZGUgPSBudWxsOwogICAgICAgIHRoaXMubGVuYml0cyA9IDA7CiAgICAgICAgdGhpcy5kaXN0Yml0cyA9IDA7CiAgICAgICAgdGhpcy5uY29kZSA9IDA7CiAgICAgICAgdGhpcy5ubGVuID0gMDsKICAgICAgICB0aGlzLm5kaXN0ID0gMDsKICAgICAgICB0aGlzLmhhdmUgPSAwOwogICAgICAgIHRoaXMubmV4dCA9IG51bGw7CiAgICAgICAgdGhpcy5sZW5zID0gbmV3IHV0aWxzLkJ1ZjE2KDMyMCk7CiAgICAgICAgdGhpcy53b3JrID0gbmV3IHV0aWxzLkJ1ZjE2KDI4OCk7CiAgICAgICAgdGhpcy5sZW5keW4gPSBudWxsOwogICAgICAgIHRoaXMuZGlzdGR5biA9IG51bGw7CiAgICAgICAgdGhpcy5zYW5lID0gMDsKICAgICAgICB0aGlzLmJhY2sgPSAwOwogICAgICAgIHRoaXMud2FzID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlUmVzZXRLZWVwKHN0cm0pIHsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBzdHJtLnRvdGFsX2luID0gc3RybS50b3RhbF9vdXQgPSBzdGF0ZS50b3RhbCA9IDA7CiAgICAgICAgc3RybS5tc2cgPSAiIjsKICAgICAgICBpZiAoc3RhdGUud3JhcCkgewogICAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLndyYXAgJiAxOwogICAgICAgIH0KICAgICAgICBzdGF0ZS5tb2RlID0gSEVBRDsKICAgICAgICBzdGF0ZS5sYXN0ID0gMDsKICAgICAgICBzdGF0ZS5oYXZlZGljdCA9IDA7CiAgICAgICAgc3RhdGUuZG1heCA9IDMyNzY4OwogICAgICAgIHN0YXRlLmhlYWQgPSBudWxsOwogICAgICAgIHN0YXRlLmhvbGQgPSAwOwogICAgICAgIHN0YXRlLmJpdHMgPSAwOwogICAgICAgIHN0YXRlLmxlbmNvZGUgPSBzdGF0ZS5sZW5keW4gPSBuZXcgdXRpbHMuQnVmMzIoRU5PVUdIX0xFTlMpOwogICAgICAgIHN0YXRlLmRpc3Rjb2RlID0gc3RhdGUuZGlzdGR5biA9IG5ldyB1dGlscy5CdWYzMihFTk9VR0hfRElTVFMpOwogICAgICAgIHN0YXRlLnNhbmUgPSAxOwogICAgICAgIHN0YXRlLmJhY2sgPSAtMTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlUmVzZXQoc3RybSkgewogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIHN0YXRlLndzaXplID0gMDsKICAgICAgICBzdGF0ZS53aGF2ZSA9IDA7CiAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgIHJldHVybiBpbmZsYXRlUmVzZXRLZWVwKHN0cm0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVSZXNldDIoc3RybSwgd2luZG93Qml0cykgewogICAgICAgIHZhciB3cmFwOwogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmICh3aW5kb3dCaXRzIDwgMCkgewogICAgICAgICAgd3JhcCA9IDA7CiAgICAgICAgICB3aW5kb3dCaXRzID0gLXdpbmRvd0JpdHM7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHdyYXAgPSAod2luZG93Qml0cyA+PiA0KSArIDE7CiAgICAgICAgICBpZiAod2luZG93Qml0cyA8IDQ4KSB7CiAgICAgICAgICAgIHdpbmRvd0JpdHMgJj0gMTU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICh3aW5kb3dCaXRzICYmICh3aW5kb3dCaXRzIDwgOCB8fCB3aW5kb3dCaXRzID4gMTUpKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmIChzdGF0ZS53aW5kb3cgIT09IG51bGwgJiYgc3RhdGUud2JpdHMgIT09IHdpbmRvd0JpdHMpIHsKICAgICAgICAgIHN0YXRlLndpbmRvdyA9IG51bGw7CiAgICAgICAgfQogICAgICAgIHN0YXRlLndyYXAgPSB3cmFwOwogICAgICAgIHN0YXRlLndiaXRzID0gd2luZG93Qml0czsKICAgICAgICByZXR1cm4gaW5mbGF0ZVJlc2V0KHN0cm0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVJbml0MihzdHJtLCB3aW5kb3dCaXRzKSB7CiAgICAgICAgdmFyIHJldDsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgaWYgKCFzdHJtKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gbmV3IEluZmxhdGVTdGF0ZSgpOwogICAgICAgIHN0cm0uc3RhdGUgPSBzdGF0ZTsKICAgICAgICBzdGF0ZS53aW5kb3cgPSBudWxsOwogICAgICAgIHJldCA9IGluZmxhdGVSZXNldDIoc3RybSwgd2luZG93Qml0cyk7CiAgICAgICAgaWYgKHJldCAhPT0gWl9PSykgewogICAgICAgICAgc3RybS5zdGF0ZSA9IG51bGw7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZUluaXQoc3RybSkgewogICAgICAgIHJldHVybiBpbmZsYXRlSW5pdDIoc3RybSwgREVGX1dCSVRTKTsKICAgICAgfQogICAgICB2YXIgdmlyZ2luID0gdHJ1ZTsKICAgICAgdmFyIGxlbmZpeDsKICAgICAgdmFyIGRpc3RmaXg7CiAgICAgIGZ1bmN0aW9uIGZpeGVkdGFibGVzKHN0YXRlKSB7CiAgICAgICAgaWYgKHZpcmdpbikgewogICAgICAgICAgdmFyIHN5bTsKICAgICAgICAgIGxlbmZpeCA9IG5ldyB1dGlscy5CdWYzMig1MTIpOwogICAgICAgICAgZGlzdGZpeCA9IG5ldyB1dGlscy5CdWYzMigzMik7CiAgICAgICAgICBzeW0gPSAwOwogICAgICAgICAgd2hpbGUgKHN5bSA8IDE0NCkgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDg7CiAgICAgICAgICB9CiAgICAgICAgICB3aGlsZSAoc3ltIDwgMjU2KSB7CiAgICAgICAgICAgIHN0YXRlLmxlbnNbc3ltKytdID0gOTsKICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzeW0gPCAyODApIHsKICAgICAgICAgICAgc3RhdGUubGVuc1tzeW0rK10gPSA3OwogICAgICAgICAgfQogICAgICAgICAgd2hpbGUgKHN5bSA8IDI4OCkgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDg7CiAgICAgICAgICB9CiAgICAgICAgICBpbmZsYXRlX3RhYmxlKExFTlMsIHN0YXRlLmxlbnMsIDAsIDI4OCwgbGVuZml4LCAwLCBzdGF0ZS53b3JrLCB7IGJpdHM6IDkgfSk7CiAgICAgICAgICBzeW0gPSAwOwogICAgICAgICAgd2hpbGUgKHN5bSA8IDMyKSB7CiAgICAgICAgICAgIHN0YXRlLmxlbnNbc3ltKytdID0gNTsKICAgICAgICAgIH0KICAgICAgICAgIGluZmxhdGVfdGFibGUoRElTVFMsIHN0YXRlLmxlbnMsIDAsIDMyLCBkaXN0Zml4LCAwLCBzdGF0ZS53b3JrLCB7IGJpdHM6IDUgfSk7CiAgICAgICAgICB2aXJnaW4gPSBmYWxzZTsKICAgICAgICB9CiAgICAgICAgc3RhdGUubGVuY29kZSA9IGxlbmZpeDsKICAgICAgICBzdGF0ZS5sZW5iaXRzID0gOTsKICAgICAgICBzdGF0ZS5kaXN0Y29kZSA9IGRpc3RmaXg7CiAgICAgICAgc3RhdGUuZGlzdGJpdHMgPSA1OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHVwZGF0ZXdpbmRvdyhzdHJtLCBzcmMsIGVuZCwgY29weSkgewogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgaWYgKHN0YXRlLndpbmRvdyA9PT0gbnVsbCkgewogICAgICAgICAgc3RhdGUud3NpemUgPSAxIDw8IHN0YXRlLndiaXRzOwogICAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgICAgc3RhdGUud2hhdmUgPSAwOwogICAgICAgICAgc3RhdGUud2luZG93ID0gbmV3IHV0aWxzLkJ1Zjgoc3RhdGUud3NpemUpOwogICAgICAgIH0KICAgICAgICBpZiAoY29weSA+PSBzdGF0ZS53c2l6ZSkgewogICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RhdGUud2luZG93LCBzcmMsIGVuZCAtIHN0YXRlLndzaXplLCBzdGF0ZS53c2l6ZSwgMCk7CiAgICAgICAgICBzdGF0ZS53bmV4dCA9IDA7CiAgICAgICAgICBzdGF0ZS53aGF2ZSA9IHN0YXRlLndzaXplOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBkaXN0ID0gc3RhdGUud3NpemUgLSBzdGF0ZS53bmV4dDsKICAgICAgICAgIGlmIChkaXN0ID4gY29weSkgewogICAgICAgICAgICBkaXN0ID0gY29weTsKICAgICAgICAgIH0KICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHN0YXRlLndpbmRvdywgc3JjLCBlbmQgLSBjb3B5LCBkaXN0LCBzdGF0ZS53bmV4dCk7CiAgICAgICAgICBjb3B5IC09IGRpc3Q7CiAgICAgICAgICBpZiAoY29weSkgewogICAgICAgICAgICB1dGlscy5hcnJheVNldChzdGF0ZS53aW5kb3csIHNyYywgZW5kIC0gY29weSwgY29weSwgMCk7CiAgICAgICAgICAgIHN0YXRlLnduZXh0ID0gY29weTsKICAgICAgICAgICAgc3RhdGUud2hhdmUgPSBzdGF0ZS53c2l6ZTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHN0YXRlLnduZXh0ICs9IGRpc3Q7CiAgICAgICAgICAgIGlmIChzdGF0ZS53bmV4dCA9PT0gc3RhdGUud3NpemUpIHsKICAgICAgICAgICAgICBzdGF0ZS53bmV4dCA9IDA7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHN0YXRlLndoYXZlIDwgc3RhdGUud3NpemUpIHsKICAgICAgICAgICAgICBzdGF0ZS53aGF2ZSArPSBkaXN0OwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGUoc3RybSwgZmx1c2gpIHsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgdmFyIGlucHV0LCBvdXRwdXQ7CiAgICAgICAgdmFyIG5leHQ7CiAgICAgICAgdmFyIHB1dDsKICAgICAgICB2YXIgaGF2ZSwgbGVmdDsKICAgICAgICB2YXIgaG9sZDsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgX2luLCBfb3V0OwogICAgICAgIHZhciBjb3B5OwogICAgICAgIHZhciBmcm9tOwogICAgICAgIHZhciBmcm9tX3NvdXJjZTsKICAgICAgICB2YXIgaGVyZSA9IDA7CiAgICAgICAgdmFyIGhlcmVfYml0cywgaGVyZV9vcCwgaGVyZV92YWw7CiAgICAgICAgdmFyIGxhc3RfYml0cywgbGFzdF9vcCwgbGFzdF92YWw7CiAgICAgICAgdmFyIGxlbjsKICAgICAgICB2YXIgcmV0OwogICAgICAgIHZhciBoYnVmID0gbmV3IHV0aWxzLkJ1ZjgoNCk7CiAgICAgICAgdmFyIG9wdHM7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIG9yZGVyID0gWzE2LCAxNywgMTgsIDAsIDgsIDcsIDksIDYsIDEwLCA1LCAxMSwgNCwgMTIsIDMsIDEzLCAyLCAxNCwgMSwgMTVdOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSB8fCAhc3RybS5vdXRwdXQgfHwgIXN0cm0uaW5wdXQgJiYgc3RybS5hdmFpbF9pbiAhPT0gMCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IFRZUEUpIHsKICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFRE87CiAgICAgICAgfQogICAgICAgIHB1dCA9IHN0cm0ubmV4dF9vdXQ7CiAgICAgICAgb3V0cHV0ID0gc3RybS5vdXRwdXQ7CiAgICAgICAgbGVmdCA9IHN0cm0uYXZhaWxfb3V0OwogICAgICAgIG5leHQgPSBzdHJtLm5leHRfaW47CiAgICAgICAgaW5wdXQgPSBzdHJtLmlucHV0OwogICAgICAgIGhhdmUgPSBzdHJtLmF2YWlsX2luOwogICAgICAgIGhvbGQgPSBzdGF0ZS5ob2xkOwogICAgICAgIGJpdHMgPSBzdGF0ZS5iaXRzOwogICAgICAgIF9pbiA9IGhhdmU7CiAgICAgICAgX291dCA9IGxlZnQ7CiAgICAgICAgcmV0ID0gWl9PSzsKICAgICAgICBpbmZfbGVhdmU6CiAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgc3dpdGNoIChzdGF0ZS5tb2RlKSB7CiAgICAgICAgICAgICAgY2FzZSBIRUFEOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLndyYXAgPT09IDApIHsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRZUEVETzsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwICYgMiAmJiBob2xkID09PSAzNTYxNSkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IDA7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEZMQUdTOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmZsYWdzID0gMDsKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZG9uZSA9IGZhbHNlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKCEoc3RhdGUud3JhcCAmIDEpIHx8ICgoKGhvbGQgJiAyNTUpIDw8IDgpICsgKGhvbGQgPj4gOCkpICUgMzEpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW5jb3JyZWN0IGhlYWRlciBjaGVjayI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKChob2xkICYgMTUpICE9PSBaX0RFRkxBVEVEKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gInVua25vd24gY29tcHJlc3Npb24gbWV0aG9kIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gNDsKICAgICAgICAgICAgICAgIGJpdHMgLT0gNDsKICAgICAgICAgICAgICAgIGxlbiA9IChob2xkICYgMTUpICsgODsKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53Yml0cyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS53Yml0cyA9IGxlbjsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAobGVuID4gc3RhdGUud2JpdHMpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCB3aW5kb3cgc2l6ZSI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZG1heCA9IDEgPDwgbGVuOwogICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLmNoZWNrID0gMTsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBob2xkICYgNTEyID8gRElDVElEIDogVFlQRTsKICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIEZMQUdTOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5mbGFncyA9IGhvbGQ7CiAgICAgICAgICAgICAgICBpZiAoKHN0YXRlLmZsYWdzICYgMjU1KSAhPT0gWl9ERUZMQVRFRCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJ1bmtub3duIGNvbXByZXNzaW9uIG1ldGhvZCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTczNDQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAidW5rbm93biBoZWFkZXIgZmxhZ3Mgc2V0IjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLnRleHQgPSBob2xkID4+IDggJiAxOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRJTUU7CiAgICAgICAgICAgICAgY2FzZSBUSU1FOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLnRpbWUgPSBob2xkOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlsyXSA9IGhvbGQgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzNdID0gaG9sZCA+Pj4gMjQgJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGhidWYsIDQsIDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBPUzsKICAgICAgICAgICAgICBjYXNlIE9TOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLnhmbGFncyA9IGhvbGQgJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQub3MgPSBob2xkID4+IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1MTIpIHsKICAgICAgICAgICAgICAgICAgaGJ1ZlswXSA9IGhvbGQgJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhidWZbMV0gPSBob2xkID4+PiA4ICYgMjU1OwogICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IGNyYzMyKHN0YXRlLmNoZWNrLCBoYnVmLCAyLCAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gRVhMRU47CiAgICAgICAgICAgICAgY2FzZSBFWExFTjoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDEwMjQpIHsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgc3RhdGUubGVuZ3RoID0gaG9sZDsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmV4dHJhX2xlbiA9IGhvbGQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgICAgaGJ1ZlswXSA9IGhvbGQgJiAyNTU7CiAgICAgICAgICAgICAgICAgICAgaGJ1ZlsxXSA9IGhvbGQgPj4+IDggJiAyNTU7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZXh0cmEgPSBudWxsOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEVYVFJBOwogICAgICAgICAgICAgIGNhc2UgRVhUUkE6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiAxMDI0KSB7CiAgICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gaGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBoYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IHN0YXRlLmhlYWQuZXh0cmFfbGVuIC0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgICAgICAgaWYgKCFzdGF0ZS5oZWFkLmV4dHJhKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZXh0cmEgPSBuZXcgQXJyYXkoc3RhdGUuaGVhZC5leHRyYV9sZW4pOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RhdGUuaGVhZC5leHRyYSwgaW5wdXQsIG5leHQsIGNvcHksIGxlbik7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaW5wdXQsIGNvcHksIG5leHQpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlIC09IGNvcHk7CiAgICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCAtPSBjb3B5OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTkFNRTsKICAgICAgICAgICAgICBjYXNlIE5BTUU6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiAyMDQ4KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGNvcHkgPSAwOwogICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgbGVuID0gaW5wdXRbbmV4dCArIGNvcHkrK107CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQgJiYgbGVuICYmIHN0YXRlLmxlbmd0aCA8IDY1NTM2KSB7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLm5hbWUgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShsZW4pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfSB3aGlsZSAobGVuICYmIGNvcHkgPCBoYXZlKTsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaW5wdXQsIGNvcHksIG5leHQpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUgLT0gY29weTsKICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5uYW1lID0gbnVsbDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQ09NTUVOVDsKICAgICAgICAgICAgICBjYXNlIENPTU1FTlQ6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA0MDk2KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGNvcHkgPSAwOwogICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgbGVuID0gaW5wdXRbbmV4dCArIGNvcHkrK107CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQgJiYgbGVuICYmIHN0YXRlLmxlbmd0aCA8IDY1NTM2KSB7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmNvbW1lbnQgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShsZW4pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfSB3aGlsZSAobGVuICYmIGNvcHkgPCBoYXZlKTsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaW5wdXQsIGNvcHksIG5leHQpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUgLT0gY29weTsKICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5jb21tZW50ID0gbnVsbDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBIQ1JDOwogICAgICAgICAgICAgIGNhc2UgSENSQzoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoaG9sZCAhPT0gKHN0YXRlLmNoZWNrICYgNjU1MzUpKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaGVhZGVyIGNyYyBtaXNtYXRjaCI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmhjcmMgPSBzdGF0ZS5mbGFncyA+PiA5ICYgMTsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5kb25lID0gdHJ1ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgRElDVElEOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSB6c3dhcDMyKGhvbGQpOwogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBESUNUOwogICAgICAgICAgICAgIGNhc2UgRElDVDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oYXZlZGljdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gcHV0OwogICAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGxlZnQ7CiAgICAgICAgICAgICAgICAgIHN0cm0ubmV4dF9pbiA9IG5leHQ7CiAgICAgICAgICAgICAgICAgIHN0cm0uYXZhaWxfaW4gPSBoYXZlOwogICAgICAgICAgICAgICAgICBzdGF0ZS5ob2xkID0gaG9sZDsKICAgICAgICAgICAgICAgICAgc3RhdGUuYml0cyA9IGJpdHM7CiAgICAgICAgICAgICAgICAgIHJldHVybiBaX05FRURfRElDVDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IDE7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICBjYXNlIFRZUEU6CiAgICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfQkxPQ0sgfHwgZmx1c2ggPT09IFpfVFJFRVMpIHsKICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGNhc2UgVFlQRURPOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmxhc3QpIHsKICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgICBiaXRzIC09IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQ0hFQ0s7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzKSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxhc3QgPSBob2xkICYgMTsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAxOwogICAgICAgICAgICAgICAgYml0cyAtPSAxOwogICAgICAgICAgICAgICAgc3dpdGNoIChob2xkICYgMykgewogICAgICAgICAgICAgICAgICBjYXNlIDA6CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFNUT1JFRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgICAgICAgIGZpeGVkdGFibGVzKHN0YXRlKTsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOXzsKICAgICAgICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfVFJFRVMpIHsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAyOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSAyOwogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUQUJMRTsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAzOgogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYmxvY2sgdHlwZSI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAyOwogICAgICAgICAgICAgICAgYml0cyAtPSAyOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBTVE9SRUQ6CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gYml0cyAmIDc7CiAgICAgICAgICAgICAgICBiaXRzIC09IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoKGhvbGQgJiA2NTUzNSkgIT09IChob2xkID4+PiAxNiBeIDY1NTM1KSkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIHN0b3JlZCBibG9jayBsZW5ndGhzIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSBob2xkICYgNjU1MzU7CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENPUFlfOwogICAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX1RSRUVTKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBjYXNlIENPUFlfOgogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENPUFk7CiAgICAgICAgICAgICAgY2FzZSBDT1BZOgogICAgICAgICAgICAgICAgY29weSA9IHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgIGlmIChjb3B5KSB7CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gaGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBoYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gbGVmdCkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBsZWZ0OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KG91dHB1dCwgaW5wdXQsIG5leHQsIGNvcHksIHB1dCk7CiAgICAgICAgICAgICAgICAgIGhhdmUgLT0gY29weTsKICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBsZWZ0IC09IGNvcHk7CiAgICAgICAgICAgICAgICAgIHB1dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgVEFCTEU6CiAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE0KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm5sZW4gPSAoaG9sZCAmIDMxKSArIDI1NzsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA1OwogICAgICAgICAgICAgICAgYml0cyAtPSA1OwogICAgICAgICAgICAgICAgc3RhdGUubmRpc3QgPSAoaG9sZCAmIDMxKSArIDE7CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gNTsKICAgICAgICAgICAgICAgIGJpdHMgLT0gNTsKICAgICAgICAgICAgICAgIHN0YXRlLm5jb2RlID0gKGhvbGQgJiAxNSkgKyA0OwogICAgICAgICAgICAgICAgaG9sZCA+Pj49IDQ7CiAgICAgICAgICAgICAgICBiaXRzIC09IDQ7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubmxlbiA+IDI4NiB8fCBzdGF0ZS5uZGlzdCA+IDMwKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gInRvbyBtYW55IGxlbmd0aCBvciBkaXN0YW5jZSBzeW1ib2xzIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5oYXZlID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU5MRU5TOwogICAgICAgICAgICAgIGNhc2UgTEVOTEVOUzoKICAgICAgICAgICAgICAgIHdoaWxlIChzdGF0ZS5oYXZlIDwgc3RhdGUubmNvZGUpIHsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW29yZGVyW3N0YXRlLmhhdmUrK11dID0gaG9sZCAmIDc7CiAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAzOwogICAgICAgICAgICAgICAgICBiaXRzIC09IDM7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB3aGlsZSAoc3RhdGUuaGF2ZSA8IDE5KSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbnNbb3JkZXJbc3RhdGUuaGF2ZSsrXV0gPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubGVuY29kZSA9IHN0YXRlLmxlbmR5bjsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSA3OwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUubGVuYml0cyB9OwogICAgICAgICAgICAgICAgcmV0ID0gaW5mbGF0ZV90YWJsZShDT0RFUywgc3RhdGUubGVucywgMCwgMTksIHN0YXRlLmxlbmNvZGUsIDAsIHN0YXRlLndvcmssIG9wdHMpOwogICAgICAgICAgICAgICAgc3RhdGUubGVuYml0cyA9IG9wdHMuYml0czsKICAgICAgICAgICAgICAgIGlmIChyZXQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBjb2RlIGxlbmd0aHMgc2V0IjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5oYXZlID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBDT0RFTEVOUzsKICAgICAgICAgICAgICBjYXNlIENPREVMRU5TOgogICAgICAgICAgICAgICAgd2hpbGUgKHN0YXRlLmhhdmUgPCBzdGF0ZS5ubGVuICsgc3RhdGUubmRpc3QpIHsKICAgICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgICAgaGVyZSA9IHN0YXRlLmxlbmNvZGVbaG9sZCAmICgxIDw8IHN0YXRlLmxlbmJpdHMpIC0gMV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGhlcmVfdmFsIDwgMTYpIHsKICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbnNbc3RhdGUuaGF2ZSsrXSA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIGlmIChoZXJlX3ZhbCA9PT0gMTYpIHsKICAgICAgICAgICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyAyOwogICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYml0IGxlbmd0aCByZXBlYXQiOwogICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IHN0YXRlLmxlbnNbc3RhdGUuaGF2ZSAtIDFdOwogICAgICAgICAgICAgICAgICAgICAgY29weSA9IDMgKyAoaG9sZCAmIDMpOwogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IDI7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IDI7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChoZXJlX3ZhbCA9PT0gMTcpIHsKICAgICAgICAgICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyAzOwogICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IDA7CiAgICAgICAgICAgICAgICAgICAgICBjb3B5ID0gMyArIChob2xkICYgNyk7CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gMzsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gMzsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgbiA9IGhlcmVfYml0cyArIDc7CiAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgICAgbGVuID0gMDsKICAgICAgICAgICAgICAgICAgICAgIGNvcHkgPSAxMSArIChob2xkICYgMTI3KTsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA3OwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSA3OwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGF2ZSArIGNvcHkgPiBzdGF0ZS5ubGVuICsgc3RhdGUubmRpc3QpIHsKICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYml0IGxlbmd0aCByZXBlYXQiOwogICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB3aGlsZSAoY29weS0tKSB7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW3N0YXRlLmhhdmUrK10gPSBsZW47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubW9kZSA9PT0gQkFEKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmxlbnNbMjU2XSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGNvZGUgLS0gbWlzc2luZyBlbmQtb2YtYmxvY2siOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSA5OwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUubGVuYml0cyB9OwogICAgICAgICAgICAgICAgcmV0ID0gaW5mbGF0ZV90YWJsZShMRU5TLCBzdGF0ZS5sZW5zLCAwLCBzdGF0ZS5ubGVuLCBzdGF0ZS5sZW5jb2RlLCAwLCBzdGF0ZS53b3JrLCBvcHRzKTsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSBvcHRzLmJpdHM7CiAgICAgICAgICAgICAgICBpZiAocmV0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgbGl0ZXJhbC9sZW5ndGhzIHNldCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZGlzdGJpdHMgPSA2OwogICAgICAgICAgICAgICAgc3RhdGUuZGlzdGNvZGUgPSBzdGF0ZS5kaXN0ZHluOwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUuZGlzdGJpdHMgfTsKICAgICAgICAgICAgICAgIHJldCA9IGluZmxhdGVfdGFibGUoRElTVFMsIHN0YXRlLmxlbnMsIHN0YXRlLm5sZW4sIHN0YXRlLm5kaXN0LCBzdGF0ZS5kaXN0Y29kZSwgMCwgc3RhdGUud29yaywgb3B0cyk7CiAgICAgICAgICAgICAgICBzdGF0ZS5kaXN0Yml0cyA9IG9wdHMuYml0czsKICAgICAgICAgICAgICAgIGlmIChyZXQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZXMgc2V0IjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOXzsKICAgICAgICAgICAgICAgIGlmIChmbHVzaCA9PT0gWl9UUkVFUykgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgY2FzZSBMRU5fOgogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTjsKICAgICAgICAgICAgICBjYXNlIExFTjoKICAgICAgICAgICAgICAgIGlmIChoYXZlID49IDYgJiYgbGVmdCA+PSAyNTgpIHsKICAgICAgICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBsZWZ0OwogICAgICAgICAgICAgICAgICBzdHJtLm5leHRfaW4gPSBuZXh0OwogICAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX2luID0gaGF2ZTsKICAgICAgICAgICAgICAgICAgc3RhdGUuaG9sZCA9IGhvbGQ7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzOwogICAgICAgICAgICAgICAgICBpbmZsYXRlX2Zhc3Qoc3RybSwgX291dCk7CiAgICAgICAgICAgICAgICAgIHB1dCA9IHN0cm0ubmV4dF9vdXQ7CiAgICAgICAgICAgICAgICAgIG91dHB1dCA9IHN0cm0ub3V0cHV0OwogICAgICAgICAgICAgICAgICBsZWZ0ID0gc3RybS5hdmFpbF9vdXQ7CiAgICAgICAgICAgICAgICAgIG5leHQgPSBzdHJtLm5leHRfaW47CiAgICAgICAgICAgICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICAgICAgICAgICAgaGF2ZSA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgICAgICAgICAgIGhvbGQgPSBzdGF0ZS5ob2xkOwogICAgICAgICAgICAgICAgICBiaXRzID0gc3RhdGUuYml0czsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IFRZUEUpIHsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gLTE7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gMDsKICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUubGVuY29kZVtob2xkICYgKDEgPDwgc3RhdGUubGVuYml0cykgLSAxXTsKICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgIGhlcmVfb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGVyZV92YWwgPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICAgIGlmIChoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChoZXJlX29wICYmIChoZXJlX29wICYgMjQwKSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBsYXN0X2JpdHMgPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgIGxhc3Rfb3AgPSBoZXJlX29wOwogICAgICAgICAgICAgICAgICBsYXN0X3ZhbCA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUubGVuY29kZVtsYXN0X3ZhbCArICgoaG9sZCAmICgxIDw8IGxhc3RfYml0cyArIGxhc3Rfb3ApIC0gMSkgPj4gbGFzdF9iaXRzKV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChsYXN0X2JpdHMgKyBoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGxhc3RfYml0czsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgc3RhdGUuYmFjayArPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSBoZXJlX3ZhbDsKICAgICAgICAgICAgICAgIGlmIChoZXJlX29wID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMSVQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKGhlcmVfb3AgJiAzMikgewogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gLTE7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChoZXJlX29wICYgNjQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBsaXRlcmFsL2xlbmd0aCBjb2RlIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5leHRyYSA9IGhlcmVfb3AgJiAxNTsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU5FWFQ7CiAgICAgICAgICAgICAgY2FzZSBMRU5FWFQ6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZXh0cmEpIHsKICAgICAgICAgICAgICAgICAgbiA9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCArPSBob2xkICYgKDEgPDwgc3RhdGUuZXh0cmEpIC0gMTsKICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBiaXRzIC09IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrICs9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUud2FzID0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IERJU1Q7CiAgICAgICAgICAgICAgY2FzZSBESVNUOgogICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgIGhlcmUgPSBzdGF0ZS5kaXN0Y29kZVtob2xkICYgKDEgPDwgc3RhdGUuZGlzdGJpdHMpIC0gMV07CiAgICAgICAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICBoZXJlX29wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICBpZiAoaGVyZV9iaXRzIDw9IGJpdHMpIHsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoKGhlcmVfb3AgJiAyNDApID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGxhc3RfYml0cyA9IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgbGFzdF9vcCA9IGhlcmVfb3A7CiAgICAgICAgICAgICAgICAgIGxhc3RfdmFsID0gaGVyZV92YWw7CiAgICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICAgIGhlcmUgPSBzdGF0ZS5kaXN0Y29kZVtsYXN0X3ZhbCArICgoaG9sZCAmICgxIDw8IGxhc3RfYml0cyArIGxhc3Rfb3ApIC0gMSkgPj4gbGFzdF9iaXRzKV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChsYXN0X2JpdHMgKyBoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGxhc3RfYml0czsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgc3RhdGUuYmFjayArPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBpZiAoaGVyZV9vcCAmIDY0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgY29kZSI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUub2Zmc2V0ID0gaGVyZV92YWw7CiAgICAgICAgICAgICAgICBzdGF0ZS5leHRyYSA9IGhlcmVfb3AgJiAxNTsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBESVNURVhUOwogICAgICAgICAgICAgIGNhc2UgRElTVEVYVDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5leHRyYSkgewogICAgICAgICAgICAgICAgICBuID0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgbikgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgc3RhdGUub2Zmc2V0ICs9IGhvbGQgJiAoMSA8PCBzdGF0ZS5leHRyYSkgLSAxOwogICAgICAgICAgICAgICAgICBob2xkID4+Pj0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIGJpdHMgLT0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUub2Zmc2V0ID4gc3RhdGUuZG1heCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IE1BVENIOwogICAgICAgICAgICAgIGNhc2UgTUFUQ0g6CiAgICAgICAgICAgICAgICBpZiAobGVmdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBjb3B5ID0gX291dCAtIGxlZnQ7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUub2Zmc2V0ID4gY29weSkgewogICAgICAgICAgICAgICAgICBjb3B5ID0gc3RhdGUub2Zmc2V0IC0gY29weTsKICAgICAgICAgICAgICAgICAgaWYgKGNvcHkgPiBzdGF0ZS53aGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5zYW5lKSB7CiAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gc3RhdGUud25leHQpIHsKICAgICAgICAgICAgICAgICAgICBjb3B5IC09IHN0YXRlLnduZXh0OwogICAgICAgICAgICAgICAgICAgIGZyb20gPSBzdGF0ZS53c2l6ZSAtIGNvcHk7CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgZnJvbSA9IHN0YXRlLnduZXh0IC0gY29weTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoY29weSA+IHN0YXRlLmxlbmd0aCkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBzdGF0ZS53aW5kb3c7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgZnJvbSA9IHB1dCAtIHN0YXRlLm9mZnNldDsKICAgICAgICAgICAgICAgICAgY29weSA9IHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gbGVmdCkgewogICAgICAgICAgICAgICAgICBjb3B5ID0gbGVmdDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGxlZnQgLT0gY29weTsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCAtPSBjb3B5OwogICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICBvdXRwdXRbcHV0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tY29weSk7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIExJVDoKICAgICAgICAgICAgICAgIGlmIChsZWZ0ID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIG91dHB1dFtwdXQrK10gPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICBsZWZ0LS07CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBDSEVDSzoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCB8PSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIF9vdXQgLT0gbGVmdDsKICAgICAgICAgICAgICAgICAgc3RybS50b3RhbF9vdXQgKz0gX291dDsKICAgICAgICAgICAgICAgICAgc3RhdGUudG90YWwgKz0gX291dDsKICAgICAgICAgICAgICAgICAgaWYgKF9vdXQpIHsKICAgICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSBzdGF0ZS5mbGFncyA/IGNyYzMyKHN0YXRlLmNoZWNrLCBvdXRwdXQsIF9vdXQsIHB1dCAtIF9vdXQpIDogYWRsZXIzMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBwdXQgLSBfb3V0KTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBfb3V0ID0gbGVmdDsKICAgICAgICAgICAgICAgICAgaWYgKChzdGF0ZS5mbGFncyA/IGhvbGQgOiB6c3dhcDMyKGhvbGQpKSAhPT0gc3RhdGUuY2hlY2spIHsKICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbmNvcnJlY3QgZGF0YSBjaGVjayI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOR1RIOwogICAgICAgICAgICAgIGNhc2UgTEVOR1RIOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLndyYXAgJiYgc3RhdGUuZmxhZ3MpIHsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGhvbGQgIT09IChzdGF0ZS50b3RhbCAmIDQyOTQ5NjcyOTUpKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW5jb3JyZWN0IGxlbmd0aCBjaGVjayI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gRE9ORTsKICAgICAgICAgICAgICBjYXNlIERPTkU6CiAgICAgICAgICAgICAgICByZXQgPSBaX1NUUkVBTV9FTkQ7CiAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgY2FzZSBCQUQ6CiAgICAgICAgICAgICAgICByZXQgPSBaX0RBVEFfRVJST1I7CiAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgY2FzZSBNRU06CiAgICAgICAgICAgICAgICByZXR1cm4gWl9NRU1fRVJST1I7CiAgICAgICAgICAgICAgY2FzZSBTWU5DOgogICAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICBzdHJtLm5leHRfb3V0ID0gcHV0OwogICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gbGVmdDsKICAgICAgICBzdHJtLm5leHRfaW4gPSBuZXh0OwogICAgICAgIHN0cm0uYXZhaWxfaW4gPSBoYXZlOwogICAgICAgIHN0YXRlLmhvbGQgPSBob2xkOwogICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzOwogICAgICAgIGlmIChzdGF0ZS53c2l6ZSB8fCBfb3V0ICE9PSBzdHJtLmF2YWlsX291dCAmJiBzdGF0ZS5tb2RlIDwgQkFEICYmIChzdGF0ZS5tb2RlIDwgQ0hFQ0sgfHwgZmx1c2ggIT09IFpfRklOSVNIKSkgewogICAgICAgICAgaWYgKHVwZGF0ZXdpbmRvdyhzdHJtLCBzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCwgX291dCAtIHN0cm0uYXZhaWxfb3V0KSkgewogICAgICAgICAgICBzdGF0ZS5tb2RlID0gTUVNOwogICAgICAgICAgICByZXR1cm4gWl9NRU1fRVJST1I7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIF9pbiAtPSBzdHJtLmF2YWlsX2luOwogICAgICAgIF9vdXQgLT0gc3RybS5hdmFpbF9vdXQ7CiAgICAgICAgc3RybS50b3RhbF9pbiArPSBfaW47CiAgICAgICAgc3RybS50b3RhbF9vdXQgKz0gX291dDsKICAgICAgICBzdGF0ZS50b3RhbCArPSBfb3V0OwogICAgICAgIGlmIChzdGF0ZS53cmFwICYmIF9vdXQpIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IHN0YXRlLmZsYWdzID8gY3JjMzIoc3RhdGUuY2hlY2ssIG91dHB1dCwgX291dCwgc3RybS5uZXh0X291dCAtIF9vdXQpIDogYWRsZXIzMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBzdHJtLm5leHRfb3V0IC0gX291dCk7CiAgICAgICAgfQogICAgICAgIHN0cm0uZGF0YV90eXBlID0gc3RhdGUuYml0cyArIChzdGF0ZS5sYXN0ID8gNjQgOiAwKSArIChzdGF0ZS5tb2RlID09PSBUWVBFID8gMTI4IDogMCkgKyAoc3RhdGUubW9kZSA9PT0gTEVOXyB8fCBzdGF0ZS5tb2RlID09PSBDT1BZXyA/IDI1NiA6IDApOwogICAgICAgIGlmICgoX2luID09PSAwICYmIF9vdXQgPT09IDAgfHwgZmx1c2ggPT09IFpfRklOSVNIKSAmJiByZXQgPT09IFpfT0spIHsKICAgICAgICAgIHJldCA9IFpfQlVGX0VSUk9SOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmV0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVFbmQoc3RybSkgewogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICB2YXIgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS53aW5kb3cpIHsKICAgICAgICAgIHN0YXRlLndpbmRvdyA9IG51bGw7CiAgICAgICAgfQogICAgICAgIHN0cm0uc3RhdGUgPSBudWxsOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVHZXRIZWFkZXIoc3RybSwgaGVhZCkgewogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmICgoc3RhdGUud3JhcCAmIDIpID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlLmhlYWQgPSBoZWFkOwogICAgICAgIGhlYWQuZG9uZSA9IGZhbHNlOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVTZXREaWN0aW9uYXJ5KHN0cm0sIGRpY3Rpb25hcnkpIHsKICAgICAgICB2YXIgZGljdExlbmd0aCA9IGRpY3Rpb25hcnkubGVuZ3RoOwogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICB2YXIgZGljdGlkOwogICAgICAgIHZhciByZXQ7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAoc3RhdGUud3JhcCAhPT0gMCAmJiBzdGF0ZS5tb2RlICE9PSBESUNUKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmIChzdGF0ZS5tb2RlID09PSBESUNUKSB7CiAgICAgICAgICBkaWN0aWQgPSAxOwogICAgICAgICAgZGljdGlkID0gYWRsZXIzMihkaWN0aWQs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y8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2NvbnN0YW50cy5qcwogIHZhciByZXF1aXJlX2NvbnN0YW50cyA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9jb25zdGFudHMuanMiKGV4cG9ydHMyLCBtb2R1bGUyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSB7CiAgICAgICAgWl9OT19GTFVTSDogMCwKICAgICAgICBaX1BBUlRJQUxfRkxVU0g6IDEsCiAgICAgICAgWl9TWU5DX0ZMVVNIOiAyLAogICAgICAgIFpfRlVMTF9GTFVTSDogMywKICAgICAgICBaX0ZJTklTSDogNCwKICAgICAgICBaX0JMT0NLOiA1LAogICAgICAgIFpfVFJFRVM6IDYsCiAgICAgICAgWl9PSzogMCwKICAgICAgICBaX1NUUkVBTV9FTkQ6IDEsCiAgICAgICAgWl9ORUVEX0RJQ1Q6IDIsCiAgICAgICAgWl9FUlJOTzogLTEsCiAgICAgICAgWl9TVFJFQU1fRVJST1I6IC0yLAogICAgICAgIFpfREFUQV9FUlJPUjogLTMsCiAgICAgICAgWl9CVUZfRVJST1I6IC01LAogICAgICAgIFpfTk9fQ09NUFJFU1NJT046IDAsCiAgICAgICAgWl9CRVNUX1NQRUVEOiAxLAogICAgICAgIFpfQkVTVF9DT01QUkVTU0lPTjogOSwKICAgICAgICBaX0RFRkFVTFRfQ09NUFJFU1NJT046IC0xLAogICAgICAgIFpfRklMVEVSRUQ6IDEsCiAgICAgICAgWl9IVUZGTUFOX09OTFk6IDIsCiAgICAgICAgWl9STEU6IDMsCiAgICAgICAgWl9GSVhFRDogNCwKICAgICAgICBaX0RFRkFVTFRfU1RSQVRFR1k6I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AgICAgICAgICAgIG9wdC53aW5kb3dCaXRzID0gLTE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAob3B0LndpbmRvd0JpdHMgPj0gMCAmJiBvcHQud2luZG93Qml0cyA8IDE2ICYmICEob3B0aW9ucyAmJiBvcHRpb25zLndpbmRvd0JpdHMpKSB7CiAgICAgICAgICBvcHQud2luZG93Qml0cyArPSAzMjsKICAgICAgICB9CiAgICAgICAgaWYgKG9wdC53aW5kb3dCaXRzID4gMTUgJiYgb3B0LndpbmRvd0JpdHMgPCA0OCkgewogICAgICAgICAgaWYgKChvcHQud2luZG93Qml0cyAmIDE1KSA9PT0gMCkgewogICAgICAgICAgICBvcHQud2luZG93Qml0cyB8PSAxNTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdGhpcy5lcnIgPSAwOwogICAgICAgIHRoaXMubXNnID0gIiI7CiAgICAgICAgdGhpcy5lbmRlZCA9IGZhbHNlOwogICAgICAgIHRoaXMuY2h1bmtzID0gW107CiAgICAgICAgdGhpcy5zdHJtID0gbmV3IFpTdHJlYW0oKTsKICAgICAgICB0aGlzLnN0cm0uYXZhaWxfb3V0ID0gMDsKICAgICAgICB2YXIgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGVJbml0Mih0aGlzLnN0cm0sIG9wdC53aW5kb3dCaXRzKTsKICAgICAgICBpZiAoc3RhdHVzICE9PSBjLlpfT0spIHsKICAgICAgICAgIHRocm93IG5ldyBFcnJvcihtc2dbc3RhdHVzXSk7CiAgICAgICAgfQogICAgICAgIHRoaXMuaGVhZGVyID0gbmV3IEdaaGVhZGVyKCk7CiAgICAgICAgemxpYl9pbmZsYXRlLmluZmxhdGVHZXRIZWFkZXIodGhpcy5zdHJtLCB0aGlzLmhlYWRlcik7CiAgICAgICAgaWYgKG9wdC5kaWN0aW9uYXJ5KSB7CiAgICAgICAgICBpZiAodHlwZW9mIG9wdC5kaWN0aW9uYXJ5ID09PSAic3RyaW5nIikgewogICAgICAgICAgICBvcHQuZGljdGlvbmFyeSA9IHN0cmluZ3Muc3RyaW5nMmJ1ZihvcHQuZGljdGlvbmFyeSk7CiAgICAgICAgICB9IGVsc2UgaWYgKHRvU3RyaW5nLmNhbGwob3B0LmRpY3Rpb25hcnkpID09PSAiW29iamVjdCBBcnJheUJ1ZmZlcl0iKSB7CiAgICAgICAgICAgIG9wdC5kaWN0aW9uYXJ5ID0gbmV3IFVpbnQ4QXJyYXkob3B0LmRpY3Rpb25hcnkpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKG9wdC5yYXcpIHsKICAgICAgICAgICAgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGVTZXREaWN0aW9uYXJ5KHRoaXMuc3RybSwgb3B0LmRpY3Rpb25hcnkpOwogICAgICAgICAgICBpZiAoc3RhdHVzICE9PSBjLlpfT0spIHsKICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IobXNnW3N0YXR1c10pOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIEluZmxhdGUyLnByb3RvdHlwZS5wdXNoID0gZnVuY3Rpb24oZGF0YSwgbW9kZSkgewogICAgICAgIHZhciBzdHJtID0gdGhpcy5zdHJtOwogICAgICAgIHZhciBjaHVua1NpemUgPSB0aGlzLm9wdGlvbnMuY2h1bmtTaXplOwogICAgICAgIHZhciBkaWN0aW9uYXJ5ID0gdGhpcy5vcHRpb25zLmRpY3Rpb25hcnk7CiAgICAgICAgdmFyIHN0YXR1cywgX21vZGU7CiAgICAgICAgdmFyIG5leHRfb3V0X3V0ZjgsIHRhaWwsIHV0ZjhzdHI7CiAgICAgICAgdmFyIGFsbG93QnVmRXJyb3IgPSBmYWxzZTsKICAgICAgICBpZiAodGhpcy5lbmRlZCkgewogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgICBfbW9kZSA9IG1vZGUgPT09IH5+bW9kZSA/IG1vZGUgOiBtb2RlID09PSB0cnVlID8gYy5aX0ZJTklTSCA6IGMuWl9OT19GTFVTSDsKICAgICAgICBpZiAodHlwZW9mIGRhdGEgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICBzdHJtLmlucHV0ID0gc3RyaW5ncy5iaW5zdHJpbmcyYnVmKGRhdGEpOwogICAgICAgIH0gZWxzZSBpZiAodG9TdHJpbmcuY2FsbChkYXRhKSA9PT0gIltvYmplY3QgQXJyYXlCdWZmZXJdIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IG5ldyBVaW50OEFycmF5KGRhdGEpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzdHJtLmlucHV0ID0gZGF0YTsKICAgICAgICB9CiAgICAgICAgc3RybS5uZXh0X2luID0gMDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gc3RybS5pbnB1dC5sZW5ndGg7CiAgICAgICAgZG8gewogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHN0cm0ub3V0cHV0ID0gbmV3IHV0aWxzLkJ1ZjgoY2h1bmtTaXplKTsKICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IDA7CiAgICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gY2h1bmtTaXplOwogICAgICAgICAgfQogICAgICAgICAgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGUoc3RybSwgYy5aX05PX0ZMVVNIKTsKICAgICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9ORUVEX0RJQ1QgJiYgZGljdGlvbmFyeSkgewogICAgICAgICAgICBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZVNldERpY3Rpb25hcnkodGhpcy5zdHJtLCBkaWN0aW9uYXJ5KTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9CVUZfRVJST1IgJiYgYWxsb3dCdWZFcnJvciA9PT0gdHJ1ZSkgewogICAgICAgICAgICBzdGF0dXMgPSBjLlpfT0s7CiAgICAgICAgICAgIGFsbG93QnVmRXJyb3IgPSBmYWxzZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdGF0dXMgIT09IGMuWl9TVFJFQU1fRU5EICYmIHN0YXR1cyAhPT0gYy5aX09LKSB7CiAgICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgICAgdGhpcy5lbmRlZCA9IHRydWU7CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdHJtLm5leHRfb3V0KSB7CiAgICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCB8fCBzdGF0dXMgPT09IGMuWl9TVFJFQU1fRU5EIHx8IHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgKF9tb2RlID09PSBjLlpfRklOSVNIIHx8IF9tb2RlID09PSBjLlpfU1lOQ19GTFVTSCkpIHsKICAgICAgICAgICAgICBpZiAodGhpcy5vcHRpb25zLnRvID09PSAic3RyaW5nIikgewogICAgICAgICAgICAgICAgbmV4dF9vdXRfdXRmOCA9IHN0cmluZ3MudXRmOGJvcmRlcihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCk7CiAgICAgICAgICAgICAgICB0YWlsID0gc3RybS5uZXh0X291dCAtIG5leHRfb3V0X3V0Zjg7CiAgICAgICAgICAgICAgICB1dGY4c3RyID0gc3RyaW5ncy5idWYyc3RyaW5nKHN0cm0ub3V0cHV0LCBuZXh0X291dF91dGY4KTsKICAgICAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSB0YWlsOwogICAgICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBjaHVua1NpemUgLSB0YWlsOwogICAgICAgICAgICAgICAgaWYgKHRhaWwpIHsKICAgICAgICAgICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RybS5vdXRwdXQsIHN0cm0ub3V0cHV0LCBuZXh0X291dF91dGY4LCB0YWlsLCAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0ZjhzdHIpOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0aGlzLm9uRGF0YSh1dGlscy5zaHJpbmtCdWYoc3RybS5vdXRwdXQsIHN0cm0ubmV4dF9vdXQpKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdHJtLmF2YWlsX2luID09PSAwICYmIHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIGFsbG93QnVmRXJyb3IgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKChzdHJtLmF2YWlsX2luID4gMCB8fCBzdHJtLmF2YWlsX291dCA9PT0gMCkgJiYgc3RhdHVzICE9PSBjLlpfU1RSRUFNX0VORCk7CiAgICAgICAgaWYgKHN0YXR1cyA9PT0gYy5aX1NUUkVBTV9FTkQpIHsKICAgICAgICAgIF9tb2RlID0gYy5aX0ZJTklTSDsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBjLlpfRklOSVNIKSB7CiAgICAgICAgICBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZUVuZCh0aGlzLnN0cm0pOwogICAgICAgICAgdGhpcy5vbkVuZChzdGF0dXMpOwogICAgICAgICAgdGhpcy5lbmRlZCA9IHRydWU7CiAgICAgICAgICByZXR1cm4gc3RhdHVzID09PSBjLlpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChfbW9kZSA9PT0gYy5aX1NZTkNfRkxVU0gpIHsKICAgICAgICAgIHRoaXMub25FbmQoYy5aX09LKTsKICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gMDsKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgfTsKICAgICAgSW5mbGF0ZTIucHJvdG90eXBlLm9uRGF0YSA9IGZ1bmN0aW9uKGNodW5rKSB7CiAgICAgICAgdGhpcy5jaHVua3MucHVzaChjaHVuayk7CiAgICAgIH07CiAgICAgIEluZmxhdGUyLnByb3RvdHlwZS5vbkVuZCA9IGZ1bmN0aW9uKHN0YXR1cykgewogICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9PSykgewogICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgdGhpcy5yZXN1bHQgPSB0aGlzLmNodW5rcy5qb2luKCIiKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdXRpbHMuZmxhdHRlbkNodW5rcyh0aGlzLmNodW5rcyk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHRoaXMuY2h1bmtzID0gW107CiAgICAgICAgdGhpcy5lcnIgPSBzdGF0dXM7CiAgICAgICAgdGhpcy5tc2cgPSB0aGlzLnN0cm0ubXNnOwogICAgICB9OwogICAgICBmdW5jdGlvbiBpbmZsYXRlKGlucHV0LCBvcHRpb25zKSB7CiAgICAgICAgdmFyIGluZmxhdG9yID0gbmV3IEluZmxhdGUyKG9wdGlvbnMpOwogICAgICAgIGluZmxhdG9yLnB1c2goaW5wdXQsIHRydWUpOwogICAgICAgIGlmIChpbmZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IGluZmxhdG9yLm1zZyB8fCBtc2dbaW5mbGF0b3IuZXJyXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGluZmxhdG9yLnJlc3VsdDsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlUmF3KGlucHV0LCBvcHRpb25zKSB7CiAgICAgICAgb3B0aW9ucyA9IG9wdGlvbnMgfHwge307CiAgICAgICAgb3B0aW9ucy5yYXcgPSB0cnVlOwogICAgICAgIHJldHVybiBpbmZsYXRlKGlucHV0LCBvcHRpb25zKTsKICAgICAgfQogICAgICBleHBvcnRzMi5Jb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gewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgIG1vZHVsZTIuZXhwb3J0cyA9IExvbmc0OwogICAgICB2YXIgd2FzbSA9IG51bGw7CiAgICAgIHRyeSB7CiAgICAgICAgd2FzbSA9IG5ldyBXZWJBc3NlbWJseS5JbnN0YW5jZShuZXcgV2ViQXNzZW1ibHkuTW9kdWxlKG5ldyBVaW50OEFycmF5KFsKICAgICAgICAgIDAsCiAgICAgICAgICA5NywKICAgICAgICAgIDExNSwKICAgICAgICAgIDEwOSwKICAgICAgICAgIDEsCiAgICAgICAgICAwLAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAxLAogICAgICAgICAgMTMsCiAgICAgICAgICAyLAogICAgICAgICAgOTYsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNywKICAgICAgICAgIDk2LAogICAgICAgICAgNCwKICAgICAgICAgIDEyNywKICAgICAgICAgIDEyNywKICAgICAgICAgIDEyNywKICAgICAgICAgIDEyNywKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAzLAogICAgICAgICAgNywKICAgICAgICAgIDYsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICA2LAogICAgICAgICAgNiwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxLAogICAgICAgICAgNjUsCiAgICAgICAgICAwLAogICAgICAgICAgMTEsCiAgICAgICAgICA3LAogICAgICAgICAgNTAsCiAgICAgICAgICA2LAogICAgICAgICAgMywKICAgICAgICAgIDEwOSwKICAgICAgICAgIDExNywKICAgICAgICAgIDEwOCwKICAgICAgICAgIDAsCiAgICAgICAgICAxLAogICAgICAgICAgNSwKICAgICAgICAgIDEwMCwKICAgICAgICAgIDEwNSwKICAgICAgICAgIDExOCwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE1LAogICAgICAgICAgMCwKICAgICAgICAgIDIsCiAgICAgICAgICA1LAogICAgICAgICAgMTAwLAogICAgICAgICAgMTA1LAogICAgICAgICAgMTE4LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMTcsCiAgICAgICAgICAwLAogICAgICAgICAgMywKICAgICAgICAgIDUsCiAgICAgICAgICAxMTQsCiAgICAgICAgICAxMDEsCiAgICAgICAgICAxMDksCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNSwKICAgICAgICAgIDAsCiAgICAgICAgICA0LAogICAgICAgICAgNSwKICAgICAgICAgIDExNCwKICAgICAgICAgIDEwMSwKICAgICAgICAgIDEwOSwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE3LAogICAgICAgICAgMCwKICAgICAgICAgIDUsCiAgICAgICAgICA4LAogICAgICAgICAgMTAzLAogICAgICAgICAgMTAxLAogICAgICAgICAgMTE2LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMDQsCiAgICAgICAgICAxMDUsCiAgICAgICAgICAxMDMsCiAgICAgICAgICAxMDQsCiAgICAgICAgICAwLAogICAgICAgICAgMCwKICAgICAgICAgIDEwLAogICAgICAgICAgMTkxLAogICAgICAgICAgMSwKICAgICAgICAgIDYsCiAgICAgICAgICA0LAogICAgICAgICAgMCwKICAgICAgICAgIDM1LAogICAgICAgICAgMCwKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI2LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI3LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI4LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI5LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTMwLAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExCiAgICAgICAgXSkpLCB7fSkuZXhwb3J0czsKICAgICAgfSBjYXRjaCAoZSkgewogICAgICB9CiAgICAgIGZ1bmN0aW9uIExvbmc0KGxvdywgaGlnaCwgdW5zaWduZWQpIHsKICAgICAgICB0aGlzLmxvdyA9IGxvdyB8IDA7CiAgICAgICAgdGhpcy5oaWdoID0gaGlnaCB8IDA7CiAgICAgICAgdGhpcy51bnNpZ25lZCA9ICEhdW5zaWduZWQ7CiAgICAgIH0KICAgICAgTG9uZzQucHJvdG90eXBlLl9faXNMb25nX187CiAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShMb25nNC5wcm90b3R5cGUsICJfX2lzTG9uZ19fIiwgeyB2YWx1ZTogdHJ1ZSB9KTsKICAgICAgZnVuY3Rpb24gaXNMb25nKG9iaikgewogICAgICAgIHJldHVybiAob2JqICYmIG9ialsiX19pc0xvbmdfXyJdKSA9PT0gdHJ1ZTsKICAgICAgfQogICAgICBMb25nNC5pc0xvbmcgPSBpc0xvbmc7CiAgICAgIHZhciBJTlRfQ0FDSEUgPSB7fTsKICAgICAgdmFyIFVJTlRfQ0FDSEUgPSB7fTsKICAgICAgZnVuY3Rpb24gZnJvbUludCh2YWx1ZSwgdW5zaWduZWQpIHsKICAgICAgICB2YXIgb2JqLCBjYWNoZWRPYmosIGNhY2hlOwogICAgICAgIGlmICh1bnNpZ25lZCkgewogICAgICAgICAgdmFsdWUgPj4+PSAwOwogICAgICAgICAgaWYgKGNhY2hlID0gMCA8PSB2YWx1ZSAmJiB2YWx1ZSA8IDI1NikgewogICAgICAgICAgICBjYWNoZWRPYmogPSBVSU5UX0NBQ0hFW3ZhbHVlXTsKICAgICAgICAgICAgaWYgKGNhY2hlZE9iaikKICAgICAgICAgICAgICByZXR1cm4gY2FjaGVkT2JqOwogICAgICAgICAgfQogICAgICAgICAgb2JqID0gZnJvbUJpdHModmFsdWUsICh2YWx1ZSB8IDApIDwgMCA/IC0xIDogMCwgdHJ1ZSk7CiAgICAgICAgICBpZiAoY2FjaGUpCiAgICAgICAgICAgIFVJTlRfQ0FDSEVbdmFsdWVdID0gb2JqOwogICAgICAgICAgcmV0dXJuIG9iajsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdmFsdWUgfD0gMDsKICAgICAgICAgIGlmIChjYWNoZSA9IC0xMjggPD0gdmFsdWUgJiYgdmFsdWUgPCAxMjgpIHsKICAgICAgICAgICAgY2FjaGVkT2JqID0gSU5UX0NBQ0hFW3ZhbHVlXTsKICAgICAgICAgICAgaWYgKGNhY2hlZE9iaikKICAgICAgICAgICAgICByZXR1cm4gY2FjaGVkT2JqOwogICAgICAgICAgfQogICAgICAgICAgb2JqID0gZnJvbUJpdHModmFsdWUsIHZhbHVlIDwgMCA/IC0xIDogMCwgZmFsc2UpOwogICAgICAgICAgaWYgKGNhY2hlKQogICAgICAgICAgICBJTlRfQ0FDSEVbdmFsdWVdID0gb2JqOwogICAgICAgICAgcmV0dXJuIG9iajsKICAgICAgICB9CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbUludCA9IGZyb21JbnQ7CiAgICAgIGZ1bmN0aW9uIGZyb21OdW1iZXIodmFsdWUsIHVuc2lnbmVkKSB7CiAgICAgICAgaWYgKGlzTmFOKHZhbHVlKSkKICAgICAgICAgIHJldHVybiB1bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICBpZiAodW5zaWduZWQpIHsKICAgICAgICAgIGlmICh2YWx1ZSA8IDApCiAgICAgICAgICAgIHJldHVybiBVWkVSTzsKICAgICAgICAgIGlmICh2YWx1ZSA+PSBUV09fUFdSXzY0X0RCTCkKICAgICAgICAgICAgcmV0dXJuIE1BWF9VTlNJR05FRF9WQUxVRTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKHZhbHVlIDw9IC1UV09fUFdSXzYzX0RCTCkKICAgICAgICAgICAgcmV0dXJuIE1JTl9WQUxVRTsKICAgICAgICAgIGlmICh2YWx1ZSArIDEgPj0gVFdPX1BXUl82M19EQkwpCiAgICAgICAgICAgIHJldHVybiBNQVhfVkFMVUU7CiAgICAgICAgfQogICAgICAgIGlmICh2YWx1ZSA8IDApCiAgICAgICAgICByZXR1cm4gZnJvbU51bWJlcigtdmFsdWUsIHVuc2lnbmVkKS5uZWcoKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModmFsdWUgJSBUV09fUFdSXzMyX0RCTCB8IDAsIHZhbHVlIC8gVFdPX1BXUl8zMl9EQkwgfCAwLCB1bnNpZ25lZCk7CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbU51bWJlciA9IGZyb21OdW1iZXI7CiAgICAgIGZ1bmN0aW9uIGZyb21CaXRzKGxvd0JpdHMsIGhpZ2hCaXRzLCB1bnNpZ25lZCkgewogICAgICAgIHJldHVybiBuZXcgTG9uZzQobG93Qml0cywgaGlnaEJpdHMsIHVuc2lnbmVkKTsKICAgICAgfQogICAgICBMb25nNC5mcm9tQml0cyA9IGZyb21CaXRzOwogICAgICB2YXIgcG93X2RibCA9IE1hdGgucG93OwogICAgICBmdW5jdGlvbiBmcm9tU3RyaW5nKHN0ciwgdW5zaWduZWQsIHJhZGl4KSB7CiAgICAgICAgaWYgKHN0ci5sZW5ndGggPT09IDApCiAgICAgICAgICB0aHJvdyBFcnJvcigiZW1wdHkgc3RyaW5nIik7CiAgICAgICAgaWYgKHN0ciA9PT0gIk5hTiIgfHwgc3RyID09PSAiSW5maW5pdHkiIHx8IHN0ciA9PT0gIitJbmZpbml0eSIgfHwgc3RyID09PSAiLUluZmluaXR5IikKICAgICAgICAgIHJldHVybiBaRVJPOwogICAgICAgIGlmICh0eXBlb2YgdW5zaWduZWQgPT09ICJudW1iZXIiKSB7CiAgICAgICAgICByYWRpeCA9IHVuc2lnbmVkLCB1bnNpZ25lZCA9IGZhbHNlOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB1bnNpZ25lZCA9ICEhdW5zaWduZWQ7CiAgICAgICAgfQogICAgICAgIHJhZGl4ID0gcmFkaXggfHwgMTA7CiAgICAgICAgaWYgKHJhZGl4IDwgMiB8fCAzNiA8IHJhZGl4KQogICAgICAgICAgdGhyb3cgUmFuZ2VFcnJvcigicmFkaXgiKTsKICAgICAgICB2YXIgcDsKICAgICAgICBpZiAoKHAgPSBzdHIuaW5kZXhPZigiLSIpKSA+IDApCiAgICAgICAgICB0aHJvdyBFcnJvcigiaW50ZXJpb3IgaHlwaGVuIik7CiAgICAgICAgZWxzZSBpZiAocCA9PT0gMCkgewogICAgICAgICAgcmV0dXJuIGZyb21TdHJpbmcoc3RyLnN1YnN0cmluZygxKSwgdW5zaWduZWQsIHJhZGl4KS5uZWcoKTsKICAgICAgICB9CiAgICAgICAgdmFyIHJhZGl4VG9Qb3dlciA9IGZyb21OdW1iZXIocG93X2RibChyYWRpeCwgOCkpOwogICAgICAgIHZhciByZXN1bHQgPSBaRVJPOwogICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgc3RyLmxlbmd0aDsgaSArPSA4KSB7CiAgICAgICAgICB2YXIgc2l6ZSA9IE1hdGgubWluKDgsIHN0ci5sZW5ndGggLSBpKSwgdmFsdWUgPSBwYXJzZUludChzdHIuc3Vic3RyaW5nKGksIGkgKyBzaXplKSwgcmFkaXgpOwogICAgICAgICAgaWYgKHNpemUgPCA4KSB7CiAgICAgICAgICAgIHZhciBwb3dlciA9IGZyb21OdW1iZXIocG93X2RibChyYWRpeCwgc2l6ZSkpOwogICAgICAgICAgICByZXN1bHQgPSByZXN1bHQubXVsKHBvd2VyKS5hZGQoZnJvbU51bWJlcih2YWx1ZSkpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0Lm11bChyYWRpeFRvUG93ZXIpOwogICAgICAgICAgICByZXN1bHQgPSByZXN1bHQuYWRkKGZyb21OdW1iZXIodmFsdWUpKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmVzdWx0LnVuc2lnbmVkID0gdW5zaWduZWQ7CiAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgfQogICAgICBMb25nNC5mcm9tU3RyaW5nID0gZnJvbVN0cmluZzsKICAgICAgZnVuY3Rpb24gZnJvbVZhbHVlKHZhbCwgdW5zaWduZWQpIHsKICAgICAgICBpZiAodHlwZW9mIHZhbCA9PT0gIm51bWJlciIpCiAgICAgICAgICByZXR1cm4gZnJvbU51bWJlcih2YWwsIHVuc2lnbmVkKTsKICAgICAgICBpZiAodHlwZW9mIHZhbCA9PT0gInN0cmluZyIpCiAgICAgICAgICByZXR1cm4gZnJvbVN0cmluZyh2YWwsIHVuc2lnbmVkKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModmFsLmxvdywgdmFsLmhpZ2gsIHR5cGVvZiB1bnNpZ25lZCA9PT0gImJvb2xlYW4iID8gdW5zaWduZWQgOiB2YWwudW5zaWduZWQpOwogICAgICB9CiAgICAgIExvbmc0LmZyb21WYWx1ZSA9IGZyb21WYWx1ZTsKICAgICAgdmFyIFRXT19QV1JfMTZfREJMID0gMSA8PCAxNjsKICAgICAgdmFyIFRXT19QV1Jf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5fVkFMVUUgPSBNSU5fVkFMVUU7CiAgICAgIHZhciBMb25nUHJvdG90eXBlID0gTG9uZzQucHJvdG90eXBlOwogICAgICBMb25nUHJvdG90eXBlLnRvSW50ID0gZnVuY3Rpb24gdG9JbnQoKSB7CiAgICAgICAgcmV0dXJuIHRoaXMudW5zaWduZWQgPyB0aGlzLmxvdyA+Pj4gMCA6IHRoaXMubG93OwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnRvTnVtYmVyID0gZnVuY3Rpb24gdG9OdW1iZXIyKCkgewogICAgICAgIGlmICh0aGlzLnVuc2lnbmVkKQogICAgICAgICAgcmV0dXJuICh0aGlzLmhpZ2ggPj4+IDApICogVFdPX1BXUl8zMl9EQkwgKyAodGhpcy5sb3cgPj4+IDApOwogICAgICAgIHJldHVybiB0aGlzLmhpZ2ggKiBUV09fUFdSXzMyX0RCTCArICh0aGlzLmxvdyA+Pj4gMCk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9TdHJpbmcgPSBmdW5jdGlvbiB0b1N0cmluZyhyYWRpeCkgewogICAgICAgIHJhZGl4ID0gcmFkaXggfHwgMTA7CiAgICAgICAgaWYgKHJhZGl4IDwgMiB8fCAzNiA8IHJhZGl4KQogICAgICAgICAgdGhyb3cgUmFuZ2VFcnJvcigicmFkaXgiKTsKICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiAiMCI7CiAgICAgICAgaWYgKHRoaXMuaXNOZWdhdGl2ZSgpKSB7CiAgICAgICAgICBpZiAodGhpcy5lcShNSU5fVkFMVUUpKSB7CiAgICAgICAgICAgIHZhciByYWRpeExvbmcgPSBmcm9tTnVtYmVyKHJhZGl4KSwgZGl2ID0gdGhpcy5kaXYocmFkaXhMb25nKSwgcmVtMSA9IGRpdi5tdWwocmFkaXhMb25nKS5zdWIodGhpcyk7CiAgICAgICAgICAgIHJldHVybiBkaXYudG9TdHJpbmcocmFkaXgpICsgcmVtMS50b0ludCgpLnRvU3RyaW5nKHJhZGl4KTsKICAgICAgICAgIH0gZWxzZQogICAgICAgICAgICByZXR1cm4gIi0iICsgdGhpcy5uZWcoKS50b1N0cmluZyhyYWRpeCk7CiAgICAgICAgfQogICAgICAgIHZhciByYWRpeFRvUG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIDYpLCB0aGlzLnVuc2lnbmVkKSwgcmVtID0gdGhpczsKICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHZhciByZW1EaXYgPSByZW0uZGl2KHJhZGl4VG9Qb3dlciksIGludHZhbCA9IHJlbS5zdWIocmVtRGl2Lm11bChyYWRpeFRvUG93ZXIpKS50b0ludCgpID4+PiAwLCBkaWdpdHMgPSBpbnR2YWwudG9TdHJpbmcocmFkaXgpOwogICAgICAgICAgcmVtID0gcmVtRGl2OwogICAgICAgICAgaWYgKHJlbS5pc1plcm8oKSkKICAgICAgICAgICAgcmV0dXJuIGRpZ2l0cyArIHJlc3VsdDsKICAgICAgICAgIGVsc2UgewogICAgICAgICAgICB3aGlsZSAoZGlnaXRzLmxlbmd0aCA8IDYpCiAgICAgICAgICAgICAgZGlnaXRzID0gIjAiICsgZGlnaXRzOwogICAgICAgICAgICByZXN1bHQgPSAiIiArIGRpZ2l0cyArIHJlc3VsdDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZ2V0SGlnaEJpdHMgPSBmdW5jdGlvbiBnZXRIaWdoQml0cygpIHsKICAgICAgICByZXR1cm4gdGhpcy5oaWdoOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmdldEhpZ2hCaXRzVW5zaWduZWQgPSBmdW5jdGlvbiBnZXRIaWdoQml0c1Vuc2lnbmVkKCkgewogICAgICAgIHJldHVybiB0aGlzLmhpZ2ggPj4+IDA7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZ2V0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JvdG90eXBlLmlzUG9zaXRpdmUgPSBmdW5jdGlvbiBpc1Bvc2l0aXZlKCkgewogICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkIHx8IHRoaXMuaGlnaCA+PSAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzT2RkID0gZnVuY3Rpb24gaXNPZGQoKSB7CiAgICAgICAgcmV0dXJuICh0aGlzLmxvdyAmIDEpID09PSAxOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzRXZlbiA9IGZ1bmN0aW9uIGlzRXZlbigpIHsKICAgICAgICByZXR1cm4gKHRoaXMubG93ICYgMSkgPT09IDA7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZXF1YWxzID0gZnVuY3Rpb24gZXF1YWxzKG90aGVyKSB7CiAgICAgICAgaWYgKCFpc0xvbmcob3RoZXIpKQogICAgICAgICAgb3RoZXIgPSBmcm9tVmFsdWUob3RoZXIpOwogICAgICAgIGlmICh0aGlzLnVuc2lnbmVkICE9PSBvdGhlci51bnNpZ25lZCAmJiB0aGlzLmhpZ2ggPj4+IDMxID09PSAxICYmIG90aGVyLmhpZ2ggPj4+IDMxID09PSAxKQogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIHJldHVybiB0aGlzLmhpZ2ggPT09IG90aGVyLmhpZ2ggJiYgdGhpcy5sb3cgPT09IG90aGVyLmxvdzsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5lcSA9IExvbmdQcm90b3R5cGUuZXF1YWxzOwogICAgICBMb25nUHJvdG90eXBlLm5vdEVxdWFscyA9IGZ1bmN0aW9uIG5vdEVxdWFscyhvdGhlcikgewogICAgICAgIHJldHVybiAhdGhpcy5lcShvdGhlcik7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUubmVxID0gTG9uZ1Byb3RvdHlwZS5ub3RFcXVhbHM7CiAgICAgIExvbmdQcm90b3R5cGUubmUgPSBMb25nUHJvdG90eXBlLm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J0cmFoZW5kKSB7CiAgICAgICAgaWYgKCFpc0xvbmcoc3VidHJhaGVuZCkpCiAgICAgICAgICBzdWJ0cmFoZW5kID0gZnJvbVZhbHVlKHN1YnRyYWhlbmQpOwogICAgICAgIHJldHVybiB0aGlzLmFkZChzdWJ0cmFoZW5kLm5lZygpKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zdWIgPSBMb25nUHJvdG90eXBlLnN1YnRyYWN0OwogICAgICBMb25nUHJvdG90eXBlLm11bHRpcGx5ID0gZnVuY3Rpb24gbXVsdGlwbHkobXVsdGlwbGllcikgewogICAgICAgIGlmICh0aGlzLmlzWmVybygpKQogICAgICAgICAgcmV0dXJuIFpFUk87CiAgICAgICAgaWYgKCFpc0xvbmcobXVsdGlwbGllcikpCiAgICAgICAgICBtdWx0aXBsaWVyID0gZnJvbVZhbHVlKG11bHRpcGxpZXIpOwogICAgICAgIGlmICh3YXNtKSB7CiAgICAgICAgICB2YXIgbG93ID0gd2FzbS5tdWwodGhpcy5sb3csIHRoaXMuaGlnaCwgbXVsdGlwbGllci5sb3csIG11bHRpcGxpZXIuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAobXVsdGlwbGllci5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiBaRVJPOwogICAgICAgIGlmICh0aGlzLmVxKE1JTl9WQUxVRSkpCiAgICAgICAgICByZXR1cm4gbXVsdGlwbGllci5pc09kZCgpID8gTUlOX1ZBTFVFIDogWkVSTzsKICAgICAgICBpZiAobXVsdGlwbGllci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgcmV0dXJuIHRoaXMuaXNPZGQoKSA/IE1JTl9WQUxVRSA6IFpFUk87CiAgICAgICAgaWYgKHRoaXMuaXNOZWdhdGl2ZSgpKSB7CiAgICAgICAgICBpZiAobXVsdGlwbGllci5pc05l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iYgZGl2aXNvci5sb3cgPT09IC0xICYmIGRpdmlzb3IuaGlnaCA9PT0gLTEpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgICB9CiAgICAgICAgICB2YXIgbG93ID0gKHRoaXMudW5zaWduZWQgPyB3YXNtLmRpdl91IDogd2FzbS5kaXZfcykodGhpcy5sb3csIHRoaXMuaGlnaCwgZGl2aXNvci5sb3csIGRpdmlzb3IuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkID8gVVpFUk8gOiBaRVJPOwogICAgICAgIHZhciBhcHByb3gsIHJlbSwgcmVzOwogICAgICAgIGlmICghdGhpcy51bnNpZ25lZCkgewogICAgICAgICAgaWYgKHRoaXMuZXEoTUlOX1ZBTFVFKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5lcShPTkUpIHx8IGRpdmlzb3IuZXEoTkVHX09ORSkpCiAgICAgICAgICAgICAgcmV0dXJuIE1JTl9WQUxVRTsKICAgICAgICAgICAgZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICAgIHJldHVybiBPTkU7CiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgIHZhciBoYWxmVGhpcyA9IHRoaXMuc2hyKDEpOwogICAgICAgICAgICAgIGFwcHJveCA9IGhhbGZUaGlzLmRpdihkaXZpc29yKS5zaGwoMSk7CiAgICAgICAgICAgICAgaWYgKGFwcHJveC5lcShaRVJPKSkgewogICAgICAgICAgICAgICAgcmV0dXJuIGRpdmlzb3IuaXNOZWdhdGl2ZSgpID8gT05FIDogTkVHX09ORTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmVtID0gdGhpcy5zdWIoZGl2aXNvci5tdWwoYXBwcm94KSk7CiAgICAgICAgICAgICAgICByZXMgPSBhcHByb3guYWRkKHJlbS5kaXYoZGl2aXNvcikpOwogICAgICAgICAgICAgICAgcmV0dXJuIHJlczsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICByZXR1cm4gdGhpcy51bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICAgIGlmICh0aGlzLmlzTmVnYXRpdmUoKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5pc05lZ2F0aXZlKCkpCiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVnKCkuZGl2KGRpdmlzb3IubmVnKCkpOwogICAgICAgICAgICByZXR1cm4gdGhpcy5uZWcoKS5kaXYoZGl2aXNvcikubmVnKCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGRpdmlzb3IuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgICByZXR1cm4gdGhpcy5kaXYoZGl2aXNvci5uZWcoKSkubmVnKCk7CiAgICAgICAgICByZXMgPSBaRVJPOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoIWRpdmlzb3IudW5zaWduZWQpCiAgICAgICAgICAgIGRpdmlzb3IgPSBkaXZpc29yLnRvVW5zaWduZWQoKTsKICAgICAgICAgIGlmIChkaXZpc29yLmd0KHRoaXMpKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAoZGl2aXNvci5ndCh0aGlzLnNocnUoMSkpKQogICAgICAgICAgICByZXR1cm4gVU9ORTsKICAgICAgICAgIHJlcyA9IFVaRVJPOwogICAgICAgIH0KICAgICAgICByZW0gPSB0aGlzOwogICAgICAgIHdoaWxlIChyZW0uZ3RlKGRpdmlzb3IpKSB7CiAgICAgICAgICBhcHByb3ggPSBNYXRoLm1heCgxLCBNYXRoLmZsb29yKHJlbS50b051bWJlcigpIC8gZGl2aXNvci50b051bWJlcigpKSk7CiAgICAgICAgICB2YXIgbG9nMiA9IE1hdGguY2VpbChNYXRoLmxvZyhhcHByb3gpIC8gTWF0aC5MTjIpLCBkZWx0YSA9IGxvZzIgPD0gNDggPyAxIDogcG93X2RibCgyLCBsb2cyIC0gNDgpLCBhcHByb3hSZXMgPSBmcm9tTnVtYmVyKGFwcHJveCksIGFwcHJveFJlbSA9IGFwcHJveFJlcy5tdWwoZGl2aXNvcik7CiAgICAgICAgICB3aGlsZSAoYXBwcm94UmVtLmlzTmVnYXRpdmUoKSB8fCBhcHByb3hSZW0uZ3QocmVtKSkgewogICAgICAgICAgICBhcHByb3ggLT0gZGVsdGE7CiAgICAgICAgICAgIGFwcHJveFJlcyA9IGZyb21OdW1iZXIoYXBwcm94LCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICAgICAgYXBwcm94UmVtID0gYXBwcm94UmVzLm11bChkaXZpc29yKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChhcHByb3hSZXMuaXNaZXJvKCkpCiAgICAgICAgICAgIGFwcHJveFJlcyA9IE9ORTsKICAgICAgICAgIHJlcyA9IHJlcy5hZGQoYXBwcm94UmVzKTsKICAgICAgICAgIHJlbSA9IHJlbS5zdWIoYXBwcm94UmVtKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlczsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5kaXYgPSBMb25nUHJvdG90eXBlLmRpdmlkZTsKICAgICAgTG9uZ1Byb3RvdHlwZS5tb2R1bG8gPSBmdW5jdGlvbiBtb2R1bG8oZGl2aXNvcikgewogICAgICAgIGlmICghaXNMb25nKGRpdmlzb3IpKQogICAgICAgICAgZGl2aXNvciA9IGZyb21WYWx1ZShkaXZpc29yKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgdmFyIGxvdyA9ICh0aGlzLnVuc2lnbmVkID8gd2FzbS5yZW1fdSA6IHdhc20ucmVtX3MpKHRoaXMubG93LCB0aGlzLmhpZ2gsIGRpdmlzb3IubG93LCBkaXZpc29yLmhpZ2gpOwogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGxvdywgd2FzbS5nZXRfaGlnaCgpLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXMuc3ViKHRoaXMuZGl2KGRpdmlzb3IpLm11bChkaXZpc29yKSk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUubW9kID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUucmVtID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUubm90ID0gZnVuY3Rpb24gbm90KCkgewogICAgICAgIHJldHVybiBmcm9tQml0cyh+dGhpcy5sb3csIH50aGlzLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmFuZCA9IGZ1bmN0aW9uIGFuZChvdGhlcikgewogICAgICAgIGlmICghaXNMb25nKG90aGVyKSkKICAgICAgICAgIG90aGVyID0gZnJvbVZhbHVlKG90aGVyKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3cgJiBvdGhlci5sb3csIHRoaXMuaGlnaCAmIG90aGVyLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm9yID0gZnVuY3Rpb24gb3Iob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1ZShvdGhlcik7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93IHwgb3RoZXIubG93LCB0aGlzLmhpZ2ggfCBvdGhlci5oaWdoLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS54b3IgPSBmdW5jdGlvbiB4b3Iob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1ZShvdGhlcik7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93IF4gb3RoZXIubG93LCB0aGlzLmhpZ2ggXiBvdGhlci5oaWdoLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdExlZnQgPSBmdW5jdGlvbiBzaGlmdExlZnQobnVtQml0cykgewogICAgICAgIGlmIChpc0xvbmcobnVtQml0cykpCiAgICAgICAgICBudW1CaXRzID0gbnVtQml0cy50b0ludCgpOwogICAgICAgIGlmICgobnVtQml0cyAmPSA2MykgPT09IDApCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBlbHNlIGlmIChudW1CaXRzIDwgMzIpCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3cgPDwgbnVtQml0cywgdGhpcy5oaWdoIDw8IG51bUJpdHMgfCB0aGlzLmxvdyA+Pj4gMzIgLSBudW1CaXRzLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICBlbHNlCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMoMCwgdGhpcy5sb3cgPDwgbnVtQml0cyAtIDMyLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGwgPSBMb25nUHJvdG90eXBlLnNoaWZ0TGVmdDsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0ID0gZnVuY3Rpb24gc2hpZnRSaWdodChudW1CaXRzKSB7CiAgICAgICAgaWYgKGlzTG9uZyhudW1CaXRzKSkKICAgICAgICAgIG51bUJpdHMgPSBudW1CaXRzLnRvSW50KCk7CiAgICAgICAgaWYgKChudW1CaXRzICY9IDYzKSA9PT0gMCkKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIGVsc2UgaWYgKG51bUJpdHMgPCAzMikKICAgICAgICAgIHJldHVybiBmcm9tQml0cyh0aGlzLmxvdyA+Pj4gbnVtQml0cyB8IHRoaXMuaGlnaCA8PCAzMiAtIG51bUJpdHMsIHRoaXMuaGlnaCA+PiBudW1CaXRzLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICBlbHNlCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5oaWdoID4+IG51bUJpdHMgLSAzMiwgdGhpcy5oaWdoID49IDAgPyAwIDogLTEsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnNociA9IExvbmdQcm90b3R5cGUuc2hpZnRSaWdodDsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0VW5zaWduZWQgPSBmdW5jdGlvbiBzaGlmdFJpZ2h0VW5zaWduZWQobnVtQml0cykgewogICAgICAgIGlmIChpc0xvbmcobnVtQml0cykpCiAgICAgICAgICBudW1CaXRzID0gbnVtQml0cy50b0ludCgpOwogICAgICAgIG51bUJpdHMgJj0gNjM7CiAgICAgICAgaWYgKG51bUJpdHMgPT09IDApCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBlbHNlIHsKICAgICAgICAgIHZhciBoaWdoID0gdGhpcy5oaWdoOwogICAgICAgICAgaWYgKG51bUJpdHMgPCAzMikgewogICAgICAgICAgICB2YXIgbG93ID0gdGhpcy5sb3c7CiAgICAgICAgICAgIHJldHVybiBmcm9tQml0cyhsb3cgPj4+IG51bUJpdHMgfCBoaWdoIDw8IDMyIC0gbnVtQml0cywgaGlnaCA+Pj4gbnVtQml0cywgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgICB9IGVsc2UgaWYgKG51bUJpdHMgPT09IDMyKQogICAgICAgICAgICByZXR1cm4gZnJvbUJpdHMoaGlnaCwgMCwgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHJldHVybiBmcm9tQml0cyhoaWdoID4+P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ZhbGxiYWNrRGVzZXJpYWxpemVyKTsKICAgICAgICAgIH0sCiAgICAgICAgICBzZXJpYWxpemUoaW5wdXQpIHsKICAgICAgICAgICAgcmV0dXJuIGltcGxlbWVudGF0aW9uLnNlcmlhbGl6ZShpbnB1dCwgZmFsbGJhY2tTZXJpYWxpemVyKTsKICAgICAgICAgIH0KICAgICAgICB9OwogICAgICB9CiAgICAgIGV4cG9ydHMyLmV4dGVuZFNlcmlhbGl6ZXIgPSBleHRlbmRTZXJpYWxpemVyOwogICAgICB2YXIgRGVmYXVsdEVycm9yU2VyaWFsaXplciA9IHsKICAgICAgICBkZXNlcmlhbGl6ZShtZXNzYWdlKSB7CiAgICAgICAgICByZXR1cm4gT2JqZWN0LmFzc2lnbihFcnJvcihtZXNzYWdlLm1lc3NhZ2UpLCB7CiAgICAgICAgICAgIG5hbWU6IG1lc3NhZ2UubmFtZSwKICAgICAgICAgICAgc3RhY2s6IG1lc3NhZ2Uuc3RhY2sKICAgICAgICAgIH0pOwogICAgICAgIH0sCiAgICAgICAgc2VyaWFsaXplKGVycm9yKSB7CiAgICAgICAgICByZXR1cm4gewogICAgICAgICAgICBfX2Vycm9yX21hcmtlcjogIiQkZXJyb3IiLAogICAgICAgICAgICBtZXNzYWdlOiBlcnJvci5tZXNzYWdlLAogICAgICAgICAgICBuYW1lOiBlcnJvci5uYW1lLAogICAgICAgICAgICBzdGFjazogZXJyb3Iuc3RhY2sKICAgICAgICAgIH07CiAgICAgICAgfQogICAgICB9OwogICAgICB2YXIgaXNTZXJpYWxpemVkRXJyb3IgPSAodGhpbmcpID0+IHRoaW5nICYmIHR5cGVvZiB0aGluZyA9PT0gIm9iamVjdCIgJiYgIl9fZXJyb3JfbWFya2VyIiBpbiB0aGluZyAmJiB0aGluZy5fX2Vycm9yX21hcmtlciA9PT0gIiQkZXJyb3IiOwogICAgICBleHBvcnRzMi5EZWZhdWx0U2VyaWFsaXplciA9IHsKICAgICAgICBkZXNlcmlhbGl6ZShtZXNzYWd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aXN0L3dvcmtlci9pbmRleC5qcwogIHZhciByZXF1aXJlX3dvcmtlciA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS90aHJlYWRzQDEuNy4wL25vZGVfbW9kdWxlcy90aHJlYWRzL2Rpc3Qvd29ya2VyL2luZGV4LmpzIihleHBvcnRzMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIF9fYXdhaXRlciA9IGV4cG9ydHMyICYmIGV4cG9ydHMyLl9fYXdhaXRlciB8fCBmdW5jdGlvbih0aGlzQXJnLCBfYXJndW1lbnRzLCBQLCBnZW5lcmF0b3IpIHsKICAgICAgICBmdW5jdGlvbiBhZG9wdCh2YWx1ZSkgewogICAgICAgICAgcmV0dXJuIHZhbHVlIGluc3RhbmNlb2YgUCA/IHZhbHVlIDogbmV3IFAoZnVuY3Rpb24ocmVzb2x2ZSkgewogICAgICAgICAgICByZXNvbHZlKHZhbHVlKTsKICAgICAgICAgIH0pOwogICAgICAgIH0KICAgICAgICByZXR1cm4gbmV3IChQIHx8IChQID0gUHJvbWlzZSkpKGZ1bmN0aW9uKHJlc29sdmUsIHJlamVjdCkgewogICAgICAgICAgZnVuY3Rpb24gZnVsZmlsbGVkKHZhbHVlKSB7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgc3RlcChnZW5lcmF0b3IubmV4dCh2YWx1ZSkpOwogICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgcmVqZWN0KGUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiByZWplY3RlZCh2YWx1ZSkgewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIHN0ZXAoZ2VuZXJhdG9yWyJ0aHJvdyJdKHZhbHVlKSk7CiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICByZWplY3QoZSk7Ci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SUQpOwogICAgICAgICAgICB9LCAoKSA9PiB7CiAgICAgICAgICAgICAgcG9zdEpvYlJlc3VsdE1lc3NhZ2Uoam9iVUlELCB0cnVlKTsKICAgICAgICAgICAgICBhY3RpdmVTdWJzY3JpcHRpb25zLmRlbGV0ZShqb2JVSUQpOwogICAgICAgICAgICB9KTsKICAgICAgICAgICAgYWN0aXZlU3Vic2NyaXB0aW9ucy5zZXQoam9iVUlELCBzdWJzY3JpcHRpb24pOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBjb25zdCByZXN1bHQgPSB5aWVsZCBzeW5jUmVzdWx0OwogICAgICAgICAgICAgIHBvc3RKb2JSZXN1bHRNZXNzYWdlKGpvYlVJRCwgdHJ1ZSwgY29tbW9uXzEuc2VyaWFsaXplKHJlc3VsdCkpOwogICAgICAgICAgICB9IGNhdGNoIChlcnJvcikgewogICAgICAgICAgICAgIHBvc3RKb2JFcnJvck1lc3NhZ2Uoam9iVUlELCBjb21tb25fMS5zZXJpYWxpemUoZXJyb3IpKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGV4cG9zZTIoZXhwb3NlZCkgewogICAgICAgIGlmICghaW1wbGVtZW50YXRpb25fMS5kZWZhdWx0LmlzV29ya2VyUnVudGltZSgpKSB7CiAgICAgICAgICB0aHJvdyBFcnJvcigiZXhwb3NlKCkgY2FsbGVkIGluIHRoZSBtYXN0ZXIgdGhyZWFkLiIpOwogICAgICAgIH0KICAgICAgICBpZiAoZXhwb3NlQ2FsbGVkKSB7CiAgICAgICAgICB0aHJvdyBFcnJvcigiZXhwb3NlKCkgY2FsbGVkIG1vcmUgdGhhbiBvbmNlLiBUaGlzIGlzIG5vdCBwb3NzaWJsZS4gUGFzcyBhbiBvYmplY3QgdG8gZXhwb3NlKCkgaWYgeW91IHdhbnQgdG8gZXhwb3NlIG11bHRpcGxlIGZ1bmN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ZW50TGlzdGVuZXIoImVycm9yIiwgKGV2ZW50KSA9PiB7CiAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHBvc3RVbmNhdWdodEVycm9yTWVzc2FnZShldmVudC5lcnJvciB8fCBldmVudCksIDI1MCk7CiAgICAgICAgfSk7CiAgICAgICAgc2VsZi5hZGRFdmVudExpc3RlbmVyKCJ1bmhhbmRsZWRyZWplY3Rpb24iLCAoZXZlbnQpID0+IHsKICAgICAgICAgIGNvbnN0IGVycm9yID0gZXZlbnQucmVhc29uOwogICAgICAgICAgaWYgKGVycm9yICYmIHR5cGVvZiBlcnJvci5tZXNzYWdlID09PSAic3RyaW5nIikgewogICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHBvc3RVbmNhdWdodEVycm9yTWVzc2FnZShlcnJvciksIDI1MCk7CiAgICAgICAgICB9CiAgICAgICAgfSk7CiAgICAgIH0KICAgICAgaWYgKHR5cGVvZiBwcm9jZXNzICE9PSAidW5kZWZpbmVkIiAmJiB0eXBlb2YgcHJvY2Vzcy5vbiA9PT0gImZ1bmN0aW9uIiAmJiBpbXBsZW1lbnRhdGlvbl8xLmRlZmF1bHQuaXNXb3JrZXJSdW50aW1lKCkpIHsKICAgICAgICBwcm9jZXNzLm9uKCJ1bmNhdWdodEV4Y2VwdGlvbiIsIChlcnJvcikgPT4gewogICAgICAgICAgc2V0VGltZW91dCgoKSA9PiBwb3N0VW5jYXVnaHRFcnJvck1lc3NhZ2UoZXJyb3IpLCAyNTApOwogICAgICAgIH0pOwogICAgICAgIHByb2Nlc3Mub24oInVuaGFuZGxlZFJlamVjdGlvbiIsIChlcnJvcikgPT4gewogICAgICAgICAgaWYgKGVycm9yICYmIHR5cGVvZiBlcnJvci5tZXNzYWdlID09PSAic3RyaW5nIikgewogICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHBvc3RVbmNhdWdodEVycm9yTWVzc2FnZShlcnJvciksIDI1MCk7CiAgICAgICAgICB9CiAgICAgICAgfSk7CiA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ICAgICAgICAgZW5kOiBmdW5jdGlvbihleHBlY3RhdGlvbikgewogICAgICAgICAgICByZXR1cm4gImVuZCBvZiBpbnB1dCI7CiAgICAgICAgICB9LAogICAgICAgICAgb3RoZXI6IGZ1bmN0aW9uKGV4cGVjdGF0aW9uKSB7CiAgICAgICAgICAgIHJldHVybiBleHBlY3RhdGlvbi5kZXNjcmlwdGlvbjsKICAgICAgICAgIH0KICAgICAgICB9OwogICAgICAgIGZ1bmN0aW9uIGhleChjaCkgewogICAgICAgICAgcmV0dXJuIGNoLmNoYXJDb2RlQXQoMCkudG9TdHJpbmcoMTYpLnRvVXBwZXJDYXNlKCk7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIGxpdGVyYWxFc2NhcGUocykgewogICAgICAgICAgcmV0dXJuIHMucmVwbGFjZSgvXFwvZywgIlxcXFwiKS5yZXBsYWNlKC8iL2csICdcXCInKS5yZXBsYWNlKC9cMC9nLCAiXFwwIikucmVwbGFjZSgvXHQvZywgIlxcdCIpLnJlcGxhY2UoL1xuL2csICJcXG4iKS5yZXBsYWNlKC9cci9nLCAiXFxyIikucmVwbGFjZSgvW1x4MDAtXHgwRl0vZywgZnVuY3Rpb24oY2gpIHsKICAgICAgICAgICAgcmV0dXJuICJcXHgwIiArIGhleChjaCk7CiAgICAgICAgICB9KS5yZXBsYWNlKC9bXHgxMC1ceDFGXHg3Ri1ceDlGXS9nLCBmdW5jdGlvbihjaCkgewogICAgICAgICAgICByZXR1cm4gIlxceCIgKyBoZXgoY2gpOwogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIGNsYXNzRXNjYXBlKHMpIHsKICAgICAgICAgIHJldHVybiBzLnJlcGxhY2UoL1xcL2csICJcXFxcIikucmVwbGFjZSgvXF0vZywgIlxcXSIpLnJlcGxhY2UoL1xeL2csICJcXF4iKS5yZXBsYWNlKC8tL2csICJcXC0iKS5yZXBsYWNlKC9cMC9nLCAiXFwwIikucmVwbGFjZSgvXHQvZywgIlxcdCIpLnJlcGxhY2UoL1xuL2csICJcXG4iKS5yZXBsYWNlKC9cci9nLCAiXFxyIikucmVwbGFjZSgvW1x4MDAtXHgwRl0vZywgZnVuY3Rpb24oY2gpIHsKICAgICAgICAgICAgcmV0dXJuICJcXHgwIiArIGhleChjaCk7CiAgICAgICAgICB9KS5yZXBsYWNlKC9bXHgxMC1ceDFGXHg3Ri1ceDlGXS9nLCBmdW5jdGlvbihjaCkgewogICAgICAgICAgICByZXR1cm4gIlxceCIgKyBoZXgoY2gpOwogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIGRlc2NyaWJlRXhwZWN0YXRpb24oZXhwZWN0YXRpb24pIHsKICAgICAgICAgIHJldHVybiBERVNDUklCRV9FWFBFQ1RBVElPTl9GTlNbZXhwZWN0YXRpb24udHlwZV0oZXhwZWN0YXRpb24pOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBkZXNjcmliZUV4cGVjdGVkKGV4cGVjdGVkMikgewogICAgICAgICAgdmFyIGRlc2NyaXB0aW9ucyA9IG5ldyBBcnJheShleHBlY3RlZDIubGVuZ3RoKSwgaSwgajsKICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBleHBlY3RlZDIubGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgZGVzY3JpcHRpb25zW2ldID0gZGVzY3JpYmVFeHBlY3RhdGlvbihleHBlY3RlZDJbaV0pOwogICAgICAgICAgfQogICAgICAgICAgZGVzY3JpcHRpb25zLnNvcnQoKTsKICAgICAgICAgIGlmIChkZXNjcmlwdGlvbnMubGVuZ3RoID4gMCkgewogICAgICAgICAgICBmb3IgKGkgPSAxLCBqID0gMTsgaSA8IGRlc2NyaXB0aW9ucy5sZW5ndGg7IGkrKykgewogICAgICAgICAgICAgIGlmIChkZXNjcmlwdGlvbnNbaSAtIDFdICE9PSBkZXNjcmlwdGlvbnNbaV0pIHsKICAgICAgICAgICAgICAgIGRlc2NyaXB0aW9uc1tqXSA9IGRlc2NyaXB0aW9uc1tpXTsKICAgICAgICAgICAgICAgIGorKzsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZGVzY3JpcHRpb25zLmxlbmd0aCA9IGo7CiAgICAgICAgICB9CiAgICAgICAgICBzd2l0Y2ggKGRlc2NyaXB0aW9ucy5sZW5ndGgpIHsKICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgIHJldHVybiBkZXNjcmlwdGlvbnNbMF07CiAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICByZXR1cm4gZGVzY3JpcHRpb25zWzBdICsgIiBvciAiICsgZGVzY3JpcHRpb25zWzFdOwogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgIHJldHVybiBkZXNjcmlwdGlvbnMuc2xpY2UoMCwgLTEpLmpvaW4oIiwgIikgKyAiLCBvciAiICsgZGVzY3JpcHRpb25zW2Rlc2NyaXB0aW9ucy5sZW5ndGggLSAxXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gZGVzY3JpYmVGb3VuZChmb3VuZDIpIHsKICAgICAgICAgIHJldHVybiBmb3VuZDIgPyAnIicgKyBsaXRlcmFsRXNjYXBlKGZvdW5kMikgKyAnIicgOiAiZW5kIG9mIGlucHV0IjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuICJFeHBlY3RlZCAiICsgZGVzY3JpYmVFeHBlY3RlZChleHBlY3RlZCkgKyAiIGJ1dCAiICsgZGVzY3JpYmVGb3VuZChmb3VuZCkgKyAiIGZvdW5kLiI7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZShpbnB1dCwgb3B0aW9ucykgewogICAgICAgIG9wdGlvbnMgPSBvcHRpb25zICE9PSB2b2lkIDAgPyBvcHRpb25zIDoge307CiAgICAgICAgdmFyIHBlZyRGQUlMRUQgPSB7fSwgcGVnJHN0YXJ0UnVsZUZ1bmN0aW9ucyA9IH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gICAgICBmdW5jdGlvbiBwZWckbGl0ZXJhbEV4cGVjdGF0aW9uKHRleHQyLCBpZ25vcmVDYXNlKSB7CiAgICAgICAgICByZXR1cm4geyB0eXBlOiAibGl0ZXJhbCIsIHRleHQ6IHRleHQyLCBpZ25vcmVDYXNlIH07CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRjbGFzc0V4cGVjdGF0aW9uKHBhcnRzLCBpbnZlcnRlZCwgaWdub3JlQ2FzZSkgewogICAgICAgICAgcmV0dXJuIHsgdHlwZTogImNsYXNzIiwgcGFydHMsIGludmVydGVkLCBpZ25vcmVDYXNlIH07CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRhbnlFeHBlY3RhdGlvbigpIHsKICAgICAgICAgIHJldHVybiB7IHR5cGU6ICJhbnkiIH07CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRlbmRFeHBlY3RhdGlvbigpIHsKICAgICAgICAgIHJldHVybiB7IHR5cGU6ICJlbmQiIH07CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRvdGhlckV4cGVjdGF0aW9uKGRlc2NyaXB0aW9uKSB7CiAgICAgICAgICByZXR1cm4geyB0eXBlOiAib3RoZXIiLCBkZXNjcmlwdGlvbiB9OwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckY29tcHV0ZVBvc0RldGFpbHMocG9zKSB7CiAgICAgICAgICB2YXIgZGV0YWlscyA9IHBlZyRwb3NEZXRhaWxzQ2FjaGVbcG9zXSwgcDsKICAgICAgICAgIGlmIChkZXRhaWxzKSB7CiAgICAgICAgICAgIHJldHVybiBkZXRhaWxzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcCA9IHBvcyAtIDE7CiAgICAgICAgICAgIHdoaWxlICghcGVnJHBvc0RldGFpbHNDYWNoZVtwXSkgewogICAgICAgICAgICAgIHAtLTsKICAgICAgICAgICAgfQogICAgICAgICAgICBkZXRhaWxzID0gcGVnJHBvc0RldGFpbHNDYWNoZVtwXTsKICAgICAgICAgICAgZGV0YWlscyA9IHsKICAgICAgICAgICAgICBsaW5lOiBkZXRhaWxzLmxpbmUsCiAgICAgICAgICAgICAgY29sdW1uOiBkZXRhaWxzLmNvbHVtbgogICAgICAgICAgICB9OwogICAgICAgICAgICB3aGlsZSAocCA8IHBvcykgewogICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHApID09PSAxMCkgewogICAgICAgICAgICAgICAgZGV0YWlscy5saW5lKys7CiAgICAgICAgICAgICAgICBkZXRhaWxzLmNvbHVtbiA9IDE7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGRldGFpbHMuY29sdW1uKys7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHArKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBwZWckcG9zRGV0YWlsc0NhY2hlW3Bvc10gPSBkZXRhaWxzOwogICAgICAgICAgICByZXR1cm4gZGV0YWlsczsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJGNvbXB1dGVMb2NhdGlvbihzdGFydFBvcywgZW5kUG9zKSB7CiAgICAgICAgICB2YXIgc3RhcnRQb3NEZXRhaWxzID0gcGVnJGNvbXB1dGVQb3NEZXRhaWxzKHN0YXJ0UG9zKSwgZW5kUG9zRGV0YWlscyA9IHBlZyRjb21wdXRlUG9zRGV0YWlscyhlbmRQb3MpOwogICAgICAgICAgcmV0dXJuIHsKICAgICAgICAgICAgc3RhcnQ6IHsKICAgICAgICAgICAgICBvZmZzZXQ6IHN0YXJ0UG9zLAogICAgICAgICAgICAgIGxpbmU6IHN0YXJ0UG9zRGV0YWlscy5saW5lLAogICAgICAgICAgICAgIGNvbHVtbjogc3RhcnRQb3NEZXRhaWxzLmNvbHVtbgogICAgICAgICAgICB9LAogICAgICAgICAgICBlbmQ6IHsKICAgICAgICAgICAgICBvZmZzZXQ6IGVuZFBvcywKICAgICAgICAgICAgICBsaW5lOiBlbmRQb3NEZXRhaWxzLmxpbmUsCiAgICAgICAgICAgICAgY29sdW1uOiBlbmRQb3NEZXRhaWxzLmNvbHVtbgogICAgICAgICAgICB9CiAgICAgICAgICB9OwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckZmFpbChleHBlY3RlZDIpIHsKICAgICAgICAgIGlmIChwZWckY3VyclBvcyA8IHBlZyRtYXhGYWlsUG9zKSB7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChwZWckY3VyclBvcyA+IHBlZyRtYXhGYWlsUG9zKSB7CiAgICAgICAgICAgIHBlZyRtYXhGYWlsUG9zID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICAgIHBlZyRtYXhGYWlsRXhwZWN0ZWQgPSBbXTsKICAgICAgICAgIH0KICAgICAgICAgIHBlZyRtYXhGYWlsRXhwZWN0ZWQucHVzaChleHBlY3RlZDIpOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckYnVpbGRTaW1wbGVFcnJvcihtZXNzYWdlLCBsb2NhdGlvbjIpIHsKICAgICAgICAgIHJldHVybiBuZXcgcGVnJFN5bnRheEVycm9yKG1lc3NhZ2UsIG51bGwsIG51bGwsIGxvY2F0aW9uMik7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRidWlsZFN0cnVjdHVyZWRFcnJvcihleHBlY3RlZDIsIGZvdW5kLCBsb2NhdGlvbjIpIHsKICAgICAgICAgIHJldHVybiBuZXcgcGVnJFN5bnRheEVycm9yKHBlZyRTeW50YXhFcnJvci5idWlsZE1lc3NhZ2UoZXhwZWN0ZWQyLCBmb3VuZCksIGV4cGVjdGVkMiwgZm91bmQsIGxvY2F0aW9uMik7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWRlY2xhcmF0aW9uKCkgewogICAgICAgICAgdmFyIHMwLCBzMSwgczIsIHMzLCBzNCwgczUsIHM2LCBzNywgczgsIHM5LCBzMTAsIHMxMSwgczEyLCBzMTM7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBwZWckcGFyc2VkZWNsYXJlVHlwZSgpOwogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlZGVjbGFyZU5hbWUoKTsKICAgICAgICAgICAgICAgIGlmIChzNCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBzNSA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgaWYgKHM1ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgczYgPSBwZWckcGFyc2Vjb21tZW50KCk7CiAgICAgICAgICAgICAgICAgICAgaWYgKHM2ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgICAgIGlmIChzNyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW5wdXQuY2hhckNvZGVBdChwZWckY3VyclBvcykgPT09IDQwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgczggPSBwZWckYzA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzOCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMxKTsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM4ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgczkgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM5ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTAgPSBwZWckcGFyc2VmaWVsZExpc3QoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMTAgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczExID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczExICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0MSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEyID0gcGVnJGMyOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEzID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEgPSBwZWckYzQoczIsIHM0LCBzNiwgczEwKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlZGVjbGFyZVR5cGUoKSB7CiAgICAgICAgICB2YXIgczA7CiAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA2KSA9PT0gcGVnJGM1KSB7CiAgICAgICAgICAgIHMwID0gcGVnJGM1OwogICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM2KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzcpIHsKICAgICAgICAgICAgICBzMCA9IHBlZyRjNzsKICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzgpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA1KSA9PT0gcGVnJGM5KSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRjOTsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMxMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWRlY2xhcmVOYW1lKCkgewogICAgICAgICAgdmFyIHMwLCBzMSwgczIsIHMzOwogICAgICAgICAgczAgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgczEgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMyID0gcGVnJHBhcnNlaW5kZXhUeXBlKCk7CiAgICAgICAgICAgICAgaWYgKHMyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzMSA9IFtzMSwgczJdOwogICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgICBzMSA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDQpID09PSBwZWckYzExKSB7CiAgICAgICAgICAgICAgICAgIHMyID0gcGVnJGMxMTsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMTIpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgczEgPSBbczEsIHMyXTsKICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgICAgICAgczEgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgczIgPSBwZWckcGFyc2VpbmRleFR5cGUoKTsKICAgICAgICAgICAgICAgICAgaWYgKHMyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjMTEpIHsKICAgICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJGMxMTsKICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDQ7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMxMik7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgczEgPSBbczEsIHMyLCBzM107CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2VpbmRleFR5cGUoKSB7CiAgICAgICAgICB2YXIgczA7CiAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA3KSA9PT0gcGVnJGMxMykgewogICAgICAgICAgICBzMCA9IHBlZyRjMTM7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDc7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzE0KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzE1KSB7CiAgICAgICAgICAgICAgczAgPSBwZWckYzE1OwogICAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDU7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMTYpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA2KSA9PT0gcGVnJGMxNykgewogICAgICAgICAgICAgICAgczAgPSBwZWckYzE3OwogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNjsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzE4KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlY29tbWVudCgpIHsKICAgICAgICAgIHZhciBzMDsKICAgICAgICAgIHMwID0gcGVnJHBhcnNlbm9uUXVvdGVkU3RyaW5nKCk7CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczAgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWZpZWxkTGlzdCgpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMywgczQsIHM1LCBzNjsKICAgICAgICAgIHMwID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgIGlmIChzMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMzID0gW107CiAgICAgICAgICAgICAgczQgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgICBzNSA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICBpZiAoczUgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlZmllbGQoKTsKICAgICAgICAgICAgICAgIGlmIChzNiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzNDsKICAgICAgICAgICAgICAgICAgczUgPSBwZWckYzE5KHMxLCBzNik7CiAgICAgICAgICAgICAgICAgIHM0ID0gczU7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHM0OwogICAgICAgICAgICAgICAgICBzNCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczQ7CiAgICAgICAgICAgICAgICBzNCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHdoaWxlIChzNCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczMucHVzaChzNCk7CiAgICAgICAgICAgICAgICBzNCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICBpZiAoczUgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgczYgPSBwZWckcGFyc2VmaWVsZCgpOwogICAgICAgICAgICAgICAgICBpZiAoczYgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzNDsKICAgICAgICAgICAgICAgICAgICBzNSA9IHBlZyRjMTkoczEsIHM2KTsKICAgICAgICAgICAgICAgICAgICBzNCA9IHM1OwogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczQ7CiAgICAgICAgICAgICAgICAgICAgczQgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHM0OwogICAgICAgICAgICAgICAgICBzNCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczQgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICBpZiAoczQgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMxID0gcGVnJGMyMChzMSwgczMpOwogICAgICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2Vjb21tZW50U3RhcnQoKSB7CiAgICAgICAgICB2YXIgczA7CiAgICAgICAgICBpZiAoaW5wdXQuY2hhckNvZGVBdChwZWckY3VyclBvcykgPT09IDM1KSB7CiAgICAgICAgICAgIHMwID0gcGVnJGMyMTsKICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMjIpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWludGVybmFsQ29tbWVudCgpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMywgczQ7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBwZWckcGFyc2Vjb21tZW50U3RhcnQoKTsKICAgICAgICAgICAgaWYgKHMyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczMgPSBwZWckcGFyc2Vub25RdW90ZWRTdHJpbmcoKTsKICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgIHMxID0gW3MxLCBzMiwgczMsIHM0XTsKICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlZmllbGQoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczMsIHM0LCBzNSwgczYsIHM3LCBzOCwgczksIHMxMCwgczExLCBzMTIsIHMxMzsKICAgICAgICAgIHMwID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkVHlwZSgpOwogICAgICAgICAgaWYgKHMxICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMyID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gNTkpIHsKICAgICAgICAgICAgICAgICAgICBzNSA9IHBlZyRjMjM7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBzNSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMyNCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzNSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgIGlmIChzNiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgczcgPSBwZWckcGFyc2Vjb21tZW50KCk7CiAgICAgICAgICAgICAgICAgICAgICBpZiAoczcgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMxID0gcGVnJGMyNShzMSwgczMsIHM3KTsKICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkVHlwZSgpOwogICAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBzMiA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gOTEpIHsKICAgICAgICAgICAgICAgICAgczMgPSBwZWckYzI2OwogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMyNyk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBzNCA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VmaWVsZFNpemUoKTsKICAgICAgICAgICAgICAgICAgICBpZiAoczUgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgaWYgKHM2ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gOTMpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRjMjg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMyOSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzNyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIHM4ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzOCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgczkgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczkgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEwID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczEwICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA1OSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczExID0gcGVnJGMyMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMjQpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczExICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczEyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxMyA9IHBlZyRwYXJzZWNvbW1lbnQoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRzYXZlZFBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxID0gcGVnJGMzMChzMSwgczUsIHM5LCBzMTMpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gczE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkVHlwZSgpOwogICAgICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0MCkgewogICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJGMwOwogICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgIGlmIChzNCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VmaWVsZFZhbHVlcygpOwogICAgICAgICAgICAgICAgICAgICAgaWYgKHM1ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoczYgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW5wdXQuY2hhckNvZGVBdChwZWckY3VyclBvcykgPT09IDQxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRjMjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHM3ID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM3ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzOCA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzOCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzOSA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM5ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEwID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMTAgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gNTkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczExID0gcGVnJGMyMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzI0KTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMTIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTMgPSBwZWckcGFyc2Vjb21tZW50KCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMSA9IHBlZyRjMzEoczEsIHM1LCBzOSwgczEzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gczE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczAgPSBwZWckcGFyc2VpbnRlcm5hbENvbW1lbnQoKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlZmllbGRWYWx1ZXMoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczMsIHM0LCBzNSwgczY7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBbXTsKICAgICAgICAgICAgczMgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0NCkgewogICAgICAgICAgICAgIHM0ID0gcGVnJGMzMjsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHM0ID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzMzKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgaWYgKHM1ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzNiA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICAgIGlmIChzNiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMzsKICAgICAgICAgICAgICAgICAgczQgPSBwZWckYzE5KHMxLCBzNik7CiAgICAgICAgICAgICAgICAgIHMzID0gczQ7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMzOwogICAgICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczM7CiAgICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczM7CiAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHdoaWxlIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMyLnB1c2goczMpOwogICAgICAgICAgICAgIHMzID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0NCkgewogICAgICAgICAgICAgICAgczQgPSBwZWckYzMyOwogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgczQgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzMzKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzNSA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgIGlmIChzNSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBzNiA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICAgICAgaWYgKHM2ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczM7CiAgICAgICAgICAgICAgICAgICAgczQgPSBwZWckYzE5KHMxLCBzNik7CiAgICAgICAgICAgICAgICAgICAgczMgPSBzNDsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMzOwogICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMzsKICAgICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMzOwogICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICBzMSA9IHBlZyRjMzQoczEsIHMyKTsKICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWZpZWxkVHlwZSgpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMzsKICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDMpID09PSBwZWckYzM1KSB7CiAgICAgICAgICAgIHMwID0gcGVnJGMzNTsKICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gMzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMzYpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjMzcpIHsKICAgICAgICAgICAgICBzMCA9IHBlZyRjMzc7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMzOCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzM5KSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRjMzk7CiAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA1OwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzQxKSB7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM0MTsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNjsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDIpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjNDMpIHsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNDM7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM0NCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzQ1KSB7CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNDU7CiAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA1OwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDYpOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzQ3KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM0NzsKICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNTsKICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDgpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjNDkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNDk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM1MCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzUxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNTE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNTIpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDcpID09PSBwZWckYzUzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM1MzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNTQpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjNTUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNTU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM1Nik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzU3KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNTc7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNTgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzU5KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM1OTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNjApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgMykgPT09IHBlZyRjNjEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNjE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM2Mik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEgPSBwZWckcGFyc2VkZWNsYXJlVHlwZSgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczMgPSBwZWckcGFyc2VkZWNsYXJlTmFtZSgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMSA9IHBlZyRjNjMoczEsIHMzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWZpZWxkU2l6ZSgpIHsKICAgICAgICAgIHZhciBzMDsKICAgICAgICAgIHMwID0gcGVnJHBhcnNlbnVtYmVyKCk7CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczAgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZW5hbWUoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczMsIHM0OwogICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgIHMxID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICBpZiAocGVnJGM2NC50ZXN0KGlucHV0LmNoYXJBdChwZWckY3VyclBvcykpKSB7CiAgICAgICAgICAgIHMyID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNjUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczMgPSBbXTsKICAgICAgICAgICAgaWYgKHBlZyRjNjYudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgIHM0ID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHM0ID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzY3KTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgd2hpbGUgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczMucHVzaChzNCk7CiAgICAgICAgICAgICAgaWYgKHBlZyRjNjYudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgICAgczQgPSBpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpOwogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgczQgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzY3KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMzICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczIgPSBbczIsIHMzXTsKICAgICAgICAgICAgICBzMSA9IHMyOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczE7CiAgICAgICAgICAgICAgczEgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBwZWckY3VyclBvcyA9IHMxOwogICAgICAgICAgICBzMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgIHMxID0gcGVnJGM2OChzMSk7CiAgICAgICAgICB9CiAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2VxdW90ZWRTdHJpbmcoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczM7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSAzNCkgewogICAgICAgICAgICBzMSA9IHBlZyRjNjk7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzcwKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMxICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMyID0gW107CiAgICAgICAgICAgIGlmIChwZWckYzcxLnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgICBzMyA9IGlucHV0LmNoYXJBdChwZWckY3VyclBvcyk7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3Mik7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHdoaWxlIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMyLnB1c2goczMpOwogICAgICAgICAgICAgIGlmIChwZWckYzcxLnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgICAgIHMzID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3Mik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gMzQpIHsKICAgICAgICAgICAgICAgIHMzID0gcGVnJGM2OTsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3MCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICBzMSA9IHBlZyRjNzMoczIpOwogICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlbm9uUXVvdGVkU3RyaW5nKCkgewogICAgICAgICAgdmFyIHMwLCBzMSwgczI7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBbXTsKICAgICAgICAgIGlmIChwZWckYzc0LnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgczIgPSBpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpOwogICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgczIgPSBwZWckRkFJTEVEOwogICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3NSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMS5wdXNoKHMyKTsKICAgICAgICAgICAgaWYgKHBlZyRjNzQudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgIHMyID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzc1KTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgczEgPSBwZWckYzc2KHMxKTsKICAgICAgICAgIH0KICAgICAgICAgIHMwID0gczE7CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZW51bWJlcigpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMzsKICAgICAgICAgIHBlZyRzaWxlbnRGYWlscysrOwogICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgIHMxID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgaWYgKHMxICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMyID0gW107CiAgICAgICAgICAgIGlmIChwZWckYzc4LnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgICBzMyA9IGlucHV0LmNoYXJBdChwZWckY3VyclBvcyk7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3OSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHdoaWxlIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczIucHVzaChzMyk7CiAgICAgICAgICAgICAgICBpZiAocGVnJGM3OC50ZXN0KGlucHV0LmNoYXJBdChwZWckY3VyclBvcykpKSB7CiAgICAgICAgICAgICAgICAgIHMzID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNzkpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICBzMSA9IHBlZyRjODAoKTsKICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICB9CiAgICAgICAgICBwZWckc2lsZW50RmFpbHMtLTsKICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzc3KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2VfKCkgewogICAgICAgICAgdmFyIHMwLCBzMTsKICAgICAgICAgIHBlZyRzaWxlbnRGYWlscysrOwogICAgICAgICAgczAgPSBbXTsKICAgICAgICAgIGlmIChwZWckYzgyLnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgczEgPSBpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpOwogICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgczEgPSBwZWckRkFJTEVEOwogICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM4Myk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMC5wdXNoKHMxKTsKICAgICAgICAgICAgaWYgKHBlZyRjODIudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgIHMxID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMxID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzgzKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHBlZyRzaWxlbnRGYWlscy0tOwogICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMxID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjODEpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIHBlZyRyZXN1bHQgPSBwZWckc3RhcnRSdWxlRnVuY3Rpb24oKTsKICAgICAgICBpZiAocGVnJHJlc3VsdCAhPT0gcGVnJEZBSUxFRCAmJiBwZWckY3VyclBvcyA9PT0gaW5wdXQubGVuZ3RoKSB7CiAgICAgICAgICByZXR1cm4gcGVnJHJlc3VsdDsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKHBlZyRyZXN1bHQgIT09IHBlZyRGQUlMRUQgJiYgcGVnJGN1cnJQb3MgPCBpbnB1dC5sZW5ndGgpIHsKICAgICAgICAgICAgcGVnJGZhaWwocGVnJGVuZEV4cGVjdGF0aW9uKCkpOwogICAgICAgICAgfQogICAgICAgICAgdGhyb3cgcGVnJGJ1aWxkU3RydWN0dXJlZEVycm9yKHBlZyRtYXhGYWlsRXhwZWN0ZWQsIHBlZyRtYXhGYWlsUG9zIDwgaW5wdXQubGVuZ3RoID8gaW5wdXQuY2hhckF0KHBlZyRtYXhGYWlsUG9zKSA6IG51bGwsIHBlZyRtYXhGYWlsUG9zIDwgaW5wdXQubGVuZ3RoID8gcGVnJGNvbXB1dGVMb2NhdGlvbihwZWckbWF4RmFpbFBvcywgcGVnJ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ICAgIG9wdHMgPSB7fTsKICAgICAgfSBlbHNlIHsKICAgICAgICBlbmNvZGluZyA9IG9wdGlvbnMuZW5jb2Rpbmc7CiAgICAgICAgb3B0cyA9IG9wdGlvbnM7CiAgICAgICAgZGVsZXRlIG9wdHMuZW5jb2Rpbmc7CiAgICAgIH0KICAgICAgY29uc3QgeyBoZWFkZXJzID0ge30sIHNpZ25hbCwgb3ZlcnJpZGVzID0ge30gfSA9IG9wdHM7CiAgICAgIGNvbnN0IGFyZ3MgPSB7CiAgICAgICAgaGVhZGVycywKICAgICAgICBtZXRob2Q6ICJHRVQiLAogICAgICAgIHJlZGlyZWN0OiAiZm9sbG93IiwKICAgICAgICBtb2RlOiAiY29ycyIsCiAgICAgICAgc2lnbmFsLAogICAgICAgIC4uLnRoaXMuYmFzZU92ZXJyaWRlcywKICAgICAgICAuLi5vdmVycmlkZXMKICAgICAgfTsKICAgICAgY29uc3QgcmVzcG9uc2UgPSBhd2FpdCB0aGlzLmZldGNoKHRoaXMudXJsLCBhcmdzKTsKICAgICAgaWYgKCFyZXNwb25zZSkgewogICAgICAgIHRocm93IG5ldyBFcnJvcigiZ2VuZXJpYy1maWxlaGFuZGxlIGZhaWxlZCB0byBmZXRjaCIpOwogICAgICB9CiAgICAgIGlmIChyZXNwb25zZS5zdGF0dXMgIT09IDIwMCkgewogICAgICAgIHRocm93IE9iamVjdC5hc3NpZ24obmV3IEVycm9yKGBIVFRQICR7cmVzcG9uc2Uuc3RhdHVzfSBmZXRjaGluZyAke3RoaXMudXJsfWApLCB7CiAgICAgICAgICBzdGF0dXM6IHJlc3BvbnNlLnN0YXR1cwogICAgICAgIH0pOwogICAgICB9CiAgICAgIGlmIChlbmNvZGluZyA9PT0gInV0ZjgiKSB7CiAgICAgICAgcmV0dXJuIHJlc3BvbnNlLnRleHQoKTsKICAgICAgfQogICAgICBpZiAoZW5jb2RpbmcpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoYHVuc3VwcG9ydGVkIGVuY29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h1bmtzID0gW107CiAgICAgIGNvbnN0IGNwb3NpdGlvbnMgPSBbXTsKICAgICAgY29uc3QgZHBvc2l0aW9ucyA9IFtdOwogICAgICBsZXQgdG90YWxTaXplID0gMDsKICAgICAgbGV0IGkgPSAwOwogICAgICBkbyB7CiAgICAgICAgY29uc3QgcmVtYWluaW5nSW5wdXQgPSBpbnB1dERhdGEuc3ViYXJyYXkoY3BvcyAtIG1pbnYuYmxvY2tQb3NpdGlvbik7CiAgICAgICAgY29uc3QgaW5mbGF0b3IgPSBuZXcgaW1wb3J0X3Bha28uSW5mbGF0ZSgpOwogICAgICAgICh7IHN0cm0gfSA9IGluZmxhdG9yKTsKICAgICAgICBpbmZsYXRvci5wdXNoKHJlbWFpbmluZ0lucHV0LCBpbXBvcnRfcGFrby5aX1NZTkNfRkxVU0gpOwogICAgICAgIGlmIChpbmZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IG5ldyBFcnJvcihpbmZsYXRvci5tc2cpOwogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIyID0gaW5mbGF0b3IucmVzdWx0OwogICAgICAgIGNodW5rcy5wdXNoKGJ1ZmZlcjIpOwogICAgICAgIGxldCBsZW4gPSBidWZmZXIyLmxlbmd0aDsKICAgICAgICBjcG9zaXRpb25zLnB1c2goY3Bvcyk7CiAgICAgICAgZHBvc2l0aW9ucy5wdXNoKGRwb3MpOwogICAgICAgIGlmIChjaHVua3MubGVuZ3RoID09PSAxICYmIG1pbnYuZGF0YVBvc2l0aW9uKSB7CiAgICAgICAgICBjaHVua3NbMF0gPSBjaHVua3NbMF0uc3ViYXJyYXkobWludi5kYXRhUG9zaXRpb24pOwogICAgICAgICAgbGVuID0gY2h1bmtzWzBdLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgY29uc3Qgb3JpZ0Nwb3MgPSBjcG9zOwogICAgICAgIGNwb3MgKz0gc3RybS5uZXh0X2luOwogICAgICAgIGRwb3MgKz0gbGVuOwogICAgICAgIGlmIChv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dGVzLnJlYWRJbnQzMkxFKGN1cnJPZmZzZXQpOwogICAgICAgIGN1cnJPZmZzZXQgKz0gNDsKICAgICAgICBjb25zdCBiaW5JbmRleCA9IHt9OwogICAgICAgIGxldCBzdGF0czsKICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IGJpbkNvdW50OyBqICs9IDEpIHsKICAgICAgICAgIGNvbnN0IGJpbiA9IGJ5dGVzLnJlYWRVSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgIGN1cnJPZmZzZXQgKz0gNDsKICAgICAgICAgIGlmIChiaW4gPiBtYXhCaW5OdW1iZXIgKyAxKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcigidGFiaXggaW5kZXggY29udGFpbnMgdG9vIG1hbnkgYmlucywgcGxlYXNlIHVzZSBhIENTSSBpbmRleCIpOwogICAgICAgICAgfSBlbHNlIGlmIChiaW4gPT09IG1heEJpbk51bWJlciArIDEpIHsKICAgICAgICAgICAgY29uc3QgY2h1bmtDb3VudCA9IGJ5dGVzLnJlYWRJbnQzMkxFKGN1cnJPZmZzZXQpOwogICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDQ7CiAgICAgICAgICAgIGlmIChjaHVua0NvdW50ID09PSAyKSB7CiAgICAgICAgICAgICAgc3RhdHMgPSB0aGlzLnBhcnNlUHNldWRvQmluKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDE2ICogY2h1bmtDb3VudDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGNvbnN0IGNodW5rQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgICAgICBjb25zdCBjaHVua3MgPSBuZXcgQXJyYXkoY2h1bmtDb3VudCk7CiAgICAgICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgY2h1bmtDb3VudDsgayArPSAxKSB7CiAgICAgICAgICAgICAgY29uc3QgdSA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCk7CiAgICAgICAgICAgICAgY29uc3QgdiA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCArIDgpOwogICAgICAgICAgICAgIGN1cnJPZmZzZXQgKz0gMTY7CiAgICAgICAgICAgICAgZmlyc3REYXRhTGluZSA9IHRoaXMuX2ZpbmRGaXJzdERhdGEoZmlyc3REYXRhTGluZSwgdSk7CiAgICAgICAgICAgICAgY2h1bmtzW2tdID0gbmV3IENodW5rKHUsIHYsIGJpbik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYmluSW5kZXhbYmluXSA9IGNodW5rczsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY29uc3QgbGluZWFyQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICBjdXJyT2Zmc2V0ICs9IDQ7CiAgICAgICAgY29uc3QgbGluZWFySW5kZXggPSBuZXcgQXJyYXkobGluZWFyQ291bnQpOwogICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgbGluZWFyQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgbGluZWFySW5kZXhba10gPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgY3Vyck9mZnNldCArPSA4OwogICAgICAgICAgZmlyc3REYXRhTGluZSA9IHRoaXMuX2ZpbmRGaXJzdERhdGEoZmlyc3REYXRhTGluZSwgbGluZWFySW5kZXhba10pOwogICAgICAgIH0KICAgICAgICByZXR1cm4geyBiaW5JbmRleCwgbGluZWFySW5kZXgsIHN0YXRzIH07CiAgICAgIH0pOwogICAgICByZXR1cm4gewogICAgICAgIGluZGljZXMsCiAgICAgICAgbWV0YUNoYXIsCiAgICAgICAgbWF4QmluTnVtYmVyLAogICAgICAgIG1heFJlZkxlbmd0aCwKICAgICAgICBza2lwT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UmVmSWQ7CiAgICAgICAgICB9CiAgICAgICAgICBjdXJyTmFtZVN0YXJ0ID0gaSArIDE7CiAgICAgICAgICBjdXJyUmVmSWQgKz0gMTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIHsgcmVmTmFtZVRvSWQsIHJlZklkVG9OYW1lIH07CiAgICB9CiAgICBhc3luYyBibG9ja3NGb3JSYW5nZShyZWZOYW1lLCBtaW4sIG1heCwgb3B0cyA9IHt9KSB7CiAgICAgIGlmIChtaW4gPCAwKSB7CiAgICAgICAgbWluID0gMDsKICAgICAgfQogICAgICBjb25zdCBpbmRleERhdGEgPSBhd2FpdCB0aGlzLnBhcnNlKG9wdHMpOwogICAgICBpZiAoIWluZGV4RGF0YSkgewogICAgICAgIHJldHVybiBbXTsKICAgICAgfQogICAgICBjb25zdCByZWZJZCA9IGluZGV4RGF0YS5yZWZOYW1lVG9JZFtyZWZOYW1lXTsKICAgICAgY29uc3QgYmEgPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmICghYmEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3QgbWluT2Zmc2V0ID0gYmEubGluZWFySW5kZXgubGVuZ3RoID8gYmEubGluZWFySW5kZXhbbWluID4+IFRBRF9MSURYX1NISUZUID49IGJhLmxpbmVhckluZGV4Lmxlbmd0aCA/IGJhLmxpbmVhckluZGV4Lmxlbmd0aCAtIDEgOiBtaW4gPj4gVEFEX0xJRFhfU0hJRlRdIDogbmV3IFZpcnR1YWxPZmZzZXQoMCwgMCk7CiAgICAgIGlmICghbWluT2Zmc2V0KSB7CiAgICAgICAgY29uc29sZS53YXJuKCJxdWVyeWluZyBvdXRzaWRlIG9mIHBvc3NpYmxlIHRhYml4IHJhbmdlIik7CiAgICAgIH0KICAgICAgY29uc3Qgb3ZlcmxhcHBpbmdCaW5zID0gcmVnMmJpbnMobWluLCBtYXgpOwogICAgICBjb25zdCBjaHVua3MgPSBbXTsKICAgICAgZm9yIChjb25zdCBbc3RhcnQsIGVuZF0gb2Ygb3ZlcmxhcHBpbmdCaW5zKSB7CiAgICAgICAgZm9yIChsZXQgYmluID0gc3RhcnQ7IGJpbiA8PSBlbmQ7IGJpbisrKSB7CiAgICAgICAgICBpZiAoYmEuYmluSW5kZXhbYmluXSkgewogICAgICAgICAgICBjb25zdCBiaW5DaHVua3MgPSBiYS5iaW5JbmRleFtiaW5dOwogICAgICAgICAgICBmb3IgKGxldCBjID0gMDsgYyA8IGJpbkNodW5rcy5sZW5ndGg7ICsrYykgewogICAgICAgICAgICAgIGNodW5rcy5wdXNoKG5ldyBDaHVuayhiaW5DaHVua3NbY10ubWludiwgYmluQ2h1bmtzW2NdLm1heHYsIGJpbikpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGNvbnN0IG5pbnR2ID0gYmEubGluZWFySW5kZXgubGVuZ3RoOwogICAgICBsZXQgbG93ZXN0ID0gbnVsbDsKICAgICAgY29uc3QgbWluTGluID0gTWF0aC5taW4obWluID4+IDE0LCBuaW50diAtIDEpOwogICAgICBjb25zdCBtYXhMaW4gPSBNYXRoLm1pbihtYXggPj4gMTQsIG5pbnR2IC0gMSk7CiAgICAgIGZvciAobGV0IGkgPSBtaW5MaW47IGkgPD0gbWF4TGluOyArK2kpIHsKICAgICAgICBjb25zdCB2cCA9IGJhLmxpbmVhckluZGV4W2ldOwogICAgICAgIGlmICh2cCkgewogICAgICAgICAgaWYgKCFsb3dlc3QgfHwgdnAuY29tcGFyZVRvKGxvd2VzdCkgPCAwKSB7CiAgICAgICAgICAgIGxvd2VzdCA9IHZwOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gb3B0aW1pemVDaHVua3MoY2h1bmtzLCBsb3dlc3QpOwogICAgfQogIH07CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9AZ21vZCt0YWJpeEAxLjUuMTEvbm9kZV9tb2R1bGVz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DE2KSA6IHsKICAgICAgICByZWZJZFRvTmFtZTogW10sCiAgICAgICAgcmVmTmFtZVRvSWQ6IHt9LAogICAgICAgIG1ldGFDaGFyOiBudWxsLAogICAgICAgIGNvbHVtbk51bWJlcnM6IHsgcmVmOiAwLCBzdGFydDogMSwgZW5kOiAyIH0sCiAgICAgICAgY29vcmRpbmF0ZVR5cGU6ICJ6ZXJvLWJhc2VkLWhhbGYtb3BlbiIsCiAgICAgICAgZm9ybWF0OiAiZ2VuZXJpYyIKICAgICAgfTsKICAgICAgY29uc3QgcmVmQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRSgxNiArIGF1eExlbmd0aCk7CiAgICAgIGxldCBmaXJzdERhdGFMaW5lOwogICAgICBsZXQgY3Vyck9mZnNldCA9IDE2ICsgYXV4TGVuZ3RoICsgNDsKICAgICAgY29uc3QgaW5kaWNlcyA9IG5ldyBBcnJheShyZWZDb3VudCkuZmlsbCgwKS5tYXAoKCkgPT4gewogICAgICAgIGNvbnN0IGJpbkNvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgIGNvbnN0IGJpbkluZGV4ID0ge307CiAgICAgICAgbGV0IHN0YXRzOwogICAgICAgIGZvciAobGV0IGogPSAwOyBqIDwgYmluQ291bnQ7IGogKz0gMSkgewogICAgICAgICAgY29uc3QgYmluID0gYnl0ZXMucmVhZFVJbnQzMkxFKGN1cnJPZmZzZXQpOwogICAgICAgICAgaWYgKGJpbiA+IHRoaXMubWF4QmluTnVtYmVyKSB7CiAgICAgICAgICAgIHN0YXRzID0gdGhpcy5wYXJzZVBzZXVkb0JpbihieXRlcywgY3Vyck9mZnNldCArIDQpOwogICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDQgKyA4ICsgNCArIDE2ICsgMTY7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjb25zdCBsb2Zmc2V0ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0ICsgNCk7CiAgICAgICAgICAgIGZpcnN0RGF0YUxpbmUgPSB0aGlzLl9maW5kRmlyc3REYXRhKGZpcnN0RGF0YUxpbmUsIGxvZmZzZXQpOwogICAgICAgICAgICBjb25zdCBjaHVua0NvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCArIDEyKTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgY29uc3QgY2h1bmtzID0gbmV3IEFycmF5KGNodW5rQ291bnQpOwogICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGNodW5rQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgICAgIGNvbnN0IHUgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgICAgIGNvbnN0IHYgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQgKyA4KTsKICAgICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDE2OwogICAgICAgICAgICAgIGNodW5rc1trXSA9IG5ldyBDaHVuayh1LCB2LCBiaW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJpbkluZGV4W2Jpbl0gPSBjaHVua3M7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiB7IGJpbkluZGV4LCBzdGF0cyB9OwogICAgICB9KTsKICAgICAgcmV0dXJuIHsKICAgICAgICAuLi5hdXgsCiAgICAgICAgY3NpOiB0cnVlLAogICAgICAgIHJlZkNvdW50LAogICAgICAgIG1heEJsb2NrU2l6ZTogMSA8PCAxNiwKICAgICAgICBmaXJzdERhdGFMaW5lLAogICAgICAgIGNzaVZlcnNpb24sCiAgICAgICAgaW5kaWNlcywKICAgICAgICBkZXB0aDogdGhpcy5kZXB0aCwKICAgICAgICBtYXhCaW5OdW1iZXI6IHRoaXMubWF4QmluTnVtYmVyLAogICAgICAgIG1heFJlZkxlbmd0aAogICAg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aHVua3MubGVuZ3RoOyArK2MpIHsKICAgICAgICAgICAgICBjaHVua3MucHVzaChuZXcgQ2h1bmsoYmluQ2h1bmtzW2NdLm1pbnYsIGJpbkNodW5rc1tjXS5tYXh2LCBiaW4pKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gb3B0aW1pemVDaHVua3MoY2h1bmtzLCBuZXcgVmlydHVhbE9mZnNldCgwLCAwKSk7CiAgICB9CiAgICByZWcyYmlucyhiZWcsIGVuZCkgewogICAgICBiZWcgLT0gMTsKICAgICAgaWYgKGJlZyA8IDEpIHsKICAgICAgICBiZWcgPSAxOwogICAgICB9CiAgICAgIGlmIChlbmQgPiAyICoqIDUwKSB7CiAgICAgICAgZW5kID0gMiAqKiAzNDsKICAgICAgfQogICAgICBlbmQgLT0gMTsKICAgICAgbGV0IGwgPSAwOwogICAgICBsZXQgdCA9IDA7CiAgICAgIGxldCBzID0gdGhpcy5taW5TaGlmdCArIHRoaXMuZGVwdGggKiAzOwogICAgICBjb25zdCBiaW5zID0gW107CiAgICAgIGZvciAoOyBsIDw9IHRoaXMuZGVwdGg7IHMgLT0gMywgdCArPSBsc2hpZnQoMSwgbCAqIDMpLCBsICs9IDEpIHsKICAgICAgICBjb25zdCBiID0gdCArIHJzaGlmdChiZWcsIHMpOwogICAgICAgIGNvbnN0IGUgPSB0ICsgcnNoaWZ0KGVuZCwgcyk7CiAgICAgICAgaWYgKGUgLSBiICsgYmlucy5sZW5ndGggPiB0aGlzLm1heEJpbk51bWJlcikgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGBxdWVyeSAke2JlZ30tJHtlbmR9IGlzIHRvbyBsYXJnZSBmb3IgY3VycmVudCBiaW5uaW5nIHNjaGVtZSAoc2hpZnQgJHt0aGlzLm1pblNoaWZ0fSwgZGVwdGggJHt0aGlzLmRlcHRofSksIHRyeSBhIHNtYWxsZXIgcXVlcnkgb3IgYSBjb2Fyc2VyIGluZG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TsKICAgIH0KICAgIGNoZWNrTGluZShtZXRhZGF0YSwgcmVnaW9uUmVmTmFtZSwgcmVnaW9uU3RhcnQsIHJlZ2lvbkVuZCwgbGluZSkgewogICAgICBjb25zdCB7IGNvbHVtbk51bWJlcnMsIG1ldGFDaGFyLCBjb29yZGluYXRlVHlwZSwgZm9ybWF0IH0gPSBtZXRhZGF0YTsKICAgICAgaWYgKGxpbmUuY2hhckF0KDApID09PSBtZXRhQ2hhcikgewogICAgICAgIHJldHVybiB7IG92ZXJsYXBzOiBmYWxzZSB9OwogICAgICB9CiAgICAgIGxldCB7IHJlZiwgc3RhcnQsIGVuZCB9ID0gY29sdW1uTnVtYmVyczsKICAgICAgaWYgKCFyZWYpIHsKICAgICAgICByZWYgPSAwOwogICAgICB9CiAgICAgIGlmICghc3RhcnQpIHsKICAgICAgICBzdGFydCA9IDA7CiAgICAgIH0KICAgICAgaWYgKCFlbmQpIHsKICAgICAgICBlbmQgPSAwOwogICAgICB9CiAgICAgIGlmIChmb3JtYXQgPT09ICJWQ0YiKSB7CiAgICAgICAgZW5kID0gODsKICAgICAgfQogICAgICBjb25zdCBtYXhDb2x1bW4gPSBNYXRoLm1heChyZWYsIHN0YXJ0LCBlbmQpOwogICAgICBsZXQgY3VycmVudENvbHVtbk51bWJlciA9IDE7CiAgICAgIGxldCBjdXJyZW50Q29sdW1uU3RhcnQgPSAwOwogICAgICBsZXQgcmVmU2VxID0gIiI7CiAgICAgIGxldCBzdGFydENvb3JkaW5hdGUgPSAtSW5maW5pdHk7CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGluZS5sZW5ndGggKyAxOyBpICs9IDEpIHsKICAgICAgICBpZiAobGluZVtpXSA9PT0gIgkiIHx8IGkgPT09IGxpbmUubGVuZ3RoKSB7CiAgICAgICAgICBpZiAoY3VycmVudENvbHVtbk51bWJlciA9PT0gcmVmKSB7CiAgICAgICAgICAgIGlmICh0aGlzLnJlbmFtZVJlZlNlcShsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSkpICE9PSByZWdpb25SZWZOYW1lKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHsgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoY3VycmVudENvbHVtbk51bWJlciA9PT0gc3RhcnQpIHsKICAgICAgICAgICAgc3RhcnRDb29yZGluYXRlID0gcGFyc2VJbnQobGluZS5zbGljZShjdXJyZW50Q29sdW1uU3RhcnQsIGkpLCAxMCk7CiAgICAgICAgICAgIGlmIChjb29yZGluYXRlVHlwZSA9PT0gIjEtYmFzZWQtY2xvc2VkIikgewogICAgICAgICAgICAgIHN0YXJ0Q29vcmRpbmF0ZSAtPSAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzdGFydENvb3JkaW5hdGUgPj0gcmVnaW9uRW5kKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHsgc3RhcnRDb29yZGluYXRlLCBvdmVybGFwczogZmFsc2UgfTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoZW5kID09PSAwIHx8IGVuZCA9PT0gc3RhcnQpIHsKICAgICAgICAgICAgICBpZiAoc3RhcnRDb29yZGluYXRlICsgMSA8PSByZWdpb25TdGFydCkgewogICAgICAgICAgICAgICAgcmV0dXJuIHsgc3RhcnRDb29yZGluYXRlLCBvdmVybGFwczogZmFsc2UgfTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoZm9ybWF0ID09PSAiVkNGIiAmJiBjdXJyZW50Q29sdW1uTnVtYmVyID09PSA0KSB7CiAgICAgICAgICAgIHJlZlNlcSA9IGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKTsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VycmVudENvbHVtbk51bWJlciA9PT0gZW5kKSB7CiAgICAgICAgICAgIGxldCBlbmRDb29yZGluYXRlOwogICAgICAgICAgICBpZiAoZm9ybWF0ID09PSAiVkNGIikgewogICAgICAgICAgICAgIGVuZENvb3JkaW5hdGUgPSB0aGlzLl9nZXRWY2ZFbmQoc3RhcnRDb29yZGluYXRlLCByZWZTZXEsIGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKSk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgZW5kQ29vcmRpbmF0ZSA9IHBhcnNlSW50KGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKSwgMTApOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChlbmRDb29yZGluYXRlIDw9IHJlZ2lvblN0YXJ0KSB7CiAgICAgICAgICAgICAgcmV0dXJuIHsgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGN1cnJlbnRDb2x1bW5TdGFydCA9IGkgKyAxOwogICAgICAgICAgY3VycmVudENvbHVtbk51bWJlciArPSAxOwogICAgICAgICAgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPiBtYXhDb2x1bW4pIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIHJldHVybiB7IHN0YXJ0Q29vcmRpbmF0ZSwgb3ZlcmxhcHM6IHRydWUgfTsKICAgIH0KICAgIF9nZXRWY2ZFbmQoc3RhcnRDb29yZGluYXRlLCByZWZTZXEsIGluZm8pIHsKICAgICAgbGV0IGVuZENvb3JkaW5hdGUgPSBzdGFydENvb3JkaW5hdGUgKyByZWZTZXEubGVuZ3RoOwogICAgICBjb25zdCBpc1RSQSA9IGluZm8uaW5kZXhPZigiU1ZUWVBFPVRSQSIpICE9PSAtMTsKICAgICAgaWYgKGluZm9bMF0gIT09ICIuIiAmJiAhaXNUUkEpIHsKICAgICAgICBsZXQgcHJldkNoYXIgPSAiOyI7CiAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCBpbmZvLmxlbmd0aDsgaiArPSAxKSB7CiAgICAgICAgICBpZiAocHJldkNoYXIgPT09ICI7IiAmJiBpbmZvLnNsaWNlKGosIGogKyA0KSA9PT0gIkVORD0iKSB7CiAgICAgICAgICAgIGxldCB2YWx1ZUVuZCA9IGluZm8uaW5kZXhPZigiOyIsIGopOwogICAgICAgICAgICBpZiAodmFsdWVFbmQgPT09IC0xKSB7CiAgICAgICAgICAgICAgdmFsdWVFbmQgPSBpbmZvLmxlbmd0aDsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbmRDb29yZGluYXRlID0gcGFyc2VJbnQoaW5mby5zbGljZShqICsgNCwgdmFsdWVFbmQpLCAxMCk7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgcHJldkNoYXIgPSBpbmZvW2pdOwogICAgICAgIH0KICAgICAgfSBlbHNlIGlmIChpc1RSQSkgewogICAgICAgIHJldHVybiBzdGFydENvb3JkaW5hdGUgKyAxOwogICAgICB9CiAgICAgIHJldHVybiBlbmRDb29yZGluYXRlOwogICAgfQogICAgYXN5bmMgbGluZUNvdW50KHJlZk5hbWUsIG9wdHMgPSB7fSkgewogICAgICByZXR1cm4gdGhpcy5pbmRleC5saW5lQ291bnQocmVmTmFtZSwgb3B0cyk7CiAgICB9CiAgICBhc3luYyBfcmVhZFJlZ2lvbihwb3MsIHNpemUsIG9wdHMgPSB7fSkgewogICAgICBjb25zdCBiID0gaW1wb3J0X2J1ZmZlcjcuQnVmZmVyLmFsbG9jKHNpemUpOwogICAgICBjb25zdCB7IGJ5dGVzUmVhZCwgYnVmZmVyIH0gPSBhd2FpdCB0aGlzLmZpbGVoYW5kbGUucmVhZChiLCAwLCBzaXplLCBwb3MsIG9wdHMpOwogICAgICByZXR1cm4gYnVmZmVyLnNsaWNlKDAsIGJ5dGVzUmVhZCk7CiAgICB9CiAgICBhc3luYyByZWFkQ2h1bmsoYywgb3B0cyA9IHt9KSB7CiAgICAgIGNvbnN0IGRh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PSBudWxsKQogICAgICAgIGhpID0gYS5sZW5ndGg7CiAgICAgIHdoaWxlIChsbyA8IGhpKSB7CiAgICAgICAgY29uc3QgbWlkID0gbG8gKyBoaSA+Pj4gMTsKICAgICAgICBpZiAoY29tcGFyZShhW21pZF0sIHgpID4gMCkKICAgICAgICAgIGhpID0gbWlkOwogICAgICAgIGVsc2UKICAgICAgICAgIGxvID0gbWlkICsgMTsKICAgICAgfQogICAgICByZXR1cm4gbG87CiAgICB9CiAgICBmdW5jdGlvbiBjZW50ZXIoYSwgeCwgbG8sIGhpKSB7CiAgICAgIGlmIChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgY29uc3QgaSA9IGxlZnQoYSwgeCwgbG8sIGhpIC0gMSk7CiAgICAgIHJldHVybiBpID4gbG8gJiYgZGVsdGEoYVtpIC0gMV0sIHgpID4gLWRlbHRhKGFbaV0sIHgpID8gaSAtIDEgOiBpOwogICAgfQogICAgcmV0dXJuIHsgbGVmdCwgY2VudGVyLCByaWdodCB9OwogIH0KICBmdW5jdGlvbiBhc2NlbmRpbmdDb21wYXJhdG9yKGYpIHsKICAgIHJldHVybiAoZCwgeCkgPT4gYXNjZW5kaW5nX2RlZmF1bHQoZihkKSwgeCk7CiAgfQoKICAvLyBzcmMvZGF0YS1mZXRjaGVycy91dGlscy50cwogIHZhciBEYXRhU291cmNlID0gY2xhc3MgewogICAgY29uc3RydWN0b3IoZmlsZSwgY2hyb21TaXplcywgb3B0aW9ucykgewogICAgICB0aGlzLmZpbGUgPSBmaWxlOwogICAgICB0aGlzLm9wdGlvbnMgPSBvcHRpb25zOwogICAgICB0aGlzLmNocm9tSW5mbyA9IHNpemVzVG9DaHJvbUluZm8oY2hyb21TaXplcyk7CiAgICAgIHRoaXMudGlsZXNldEluZm8gPSB0aWxlc2V0SW5mb0Zyb21DaHJvbUluZm8odGhpcy5jaHJvbUluZ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2b2lkIDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoY29sdW1uVmFsICE9PSAiLiIpIHsKICAgICAgICAgICAgaWYgKGlzTnVtZXJpYykgewogICAgICAgICAgICAgIGNvbnN0IG51bSA9IE51bWJlcihjb2x1bW5WYWwpOwogICAgICAgICAgICAgIGNvbHVtblZhbCA9IE51bWJlci5pc05hTihudW0pID8gY29sdW1uVmFsIDogbnVtOwogICAgICAgICAgICB9IGVsc2UgaWYgKGlzQXJyYXkyKSB7CiAgICAgICAgICAgICAgY29sdW1uVmFsID0gY29sdW1uVmFsLnNwbGl0KCIsIik7CiAgICAgICAgICAgICAgaWYgKGNvbHVtblZhbFtjb2x1bW5WYWwubGVuZ3RoIC0gMV0gPT09ICIiKSB7CiAgICAgICAgICAgICAgICBjb2x1bW5WYWwucG9wKCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChhcnJheUlzTnVtZXJpYykgewogICAgICAgICAgICAgICAgY29sdW1uVmFsID0gY29sdW1uVmFsLm1hcCgoc3RyKSA9PiBOdW1iZXIoc3RyKSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGZlYXR1cmVbbmFtZV0gPSBjb2x1bW5WYWw7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9IGVsc2UgewogICAgICAgIGNvbnN0IGZpZWxkTmFtZXMgPSBbImNocm9tIiwgImNocm9tU3RhcnQiLCAiY2hyb21FbmQiLCAibmFtZSJdOwogICAgICAgIGZlYXR1cmUgPSBPYmplY3QuZnJvbUVudHJpZXMoZmllbGRzLm1hcCgoZiwgaSkgPT4gW2ZpZWxkTmFtZXNbaV0gfHwgImZpZWxkIiArIGksIGZdKSk7CiAgICAgICAgZmVhdHVyZS5jaHJvbVN0YXJ0ID0gK2ZlYXR1cmUuY2hyb21TdGFydDsKICAgICAgICBmZWF0dXJlLmNocm9tRW5kID0gK2ZlYXR1cmUuY2h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BiZWRSZWNvcmQ7CiAgICB9CiAgICBjb25zdHJ1Y3RCZWRBdXRvU3FsKCkgewogICAgICBjb25zdCBBVVRPX1NRTF9IRUFERVIgPSBgdGFibGUgY3VzdG9tQmVkU2NoZW1hCiJCRUQxMiIKICAgICgKYDsKICAgICAgY29uc3QgQVVUT19TUUxfRk9PVEVSID0gIlxuICAgICkiOwogICAgICBjb25zdCBhdXRvU3FsRmllbGRzID0gdGhpcy4jZ2VuZXJhdGVBdXRvU1FMRmllbGRzKCk7CiAgICAgIHJldHVybiBTdHJpbmcucHJvdG90eXBlLmNvbmNhdChBVVRPX1NRTF9IRUFERVIsIGF1dG9TcWxGaWVsZHMsIEFVVE9fU1FMX0ZPT1RFUik7CiAgICB9CiAgICAjZ2VuZXJhdGVBdXRvU1FMRmllbGRzKCkgewogICAgICBjb25zdCBCRUQxMkZpZWxkcyA9IFsKICAgICAgICBbInN0cmluZyIsICJjaHJvbSJdLAogICAgICAgIFsidWludCIsICJjaHJvbVN0YXJ0Il0sCiAgICAgICAgWyJ1aW50IiwgImNocm9tRW5kIl0sCiAgICAgICAgWyJzdHJpbmciLCAibmFtZSJdLAogICAgICAgIFsiZmxvYXQiLCAic2NvcmUiXSwKICAgICAgICBbImNoYXIiLCAic3RyYW5kIl0sCiAgICAgICAgWyJ1aW50IiwgInRoaWNrU3RhcnQiXSwKICAgICAgICBbInVpbnQiLCAidGhpY2tFbmQiXSwKICAgICAgICBbInN0cmluZyIsICJpdGVtUmdiIl0sCiAgICAgICAgWyJ1aW50IiwgImJsb2NrQ291bnQiXSwKICAgICAgICBbInVpbnRbYmxvY2tDb3VudF0iLCAiYmxvY2tTaXplcyJdLAogICAgICAgIFsidWludFtibG9ja0NvdW50XSIsICJibG9ja1N0YXJ0cyJdCiAgICAgIF07CiAgICAgIGlmICghdGhpcy4jbl9jb2x1bW5zKQogICAgICAgIHRocm93IG5ldyBFcnJvcigiTnVtYmVyIG9mIGNvbHVtbnMgd2FzIG5vdCBhYmxlIHR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tTmFtZSA9IGN1bVBvcy5jaHI7CiAgICAgICAgY29uc3QgY2hyb21TdGFydCA9IGN1bVBvcy5wb3M7CiAgICAgICAgY29uc3QgY2hyb21FbmQgPSBjdW1Qb3MucG9zICsgY2hyb21MZW5ndGhzW2Nocm9tTmFtZV07CiAgICAgICAgbl9jb2xzID0gYXdhaXQgbmV3IFByb21pc2UoKHJlc29sdmUpID0+IHsKICAgICAgICAgIHNvdXJjZS5maWxlLnRiaS5nZXRMaW5lcyhjaHJvbU5hbWUsIGNocm9tU3RhcnQsIGNocm9tRW5kLCAobGluZSkgPT4gewogICAgICAgICAgICByZXNvbHZlKGxpbmUuc3BsaXQoIgkiKS5sZW5ndGgpOwogICAgICAgICAgfSk7CiAgICAgICAgfSk7CiAgICAgICAgaWYgKG5fY29scyA+IDApCiAgICAgICAgICBicmVhazsKICAgICAgfQogICAgICByZXR1cm4gbl9jb2xzOwogICAgfQogICAgYXN5bmMgZ2V0VGlsZURhdGEobWluWCwgbWF4WCkgewogICAgICBjb25zdCBzb3VyY2UgPSBkYXRhU291cmNlcy5nZXQodGhpcy4jdWlkKTsKICAgICAgY29uc3QgcGFyc2VyMiA9IGF3YWl0IHRoaXMuZ2V0UGFyc2VyKCk7CiAgICAgIGxldCBjdXJNaW5YID0gbWluWDsKICAgICAgY29uc3QgeyBjaHJvbUxlbmd0aHMsIGN1bVBvc2l0aW9ucyB9ID0gc291cmNlLmNocm9tSW5mbzsKICAgICAgY29uc3QgYWxsVGlsZXMgPSBbXTsKICAgICAgZm9yIChjb25zdCBjdW1Qb3Mgb2YgY3VtUG9zaXRpb25zKSB7CiAgICAgICAgY29uc3QgY2hyb21OYW1lID0gY3VtUG9zLmNocjsKICAgICAgICBjb25zdCBjaHJvbVN0YXJ0ID0gY3VtUG9zLnBvczsKICAgICAgICBjb25zdCBjaHJvbUVuZCA9IGN1bVBvcy5wb3MgKyBjaHJvbUxlbmd0aHNbY2hyb21OYW1lXTsKICAgICAgICBsZXQgc3RhcnRQb3MsIGVuZFBvczsKICAgICAgICBpZiAoY2hyb21TdGFydCA+IGN1ck1pblggfHwgY3VyTWluWCA+PSBjaHJvbUVuZCkgewogICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIGNvbnN0IHRpbGVzUHJvbWlzZSA9IG5ldyBQcm9taXNlKChyZXNvbHZlKSA9PiB7CiAgICAgICAgICBjb25zdCB0aWxlcyA9IFtdOwogICAgICAgICAgY29uc3QgbGluZUNhbGxiYWNrID0gKGxpbmUpID0+IHsKICAgICAgICAgICAgY29uc3QgYmVkVGlsZSA9IHBhcnNlcjIucGFyc2VMaW5lKGxpbmUsIGNocm9tU3RhcnQpOwogICAgICAgICAgICB0aWxlcy5wdXNoKGJlZFRpbGUpOwogICAgICAgICAgfTsKICAgICAgICAgIGlmIChtYXhYID4gY2hyb21FbmQpIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBjdXJNaW5YIC0gY2hyb21TdGFydDsKICAgICAgICAgICAgZW5kUG9zID0gY2hyb21FbmQgLSBjaHJvbVN0YXJ0OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBNYXRoLmZsb29yKGN1ck1pblggLSBjaHJvbVN0YXJ0KTsKICAgICAgICAgICAgZW5kUG9zID0gTWF0aC5jZWlsKG1heFggLSBjaHJvbVN0YXJ0KTsKICAgICAgICAgIH0KICAgICAgICAgIHNvdXJjZS5maWxlLnRiaS5nZXRMaW5lcyhjaHJvbU5hbWUsIHN0YXJ0UG9zLCBlbmRQb3MsIGxpbmVDYWxsYmFjaykudGhlbigoKSA9PiB7CiAgICAgICAgICAgIHJlc29sdmUodGlsZXMpOwogICAgICAgICAgfSk7CiAgICAgICAgfSk7CiAgICAgICAgYWxsVGlsZXMucHVzaCh0aWxlc1Byb21pc2UpOwogICAgICAgIGlmIChtYXhYIDw9IGNocm9tRW5kKSB7CiAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CiAgICAgICAgY3VyTWluWCA9IGN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vbG9kYXNoLmNvbS9saWNlbnNlPgogKiBCYXNlZCBvbiBVbmRlcnNjb3JlLmpzIDEuOC4zIDxodHRwOi8vdW5kZXJzY29yZWpzLm9yZy9MSUNFTlNFPgogKiBDb3B5cmlnaHQgSmVyZW15IEFzaGtlbmFzLCBEb2N1bWVudENsb3VkIGFuZCBJbnZlc3RpZ2F0aXZlIFJlcG9ydGVycyAmIEVkaXRvcnMKICovCg==",qle=typeof window<"u"&&window.Blob&&new Blob([atob(z2e)],{type:"text/javascript;charset=utf-8"});function eng(){const e=qle&&(window.URL||window.webkitURL).createObjectURL(qle);try{return e?new Worker(e):new Worker("data:application/javascript;base64,"+z2e,{type:"module"})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const tng=200;class P2e{constructor(g,I){rt(this,"dataConfig",{}),rt(this,"uid"),rt(this,"prevRequestTime"),rt(this,"track"),rt(this,"toFetch"),rt(this,"fetchTimeout"),rt(this,"worker"),this.uid=g.libraries.slugid.nice(),this.prevRequestTime=0,this.toFetch=new Set;const{url:i,indexUrl:n,assembly:C,...r}=I;this.worker=JT(new eng).then(async o=>{const a=Object.entries(bI(C).size);return await o.init(this.uid,{url:i,indexUrl:n},a,r),o})}async tilesetInfo(g){(await this.worker).tilesetInfo(this.uid).then(g)}fetchTilesDebounced(g,I){this.track.drawLoadingCue(),I.forEach(i=>this.toFetch.add(i)),this.fetchTimeout&&clearTimeout(this.fetchTimeout),this.fetchTimeout=setTimeout(()=>{this.sendFetch(g,[...this.toFetch]),this.toFetch.clear()},tng)}async sendFetch(g,I){(await this.worker).fetchTilesDebounced(this.uid,I).then(g)}async getTabularData(g){const I=await(await this.worker).getTabularData(this.uid,g);return JSON.parse(new TextDecoder().decode(I))}}rt(P2e,"config",{type:"bed"});const gng=Object.freeze(Object.defineProperty({__proto__:null,BamDataFetcher:BH,BedDataFetcher:P2e,BigWigDataFetcher:K2e,CsvDataFetcher:D2e,GffDataFetcher:M2e,JsonDataFetcher:F2e,VcfDataFetcher:s2e},Symbol.toStringTag,{value:"Module"})),Ing="gosling-data-row-uid";function ing(e,g){var I,i,n,C,r,o,a,s,A,l,c,u,d,h,m,f;const b=[];if(!i7(e.data)){console.warn("No data is specified");return}if(e.data.type==="vector"||e.data.type==="bigwig"){if(!("dense"in g))return;const p=(I=e.data.binSize)!=null?I:1,y=g.dense,Z=g.tileSize,B=g.tileWidth/g.tileSize,G=(i=e.data.value)!=null?i:"value",v=(n=e.data.column)!=null?n:"position",w=(C=e.data.start)!=null?C:"start",V=(r=e.data.end)!=null?r:"end",S=`${G}_min`,X=`${G}_max`,W=(o=e.data.aggregation)!=null?o:"mean";let R=0,H=Number.MAX_SAFE_INTEGER,Y=Number.MIN_SAFE_INTEGER,K=Number.MIN_SAFE_INTEGER,F=Number.MAX_SAFE_INTEGER;Array.from(Array(Z).keys()).forEach((J,P)=>{if(p===1){const ge=y[P]/(W==="mean"?B:1);b.push({[G]:ge,[v]:g.tileX+(P+.5)*B,[w]:g.tileX+P*B,[V]:g.tileX+(P+1)*B,[S]:ge,[X]:ge})}else if(P%p===0)R=H=Y=y[P],K=P,F=P+p;else if(P%p===p-1)b.push({[G]:R/p/(W==="mean"?B:1),[v]:g.tileX+(K+p/2)*B,[w]:g.tileX+K*B,[V]:g.tileX+F*B,[S]:H,[X]:Y});else if(P===Z-1){const ge=Z%p,q=K+ge;b.push({[G]:R/ge/(W==="mean"?B:1),[v]:g.tileX+(K+ge/2)*B,[w]:g.tileX+K*B,[V]:g.tileX+q*B,[S]:H,[X]:Y})}else R+=y[P],H>y[P]&&(H=y[P]),Y{let J=0,P=Number.MIN_SAFE_INTEGER,ge=Number.MAX_SAFE_INTEGER,q=Number.MAX_SAFE_INTEGER,$=Number.MIN_SAFE_INTEGER;Array.from(Array(G).keys()).forEach((j,te)=>{if(p===1){const Q=B[G*F+te]/(Y==="mean"?v:1);b.push({[w]:K,[V]:Q,[S]:g.tileX+(te+.5)*v,[X]:g.tileX+te*v,[W]:g.tileX+(te+1)*v,[R]:Q,[H]:Q})}else if(te%p===0)J=q=$=B[G*F+te],P=te,ge=te+p;else if(te%p===p-1)b.push({[w]:K,[V]:Y==="mean"?J/p/v:J,[S]:g.tileX+(P+p/2)*v,[X]:g.tileX+P*v,[W]:g.tileX+ge*v,[R]:q,[H]:$});else if(te===G-1){const Q=G%p,ie=P+Q;b.push({[w]:K,[V]:Y==="mean"?J/Q/v:J,[S]:g.tileX+(P+Q/2)*v,[X]:g.tileX+P*v,[W]:g.tileX+ie*v,[R]:q,[H]:$})}else{const Q=B[G*F+te];J+=Q,q>Q&&(q=Q),$"u"||typeof g.tileHeight>"u")return;const p=Math.sqrt(g.dense.length),{tileX:y,tileY:Z,tileWidth:B,tileHeight:G}=g,v=g.dense,w=B/p,V=G/p,S=(m=e.data.column)!=null?m:"x",X=(f=e.data.row)!=null?f:"y",W=16;for(let R=0;R{const{chrOffset:v,fields:w}=B,V={};if(V[Ing]=`${G}`,p.forEach(S=>{V[S.name]=+w[S.index]+v}),Z==null||Z.forEach(S=>{V[S.name]=S.type==="quantitative"?+w[S.index]:w[S.index]}),b.push({...V,type:"gene"}),y){const[S,X]=y,W=w[S.index].split(","),R=w[X.index].split(",");W.forEach((H,Y)=>{const K=R[Y];if(b.push({...V,[S.name]:+H+v,[X.name]:+K+v,type:"exon"}),Y+1n===e.chromosome))){if(m4e(e))return[I[e.chromosome][0]+1,I[e.chromosome][1]];if(f4e(e))return e.interval;if(p4e(e)){const i=I[e.chromosome][0],[n,C]=e.interval;return[i+n,i+C]}}}function ang(e,g){const I={},i=Hd;e.forEach(n=>{i.forEach(C=>{const r=n.spec()[C];if(!ut(r)||r.domain===void 0)return;const{domain:o,type:a}=r;if(a==="quantitative"){const s=Array.from(o);if(!I[C])I[C]=s;else{const A=I[C];A[0]>s[0]&&(A[0]=s[0]),A[1]{i.forEach(C=>{const r=n.spec()[C];ut(r)&&r.type==="genomic"||(n.setChannelDomain(C,I[C],g),n.generateScales())}),n.updateChannelValue()})}const Ang={compactLayout:!1,trackSourceServers:["https://server.gosling-lang.org/api/v1/"],views:[{genomePositionSearchBoxVisible:!1,genomePositionSearchBox:{autocompleteServer:"https://higlass.io/api/v1",autocompleteId:"P0PLbQMwTYGy-5uPIQid7A",chromInfoServer:"https://higlass.io/api/v1",chromInfoId:"hg38"},layout:{x:0,y:0,w:6.4,h:600},tracks:{top:[],left:[{type:"combined",width:130,height:600,contents:[{type:"gosling-track",server:"https://server.gosling-lang.org/api/v1/",tilesetUid:"cistrome-multivec",width:130,height:600,options:{showMousePosition:!0,mousePositionColor:"#000000",fontSize:24,labelPosition:"none",labelShowResolution:!1,labelColor:"black",labelBackgroundColor:"white",labelTextOpacity:1,labelLeftMargin:1,labelTopMargin:1,labelRightMargin:0,labelBottomMargin:0,backgroundColor:"transparent",spec:{spacing:10,orientation:"vertical",assembly:"hg38",layout:"linear",static:!1,xDomain:{interval:[0,1e9]},centerRadius:.3,xOffset:0,yOffset:0,style:{outlineWidth:.5},data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"],binSize:4},mark:"rect",x:{field:"start",type:"genomic",axis:"left",domain:{interval:[0,1e9]},linkingId:"7f94b74e-25ec-4e67-8c75-3dc0f1b0d6bd"},xe:{field:"end",type:"genomic"},row:{field:"sample",type:"nominal",legend:!0},color:{field:"peak",type:"quantitative",legend:!0},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:160,height:600,overlayOnPreviousTrack:!1},theme:{base:"light",root:{background:"white",titleColor:"black",titleBackgroundColor:"transparent",titleFontSize:18,titleFontFamily:"Arial",titleAlign:"left",titleFontWeight:"bold",subtitleColor:"gray",subtitleBackgroundColor:"transparent",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleFontWeight:"normal",subtitleAlign:"left",mousePositionColor:"#000000"},track:{background:"transparent",alternatingBackground:"transparent",titleColor:"black",titleBackground:"white",titleFontSize:24,titleAlign:"left",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"#DBDBDB",tickColor:"black"},axis:{tickColor:"black",labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",baselineColor:"black",gridColor:"#E3E3E3",gridStrokeWidth:1,gridStrokeType:"solid",gridStrokeDash:[4,4]},markCommon:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},point:{color:"#E79F00",size:3,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rect:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},triangle:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},area:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},line:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},bar:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rule:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},link:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},text:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6],textAnchor:"middle",textFontWeight:"normal"},brush:{color:"gray",size:1,stroke:"black",strokeWidth:1,opacity:.3,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]}}}}]},{uid:"15483511-f6fb-11eb-914b-976b6ecda162",type:"axis-track",chromInfoPath:"https://s3.amazonaws.com/gosling-lang.org/data/hg38.chrom.sizes",options:{layout:"linear",outerRadius:null,width:160,height:600,theme:{base:"light",root:{background:"white",titleColor:"black",titleBackgroundColor:"transparent",titleFontSize:18,titleFontFamily:"Arial",titleAlign:"left",titleFontWeight:"bold",subtitleColor:"gray",subtitleBackgroundColor:"transparent",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleFontWeight:"normal",subtitleAlign:"left",mousePositionColor:"#000000"},track:{background:"transparent",alternatingBackground:"transparent",titleColor:"black",titleBackground:"white",titleFontSize:24,titleAlign:"left",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"#DBDBDB",tickColor:"black"},axis:{tickColor:"black",labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",baselineColor:"black",gridColor:"#E3E3E3",gridStrokeWidth:1,gridStrokeType:"solid",gridStrokeDash:[4,4]},markCommon:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},point:{color:"#E79F00",size:3,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rect:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},triangle:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},area:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},line:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},bar:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rule:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},link:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},text:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6],textAnchor:"middle",textFontWeight:"normal"},brush:{color:"gray",size:1,stroke:"black",strokeWidth:1,opacity:.3,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]}},assembly:"hg38",stroke:"transparent",color:"black",fontSize:12,fontFamily:"Arial",fontWeight:"normal",tickColor:"black",tickFormat:"plain",tickPositions:"even",reverseOrientation:!1},width:30}],center:[],right:[],bottom:[],gallery:[],whole:[]},initialXDomain:[0,1e9],initialYDomain:[0,1e9],zoomFixed:!1,zoomLimits:[1,null],uid:"15483510-f6fb-11eb-914b-976b6ecda162",chromInfoPath:"https://s3.amazonaws.com/gosling-lang.org/data/hg38.chrom.sizes"},{genomePositionSearchBoxVisible:!1,genomePositionSearchBox:{autocompleteServer:"https://higlass.io/api/v1",autocompleteId:"P0PLbQMwTYGy-5uPIQid7A",chromInfoServer:"https://higlass.io/api/v1",chromInfoId:"hg38"},layout:{x:6.8,y:0,w:5.2,h:600},tracks:{top:[],left:[{type:"combined",width:130,height:600,contents:[{type:"gosling-track",server:"https://server.gosling-lang.org/api/v1/",tilesetUid:"cistrome-multivec",width:130,height:600,options:{showMousePosition:!0,mousePositionColor:"#000000",fontSize:24,labelPosition:"none",labelShowResolution:!1,labelColor:"black",labelBackgroundColor:"white",labelTextOpacity:1,labelLeftMargin:1,labelTopMargin:1,labelRightMargin:0,labelBottomMargin:0,backgroundColor:"transparent",spec:{spacing:10,orientation:"vertical",assembly:"hg38",layout:"linear",static:!1,xDomain:{interval:[0,1e9]},centerRadius:.3,xOffset:0,yOffset:0,style:{outlineWidth:.5},data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"],binSize:4},mark:"rect",x:{field:"start",type:"genomic",domain:{interval:[0,1e9]},linkingId:"7f94b74e-25ec-4e67-8c75-3dc0f1b0d6bd"},xe:{field:"end",type:"genomic"},row:{field:"sample",type:"nominal",legend:!0},color:{field:"peak",type:"quantitative",legend:!0},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:130,height:600},theme:{base:"light",root:{background:"white",titleColor:"black",titleBackgroundColor:"transparent",titleFontSize:18,titleFontFamily:"Arial",titleAlign:"left",titleFontWeight:"bold",subtitleColor:"gray",subtitleBackgroundColor:"transparent",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleFontWeight:"normal",subtitleAlign:"left",mousePositionColor:"#000000"},track:{background:"transparent",alternatingBackground:"transparent",titleColor:"black",titleBackground:"white",titleFontSize:24,titleAlign:"left",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"#DBDBDB",tickColor:"black"},axis:{tickColor:"black",labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",baselineColor:"black",gridColor:"#E3E3E3",gridStrokeWidth:1,gridStrokeType:"solid",gridStrokeDash:[4,4]},markCommon:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},point:{color:"#E79F00",size:3,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rect:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},triangle:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},area:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},line:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},bar:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rule:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},link:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},text:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6],textAnchor:"middle",textFontWeight:"normal"},brush:{color:"gray",size:1,stroke:"black",strokeWidth:1,opacity:.3,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]}}}}]}],center:[],right:[],bottom:[],gallery:[],whole:[]},initialXDomain:[0,1e9],initialYDomain:[0,1e9],zoomFixed:!1,zoomLimits:[1,null],uid:"154b1b40-f6fb-11eb-914b-976b6ecda162"}],zoomLocks:{locksByViewUid:{},locksDict:{}},locationLocks:{locksByViewUid:{},locksDict:{}},editable:!1,chromInfoPath:"https://s3.amazonaws.com/gosling-lang.org/data/hg38.chrom.sizes"},Qr=30,sng=e=>({genomePositionSearchBoxVisible:!1,genomePositionSearchBox:{autocompleteServer:"https://higlass.io/api/v1",autocompleteId:C6e(e),chromInfoServer:"https://higlass.io/api/v1",chromInfoId:e??"hg38"},layout:{w:12,h:12,x:0,y:0},tracks:{top:[],left:[],center:[],right:[],bottom:[],gallery:[],whole:[]},initialXDomain:[0,bI(e).total],initialYDomain:[0,bI(e).total],zoomFixed:!1});class lng{constructor(){rt(this,"assembly"),rt(this,"orientation"),rt(this,"hg"),this.assembly="hg38",this.hg={compactLayout:!1,trackSourceServers:[],views:[],zoomLocks:{locksByViewUid:{},locksDict:{}},locationLocks:{locksByViewUid:{},locksDict:{}}},this.setEditable(!1)}spec(){return this.hg}setViewOrientation(g){return this.orientation=g,this}addDefaultView(g,I){return this.hg.views.push(JSON.parse(JSON.stringify({...sng(I),uid:g}))),this}setAssembly(g){return this.assembly=g,this.setChromInfoPath(bI(this.assembly).path),this}getAssembly(){return this.assembly}setTextTrack(g,I,i,n="black",C=14,r="normal",o="left",a="transparent",s="Arial"){var A;return this.getLastView()&&((A=this.getLastView().tracks.top)==null||A.push({type:"text",width:g,height:I,options:{backgroundColor:a,textColor:n,fontSize:C,fontWeight:r,fontFamily:s,offsetY:0,align:o,text:i}})),this}setDummyTrack(g){var I;return this.getLastView()&&((I=this.getLastView().tracks.top)==null||I.push({type:"dummy-track",width:g.width,height:g.height,options:{width:g.width,height:g.height,title:g.title,...g.style}})),this}addBrush(g,I,i,n,C){var r,o,a,s,A,l;if(n)return(l=this.getView(I))==null||l.tracks.whole.push({type:g==="circular"?"brush-track":"viewport-projection-horizontal",uid:ln(),fromViewUid:n,options:{projectionFillColor:(r=C==null?void 0:C.color)!=null?r:i.brush.color,projectionStrokeColor:(o=C==null?void 0:C.stroke)!=null?o:i.brush.stroke,projectionFillOpacity:(a=C==null?void 0:C.opacity)!=null?a:i.brush.opacity,projectionStrokeOpacity:(s=C==null?void 0:C.opacity)!=null?s:i.brush.opacity,strokeWidth:(A=C==null?void 0:C.strokeWidth)!=null?A:i.brush.strokeWidth,startAngle:C==null?void 0:C.startAngle,endAngle:C==null?void 0:C.endAngle,innerRadius:C==null?void 0:C.innerRadius,outerRadius:C==null?void 0:C.outerRadius}}),this}getLastView(){return this.hg.views[this.hg.views.length-1]}getMainTrackPosition(){return this.orientation==="vertical"?"left":"center"}getLastVisView(){const g=this.hg.views.filter(I=>{var i,n;return((n=(i=I.tracks[this.getMainTrackPosition()])==null?void 0:i[0])==null?void 0:n.type)==="combined"});return g[g.length-1]}getView(g){return this.hg.views.find(I=>I.uid===g)}validateSpec(g=!1){return n2e(ong,this.spec(),g).state==="success"}setDomain(g,I){return g&&(this.getLastView().initialXDomain=a_(g,this.getAssembly())),I&&(this.getLastView().initialYDomain=a_(I,this.getAssembly())),this}adjustDomain(g="horizontal",I,i){if(g!=="vertical")return this;const n=this.getLastView().initialXDomain;if(!n)return this;const[C,r]=n,o=r-C,a=(C+r)/2;return this.getLastView().initialXDomain=[a-o/I/2/i*I,a+o/I/2/i*I],this}setZoomFixed(g){return this.getLastView().zoomFixed=g,this}setZoomLimits(g){return this.getLastView().zoomLimits=g,this}setLayout(g){return this.getLastView().layout=g,this}setEditable(g){return this.hg.editable=g,this}setChromInfoPath(g){return this.getLastView()&&(this.getLastView().chromInfoPath=g),this.hg.chromInfoPath=g,this}addTrackSourceServers(g){var I,i;return g&&((I=this.hg.trackSourceServers)==null?void 0:I.indexOf(g))===-1&&((i=this.hg.trackSourceServers)==null||i.push(g)),this}setMainTrack(g){var I;return this.getLastView()?(this.getLastView().tracks[this.getMainTrackPosition()]=[{type:"combined",uid:`${(I=g.uid)!=null?I:ln()}-${this.getMainTrackPosition()}-combined`,width:g.width-1,height:g.height,contents:[g]}],this):this}addTrackToCombined(g){var I;return this.getLastVisView()?((I=this.getLastVisView().tracks[this.getMainTrackPosition()][0])==null||I.contents.push(g),this):this}setAxisTrack(g,I="regular",i){if(!this.hg.views)return this;const n=g==="left"||g==="right"?"width":"height",C={type:"axis-track",chromInfoPath:this.hg.chromInfoPath,options:{...i,assembly:this.getAssembly(),stroke:"transparent",color:i.theme.axis.labelColor,labelMargin:i.theme.axis.labelMargin,excludeChrPrefix:i.theme.axis.labelExcludeChrPrefix,fontSize:i.theme.axis.labelFontSize,fontFamily:i.theme.axis.labelFontFamily,fontWeight:i.theme.axis.labelFontWeight,tickColor:i.theme.axis.tickColor,tickFormat:I==="narrower"?"si":"plain",tickPositions:I==="regular"?"even":"ends",reverseOrientation:g==="bottom"||g==="right"}};if(i.layout==="circular")this.addTrackToCombined({...C,options:{...C.options,layout:"circular"}});else{const r={...C,[n]:Qr};if(g==="left"){if(this.getLastView().tracks.left.filter(o=>o.type==="axis-track").length!==0)return this;this.getLastView().tracks.left=Lje(this.getLastView().tracks.left,0,r)}else if(g==="right"){if(this.getLastView().tracks.right.filter(o=>o.type==="axis-track").length!==0)return this;this.getLastView().tracks.right.push(r)}else{if(this.getLastView().tracks[g].filter(o=>o.type==="axis-track").length!==0)return this;this.getLastView().tracks[g].push(r)}}return this}setExampleHiglassViewConfig(){this.hg=Ang}}function pG(e,g,I,i){const n=i&&i!==0?i:void 0;let C=0;switch(g){case"less-than":case"LT":case"lt":C=I>e?n?(I-e)/n:1:0;break;case"less-than-or-equal-to":case"LTET":case"ltet":C=I>=e?n?(I-e)/n:1:0;break;case"greater-than":case"GT":case"gt":C=I{e[I]&&I!=="base"&&(g[I]=Object.assign(JSON.parse(JSON.stringify(g[I])),JSON.parse(JSON.stringify(e[I]))))}),g}}class ung{constructor(g,I,i){rt(this,"id"),rt(this,"theme"),rt(this,"specOriginal"),rt(this,"specComplete"),rt(this,"dataAggregated"),rt(this,"channelScales"),rt(this,"mouseEventModel"),this.id=ln(),this.theme=i??J2e(),this.dataAggregated=I,this.specOriginal=g,this.specComplete=structuredClone(g),this.channelScales={},this.mouseEventModel=new hgg;const n=this.validateSpec();if(!n.valid){console.warn("Gosling specification is not valid!",n.errorMessages);return}this.generateCompleteSpec(this.specComplete),this.flipRanges(this.specComplete),this.generateScales(),this.dataAggregated=Qig(this.spec(),this.dataAggregated)}getId(){return this.id}originalSpec(){return this.specOriginal}spec(){return this.specComplete}data(){return this.dataAggregated}getMouseEventModel(){return this.mouseEventModel}generateCompleteSpec(g){if(!g.width||!g.height){console.warn("Size of track is not determined yet.");return}if(g.orientation==="vertical"){const n=g.width;g.width=g.height,g.height=n}const I=this.getGenomicChannelKey();let i=!1;I==="x"&&(i=ut(g.x)&&g.x.axis!==void 0&&g.x.axis!=="none"),I==="y"&&(i=ut(g.y)&&g.y.axis!==void 0&&g.y.axis!=="none"),g.layout!=="circular"?ut(g.x)&&g.x.axis!==void 0&&g.x.axis!=="none"&&(g.height-=Qr):I==="x"&&i&&ut(g.x)&&g.x.axis==="top"?g.outerRadius=g.outerRadius-Qr:I==="x"&&i&&ut(g.x)&&g.x.axis==="bottom"&&(g.innerRadius=g.innerRadius+Qr),Hd.forEach(n=>{const C=g[n];ut(C)&&!("zeroBaseline"in C)&&C.type==="quantitative"&&(C.zeroBaseline=!0)}),this.addScaleMaterials(g)}flipRanges(g){ut(g.y)&&g.y.flip&&Array.isArray(g.y.range)&&(g.y.range=g.y.range.reverse())}getGenomicChannelKey(){return r2e(this.spec())}getGenomicChannel(){return D$(this.spec())}setChannelDomain(g,I,i){const n=this.originalSpec()[g];if(!i&&ut(n)&&n.domain!==void 0)return;const C=this.specComplete[g];ut(C)&&(C.domain=I)}updateChannelValue(){if(this.originalSpec().y===void 0){const g=this.spec().y,I=this.getChannelDomainArray("row");g&&N1(g)&&I&&this.spec().mark!=="withinLink"&&(g.value=this.spec().height/I.length/2)}}encodedValue(g,I){var i;if(g==="text"&&I!==void 0)return`${+I?~~I:I}`;const n=this.spec()[g],C=ut(n)?n.type:N1(n)?"constant":void 0;if(C){if(C==="constant")return this.channelScales[g]();if(I!==void 0&&(I===null&&(C==="quantitative"?I=0:C==="nominal"&&(I="null")),typeof this.channelScales[g]=="function"))switch(g){case"x":case"y":case"x1":case"y1":case"xe":case"ye":case"x1e":if(C==="quantitative"||C==="genomic")return this.channelScales[g](I);if(C==="nominal")return this.channelScales[g](I);break;case"stroke":case"color":if(C==="quantitative"){const r=this.channelScales[g].copy(),o=r.domain(),a=o[1]-o[0],s=Array.from((i=n.scaleOffset)!=null?i:[0,1]);return r.domain([o[0]+a*s.sort()[0],o[0]+a*s.sort()[1]])(I)}if(C==="nominal")return this.channelScales[g](I);break;case"size":if(C==="quantitative")return this.channelScales[g](I);if(C==="nominal")return this.channelScales[g](I);break;case"row":if(C==="nominal")return this.channelScales[g](I);break;case"strokeWidth":case"opacity":if(C==="quantitative")return this.channelScales[g](I);break;default:console.warn(`${g} is not supported for encoding values, so returning a undefined value`);return}}}trackVisibility(g){const I=this.spec();if(!I.visibility||I.visibility.length===0||I.visibility.filter(n=>n.target==="track").length===0)return!0;let i=!0;return I.visibility.filter(n=>n.target==="track").forEach(n=>{const{operation:C,measure:r,threshold:o}=n;let a;r==="zoomLevel"?a=g[r]:a=I[r],a!==void 0&&(i=i&&pG(a,C,o)===1)}),i}markVisibility(g,I){const i=this.spec();if(!i.visibility||i.visibility.length===0||i.visibility.filter(C=>C.target==="mark").length===0)return 1;let n=1;return i.visibility.filter(C=>C.target==="mark").forEach(C=>{const{operation:r,threshold:o,conditionPadding:a,transitionPadding:s,measure:A}=C,l=a??0,c=i.mark;let u=1;if(c==="text"&&o==="|xe-x|"&&A==="width"){const d=this.encodedPIXIProperty("xe",g),h=this.encodedPIXIProperty("x",g);d!==void 0&&(I!=null&&I.width)&&(u=pG(I.width+l,r,Math.abs(d-h),s))}else A==="width"&&typeof o=="number"&&(I!=null&&I.width)?u=pG(I.width+l,r,o,s):A==="zoomLevel"&&typeof o=="number"&&(I!=null&&I.zoomLevel)&&(u=pG(I.zoomLevel,r,o,s));n>u&&(n=u)}),n}visualPropertyByChannel(g,I){const i=I!==void 0?pI(I,this.spec()[g]):void 0;return this.encodedValue(g,i)}encodedPIXIProperty(g,I,i){const n=this.spec().mark;if(["text","color","row","stroke","opacity","strokeWidth","x","y","xe","x1","x1e","ye","size"].includes(g))return this.visualPropertyByChannel(g,I);switch(n){case"bar":return Fje(this,g,I,i);case"point":case"text":return Kje(this,g,I);case"rect":return zje(this,g,I,i);default:return}}addScaleMaterials(g){const I=this.data(),i=this.getGenomicChannel();if(!i||!i.field){console.warn("Genomic field is not provided in the specification");return}if(typeof g.width>"u"||typeof g.height>"u"){console.warn("Track size is not determined yet");return}Hd.forEach(n=>{var C,r,o,a;const s=g[n];if(w4e(g,n)&&ut(s)){const A=yT(I,c=>c[i.field]),l=[...A.keys()];if(!s.domain){const c="zeroBaseline"in s&&s.zeroBaseline?0:X1(l.map(d=>Oee(A.get(d).map(h=>s.field?h[s.field]:void 0)))),u=FG(l.map(d=>Oee(A.get(d).map(h=>s.field?h[s.field]:void 0))));s.domain=[c,u]}if(!s.range){const c=g.row,u=ut(c)?c.field:void 0,d=(C=this.getChannelDomainArray("row"))!=null?C:u?Array.from(new Set(I.map(m=>m[u]))):[1],h=g.height/d.length;switch(n){case"x":s.range=[0,g.width];break;case"y":s.range=[0,h];break}}}else{const A=g.row,l=ut(A)?A.field:void 0,c=(r=this.getChannelDomainArray("row"))!=null?r:l?Array.from(new Set(I.map(d=>d[l]))):[1],u=g.height/c.length;if(s){if(ut(s)&&(s.type==="quantitative"||s.type==="genomic")){if(s.domain===void 0){const d="zeroBaseline"in s&&s.zeroBaseline?0:(o=X1(I.map(m=>+m[s.field])))!=null?o:0,h=(a=FG(I.map(m=>+m[s.field])))!=null?a:0;s.domain=[d,h]}else s.type==="genomic"&&!Kte(s.domain)&&(s.domain=a_(s.domain));if((n==="color"||n==="stroke")&&s.type==="quantitative"&&!s.scaleOffset&&(s.scaleOffset=[0,1]),!s.range){let d;switch(n){case"x":case"xe":case"x1":case"x1e":d=[0,g.width];break;case"y":case"ye":d=[0,u];break;case"color":case"stroke":d=cng.QUANTITATIVE_COLOR;break;case"size":d=this.theme.markCommon.quantitativeSizeRange;break;case"strokeWidth":d=[1,3];break;case"opacity":d=[0,1];break}d&&(s.range=d)}}else if(ut(s)&&s.type==="nominal"&&(s.domain===void 0&&(s.domain=Array.from(new Set(I.map(d=>{var h;return(h=d[s.field])!=null?h:"null"})))),!s.range)){let d=2,h;switch(n){case"x":case"xe":h=[0,g.width];break;case"y":case"ye":h=[u,0];break;case"color":case"stroke":h=this.theme.markCommon.nominalColorRange;break;case"row":h=[0,g.height];break;case"size":h=s.domain.map(()=>d++);break}h&&(s.range=h)}}else{let d;switch(n){case"x":d=g.width/2;break;case"y":g.mark==="withinLink"?d=u:d=u/2;break;case"size":g.mark==="line"?d=this.theme.line.size:g.mark==="bar"||g.mark==="rect"||g.mark==="triangleRight"||g.mark==="triangleLeft"||g.mark==="triangleBottom"||g.stretch&&g.mark==="point"&&ut(g.x)&&ut(g.xe)?d=void 0:g.mark==="text"?d=12:d=this.theme.point.size;break;case"color":d=this.theme.markCommon.color;break;case"row":d=0;break;case"stroke":g.mark==="text"?d=this.theme.text.stroke:d=this.theme.markCommon.stroke;break;case"strokeWidth":g.mark==="rule"?d=this.theme.rule.strokeWidth:g.mark==="withinLink"||g.mark==="betweenLink"?d=this.theme.link.strokeWidth:g.mark==="text"?d=this.theme.text.strokeWidth:d=this.theme.markCommon.strokeWidth;break;case"opacity":d=this.theme.markCommon.opacity;break;case"text":d="";break}typeof d<"u"&&(g[n]={value:d})}}}),[["x","xe"],["y","ye"]].forEach(n=>{const[C,r]=n,o=g[C],a=g[r];if(ut(o)&&ut(a)&&o.type===a.type&&o.domain&&a.domain&&Array.isArray(o.domain)&&Array.isArray(a.domain)){if(o.type==="genomic"||o.type==="quantitative"){const s=X1([o.domain[0],a.domain[0]]),A=FG([o.domain[1],a.domain[1]]);o.domain=a.domain=[s,A]}else if(o.type==="nominal"){const s=Array.from(new Set([...o.domain,...a.domain]));o.range=a.range=s}}})}generateScales(){const g=this.spec();Hd.forEach(I=>{const i=g[I];if(N1(i))this.channelScales[I]=()=>i.value;else if(ut(i)){if(I==="text")return;const n=i.domain,C=i.range;if(n===void 0||C===void 0)return;if(i.type==="quantitative"||i.type==="genomic")switch(I){case"x":case"x1":case"xe":case"x1e":case"y":case"ye":case"size":case"opacity":case"strokeWidth":this.channelScales[I]=eh().domain(n).range(C);break;case"color":case"stroke":let r=sbe;Object.keys(NX).includes(C)&&(r=NX[C]),this.channelScales[I]=Xpe(r).domain(n);break}else if(i.type==="nominal")switch(I){case"x":case"xe":case"y":case"ye":case"row":this.channelScales[I]=Zpe().domain(n).range(C);break;case"size":this.channelScales[I]=wX().domain(n).range(C);break;case"color":case"stroke":this.channelScales[I]=wX(C).domain(n);break}}})}getChannelScale(g){return this.channelScales[g]}setChannelScale(g,I){this.channelScales[g]=I}isShowYAxis(){const g=this.spec(),I=this.getChannelDomainArray("y"),i=this.getChannelRangeArray("y");return ut(g.y)&&g.y.axis!=="none"&&g.y.type==="quantitative"&&!!I&&!!i}getChannelDomainArray(g){const I=this.spec()[g];return ut(I)&&Kte(I.domain)?I.domain:void 0}getChannelRangeArray(g){const I=this.spec()[g];return ut(I)&&S4e(I.range)?I.range:void 0}validateSpec(){return C2e(this.originalSpec())}}function Hr(e,g){G7.publish(e,g)}function dng(e,g){G7.subscribe(e,g)}function hng(e){G7.unsubscribe(e)}const ece={stroke:"black",strokeWidth:1,strokeOpacity:1,color:"none",opacity:1,arrange:"front"};function mng(){return{goslingModels:[],tabularData:[],skipRendering:!1}}const fng={type:"gosling-track",datatype:["multivec","epilogos"],orientation:"1d-horizontal",defaultOptions:{theme:mG("light")}},png=(e,g,I)=>{var i,n,C,r,o,a,s,A,l,c,u,d,h,m,f,b,p,y,Z,B,G,v,w,V,S,X,W,R,H,Y,K,F,J;const{tileProxy:P}=e.services,{BarTrack:ge}=e.tracks,q=xs({color:"black",size:12}),$=class A_ extends ge{constructor(){var Q,ie,he,ne,be,pe;super(g,I),fg(this,d),fg(this,m),fg(this,b),fg(this,y),fg(this,B),fg(this,v),fg(this,V),fg(this,X),fg(this,R),fg(this,Y),fg(this,F),rt(this,"tileSize"),rt(this,"mRangeBrush"),fg(this,i,void 0),fg(this,n,void 0),rt(this,"firstDraw",!0),rt(this,"gLegend",e.libraries.d3Selection.select(g.svgElement).append("g")),rt(this,"displayedLegends",[]),rt(this,"textGraphics",[]),rt(this,"textsBeingUsed",0),rt(this,"pMouseHover",new e.libraries.PIXI.Graphics),rt(this,"pMouseSelection",new e.libraries.PIXI.Graphics),fg(this,C,0),fg(this,r,0),fg(this,o,!1),fg(this,a,e.libraries.d3Selection.select(g.svgElement).append("g")),fg(this,s,new e.libraries.PIXI.TextStyle(q)),fg(this,A,new e.libraries.PIXI.Graphics),fg(this,l,new e.libraries.PIXI.Text("",q)),rt(this,"prevVisibleAndFetchedTiles"),rt(this,"resolvedTracks"),rt(this,"hideMousePosition"),g.dataFetcher.track=this,WC(this,n,{}),WC(this,i,this.options.spec.assembly),"overlay"in this.options.spec?this.options.spec.overlay=this.options.spec._overlay.map(Be=>({...Be,_renderingId:ln()})):this.options.spec._renderingId=ln(),this.fetchedTiles={},this.tileSize=(ie=(Q=this.tilesetInfo)==null?void 0:Q.tile_size)!=null?ie:1024;const{valid:ve,errorMessages:We}=C2e(this.options.spec);ve||console.warn("The specification of the following track is invalid",We,this.options.spec),this.pMain.addChild(this.pMouseHover),this.pMain.addChild(this.pMouseSelection),this.pMask.interactive=!0,this.mRangeBrush=new agg(Dt(this,a),e.libraries,(he=this.options.spec.style)==null?void 0:he.brush),this.mRangeBrush.on("brush",SI(this,R,H).bind(this)),this.pMask.on("mousedown",Be=>{const{x:Je,y:Pe}=Be.data.getLocalPosition(this.pMain);SI(this,b,p).call(this,Je,Pe,Be.data.originalEvent.altKey)}),this.pMask.on("mouseup",Be=>{const{x:Je,y:Pe}=Be.data.getLocalPosition(this.pMain);SI(this,B,G).call(this,Je,Pe)}),this.pMask.on("mousemove",Be=>{const{x:Je}=Be.data.getLocalPosition(this.pMain);SI(this,y,Z).call(this,Je)}),this.pMask.on("mouseout",SI(this,v,w).bind(this)),this.flipText=this.options.spec.orientation==="vertical",this.hideMousePosition&&(this.hideMousePosition(),this.hideMousePosition=void 0),(ne=this.options)!=null&&ne.showMousePosition&&!this.hideMousePosition&&(this.hideMousePosition=e.utils.showMousePosition(this,nC(this.getResolvedTracks()[0]),this.isShowGlobalMousePosition())),this.pLabel.removeChild(this.trackNotFoundText),Dt(this,l).anchor.x=1,Dt(this,l).anchor.y=1,this.pLabel.addChild(Dt(this,A)),this.pLabel.addChild(Dt(this,l)),e.libraries.PIXI.GRAPHICS_CURVES.adaptive=(pe=(be=this.options.spec.style)==null?void 0:be.enableSmoothPath)!=null?pe:!1,e.libraries.PIXI.GRAPHICS_CURVES.adaptive&&(e.libraries.PIXI.GRAPHICS_CURVES.maxLength=1,e.libraries.PIXI.GRAPHICS_CURVES.maxSegments=2048*10)}draw(){var Q,ie;this.clearMouseEventData(),this.textsBeingUsed=0,(Q=this.pMouseHover)==null||Q.clear();const he=()=>{const ne=this.dataFetcher instanceof BH;this.processAllTiles(ne),super.draw(),this.prevVisibleAndFetchedTiles=this.visibleAndFetchedTiles()};PV(this.dataFetcher)&&!abe(this.visibleAndFetchedTiles(),this.prevVisibleAndFetchedTiles)?this.updateTileAsync(this.dataFetcher,he):he(),(ie=this.mRangeBrush)==null||ie.drawBrush(!0),this.firstDraw&&(SI(this,F,J).call(this),this.firstDraw=!1)}initTile(Q){this.drawTile(Q)}updateTile(){}renderTile(){}drawTile(Q){var ie,he;Q.drawnAtScale=this._xScale.copy();const ne=Dt(this,n)[Q.tileId];ne&&((ie=Q.graphics)==null||ie.clear(),(he=Q.graphics)==null||he.removeChildren(),this.pBackground.clear(),this.pBackground.removeChildren(),this.pBorder.clear(),this.pBorder.removeChildren(),this.displayedLegends=[],ne.goslingModels.forEach(be=>{const pe=this.dimensions[0],ve=this._xScale.invert(pe)-this._xScale.invert(0);be.trackVisibility({zoomLevel:ve})&&(A4e(e,this,Q,be,this.options.theme),a4e(e,this,Q,be),s4e(e,this,Q,be,this.options.theme))}),this.forceDraw())}rerender(Q){this.options=Q,this.options.spec.layout==="circular"&&this.mRangeBrush.remove(),this.getResolvedTracks(!0),this.clearMouseEventData(),this.textsBeingUsed=0,this.processAllTiles(!0),this.draw(),this.forceDraw()}clearMouseEventData(){this.visibleAndFetchedGoslingModels().forEach(Q=>Q.getMouseEventModel().clear())}visibleAndFetchedGoslingModels(){return this.visibleAndFetchedTiles().flatMap(Q=>{var ie,he;return(he=(ie=Dt(this,n)[Q.tileId])==null?void 0:ie.goslingModels)!=null?he:[]})}remove(){super.remove(),this.gLegend&&(this.gLegend.remove(),this.gLegend=void 0),this.mRangeBrush.remove()}setDimensions(Q){super.setDimensions(Q),this.mRangeBrush.setSize(Q[1])}setPosition(Q){super.setPosition(Q),[this.pMain.position.x,this.pMain.position.y]=this.position,this.mRangeBrush.setOffset(...Q)}forceDraw(){this.animate()}zoomed(Q,ie){const he=this.mRangeBrush.getRange();this.mRangeBrush.updateRange(he?[Q(this._xScale.invert(he[0])),Q(this._xScale.invert(he[1]))]:null),this.xScale(Q),this.yScale(ie),this.refreshTiles(),this.draw(),this.forceDraw();const ne=Q.domain().map(be=>Uu(be,Dt(this,i),!0));Hr("location",{id:g.viewUid,genomicRange:ne})}setMask(Q,ie){if(this.pMask.clear(),this.pMask.beginFill(),this.options.spec.layout==="circular"){const[he,ne]=this.position,[be,pe]=this.dimensions,ve=he+be/2,We=ne+pe/2,Be=this.options.spec.outerRadius;this.pMask.drawCircle(ve,We,Be)}else this.pMask.drawRect(Q[0],Q[1],ie[0],ie[1]);this.pMask.endFill()}processAllTiles(Q=!1){var ie,he;this.tileSize=(he=(ie=this.tilesetInfo)==null?void 0:ie.tile_size)!=null?he:1024;const ne=this.visibleAndFetchedTiles();ne.forEach(ve=>SI(this,m,f).call(this,ve,Q)),this.combineAllTilesIfNeeded();const be=ne.flatMap(ve=>this.transformDataAndCreateModels(ve));ang(be);const pe=[].concat(...be.map(ve=>ve.data()));pe.length!==0&&this.options.siblingIds.forEach(ve=>Hr("rawData",{id:ve,data:pe}))}async updateTileAsync(Q,ie){if(!this.tilesetInfo)return;const he=this.visibleAndFetchedTiles(),ne=await Q.getTabularData(Object.values(he).map(pe=>pe.remoteId)),be=this.tilesetInfo;he.forEach((pe,ve)=>{if(ve===0){const[We]=e.utils.trackUtils.calculate1DVisibleTiles(be,this._xScale);pe.tileData.zoomLevel=We[0],pe.tileData.tilePos=[We[1],We[1]],pe.tileData.tabularData=ne}else pe.tileData.tabularData=[]}),ie()}calculateVisibleTiles(){var Q,ie,he,ne,be;if(this.tilesetInfo)if(PV(this.dataFetcher)){const pe=e.utils.trackUtils.calculate1DVisibleTiles(this.tilesetInfo,this._xScale),ve=(ie=(Q=this.tilesetInfo.max_tile_width)!=null?Q:this.dataFetcher.MAX_TILE_WIDTH)!=null?ie:Number.MAX_SAFE_INTEGER;for(const We of pe){const{tileWidth:Be}=this.getTilePosAndDimensions(We[0],[We[1],We[1]]);if(this.forceDraw(),Be>ve)return}this.setVisibleTiles(pe)}else{if(!this.tilesetInfo)return;const pe=this.calculateZoomLevel();if("resolutions"in this.tilesetInfo){const ve=this.tilesetInfo.resolutions.map(Pe=>+Pe).sort((Pe,De)=>De-Pe),We=P.calculateTilesFromResolution(ve[pe],this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]);let Be;nC(this.getResolvedTracks()[0])&&(Be=P.calculateTilesFromResolution(ve[pe],this._yScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]));const Je=SI(he=A_,c,u).call(he,We,Be,pe);this.setVisibleTiles(Je)}else{const ve=P.calculateTiles(pe,this.relevantScale(),this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width);let We;nC(this.getResolvedTracks()[0])&&(We=P.calculateTiles(pe,this._yScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1],this.tilesetInfo.max_zoom,(ne=this.tilesetInfo.max_width1)!=null?ne:this.tilesetInfo.max_width));const Be=SI(be=A_,c,u).call(be,ve,We,pe);this.setVisibleTiles(Be)}}}getTilePosAndDimensions(Q,ie){if(!this.tilesetInfo)throw Error("tilesetInfo not parsed");if("resolutions"in this.tilesetInfo){const ne=this.tilesetInfo.resolutions.map(Pe=>+Pe).sort((Pe,De)=>De-Pe)[Q],[be,pe]=ie,ve=ne*Dt(this,d,h),We=ve,Be=ve*be,Je=We*pe;return{tileX:Be,tileY:Je,tileWidth:ve,tileHeight:We}}else{const[he,ne]=ie,be=this.tilesetInfo.min_pos[0],pe=this.tilesetInfo.min_pos[1],ve=this.tilesetInfo.max_width/2**Q,We=this.tilesetInfo.max_width/2**Q,Be=be+he*ve,Je=pe+ne*We;return{tileX:Be,tileY:Je,tileWidth:ve,tileHeight:We}}}getIndicesOfVisibleDataInTile(Q){const ie=this._xScale.range();if(!this.tilesetInfo||!Q.tileData.tilePos||!("dense"in Q.tileData))return[0,0];const{tileX:he,tileWidth:ne}=this.getTilePosAndDimensions(Q.tileData.zoomLevel,Q.tileData.tilePos),be=e.libraries.d3Scale.scaleLinear().domain([0,Dt(this,d,h)]).range([he,he+ne]),pe=Math.max(0,Math.round(be.invert(this._xScale.invert(ie[0])))),ve=Math.min(Q.tileData.dense.length,Math.round(be.invert(this._xScale.invert(ie[1]))));return[pe,ve]}receivedTiles(Q){super.receivedTiles(Q),PV(this.dataFetcher)&&this.drawLoadingCue()}removeOldTiles(){super.removeOldTiles(),PV(this.dataFetcher)&&this.drawLoadingCue()}combineAllTilesIfNeeded(){var Q,ie,he;if(!this.shouldCombineTiles())return;const ne=this.visibleAndFetchedTiles();if(!ne||ne.length<=1)return;this.tileSize=((ie=(Q=this.tilesetInfo)==null?void 0:Q.tile_size)!=null?ie:1024)*ne.length;let be=[];ne.forEach((ve,We)=>{const Be=Dt(this,n)[ve.tileId];Be&&(be=[...be,...Be.tabularData],Be.skipRendering=We!==0)});const pe=Dt(this,n)[ne[0].tileId];pe.tabularData=be,(he=pe.tabularData[0])!=null&&he.uid&&(pe.tabularData=nje(pe.tabularData,"uid"))}shouldCombineTiles(){const Q=l4e(this.options.spec,"displace"),ie=()=>{const ne=this.visibleAndFetchedTiles();return ne.length>=1&&"dense"in ne[0].tileData},he=this.dataFetcher instanceof BH;return Q&&!ie()&&!he}getResolvedTracks(Q=!1){if(Q||!this.resolvedTracks){const ie=structuredClone(this.options.spec),he=T0(ie).filter(ne=>ne.mark!=="brush");he.forEach(ne=>{"values"in ne.data&&(ne.data.values=[])}),this.resolvedTracks=he}return this.resolvedTracks}transformDataAndCreateModels(Q){const ie=Dt(this,n)[Q.tileId];return!ie||ie.skipRendering?[]:(ie.goslingModels=[],this.getResolvedTracks().forEach(ne=>{var be;let pe=Array.from(ie.tabularData);(be=ne.dataTransform)==null||be.forEach(_e=>{switch(_e.type){case"filter":pe=x2e(_e,pe);break;case"concat":pe=Eig(_e,pe);break;case"replace":pe=Mig(_e,pe);break;case"log":pe=zig(_e,pe);break;case"exonSplit":pe=Lig(_e,pe,ne.assembly);break;case"genomicLength":pe=Pig(_e,pe);break;case"svType":pe=Jig(_e,pe);break;case"coverage":pe=Oig(_e,pe,this._xScale.copy());break;case"subjson":pe=Uig(_e,pe);break;case"displace":pe=_ig(_e,pe,this._xScale.copy());break}});try{if(PubSub){const gt=pe.length;PubSub.publish("data-preview",{id:g.viewUid,dataConfig:JSON.stringify({data:ne.data}),data:100>gt?pe:e7(pe,100)})}}catch{}const[ve,We]=this.dimensions,Be=kX(ne)?Qr:0,[Je,Pe]=[ve,We+Be],De=Math.min(Je,Pe)/Math.min(ne.width,ne.height);ne.innerRadius&&(ne.innerRadius=ne.innerRadius*De),ne.outerRadius&&(ne.outerRadius=ne.outerRadius*De),ne.width=Je,ne.height=Pe;const Qe=new ung(ne,pe,this.options.theme);ie.goslingModels.push(Qe)}),ie.goslingModels)}getMouseOverHtml(Q,ie){var he,ne,be,pe,ve;if(SI(this,X,W).call(this,"trackMouseOver",Q,ie),Dt(this,o)||!this.tilesetInfo)return"";this.pMouseHover.clear();const We=Uu(Math.floor(this._xScale.invert(Q)),Dt(this,i)),Be=SI(this,V,S).call(this,Q,ie);if(Be.length!==0?document.body.style.cursor="pointer":document.body.style.cursor="default",Be.length!==0){const Je=(he=this.options.spec.experimental)==null?void 0:he.mouseEvents;if(!!Je||Ym(Je)&&!!Je.mouseOver){const _e=this.pMouseHover;((be=(ne=this.options.spec.style)==null?void 0:ne.mouseOver)==null?void 0:be.arrange)!=="behind"&&(this.pMain.removeChild(_e),this.pMain.addChild(_e)),SI(this,Y,K).call(this,_e,Be,Object.assign({},ece,(pe=this.options.spec.style)==null?void 0:pe.mouseOver)),Hr("mouseOver",{id:g.viewUid,genomicPosition:We,data:Be.map(gt=>gt.value)})}const Qe=(ve=this.visibleAndFetchedGoslingModels().find(_e=>{var gt;return _e.spec().tooltip&&((gt=_e.spec().tooltip)==null?void 0:gt.length)!==0}))==null?void 0:ve.spec().tooltip;if(Qe){let _e=Qe.map(gt=>{var lt;const tt=Be[0].value[gt.field];let Xe=tt;if(gt.type==="quantitative"&>.format)Xe=e.libraries.d3Format.format(gt.format)(+tt);else if(gt.type==="genomic"){const{chromosome:ae,position:ye}=Uu(+tt,Dt(this,i));Xe=`${ae}:${e.libraries.d3Format.format(",")(ye)}`}return`${(lt=gt.alt)!=null?lt:gt.field}${Xe}`}).join("");return _e=`${_e}
`,Be.length>1&&(_e+=`
${Be.length-1} Additional Selections...
`),`
${_e}
`}}return""}minVisibleValue(){return 0}maxVisibleValue(){return 0}exportSVG(){throw new Error("exportSVG() not supported for gosling-track")}drawLoadingCue(){if(this.fetching.size){const ie=`Fetching... ${Array.from(this.fetching).join(" ")}`;Dt(this,l).text=ie,Dt(this,l).x=this.position[0]+this.dimensions[0]-6/2,Dt(this,l).y=this.position[1]+this.dimensions[1]-6/2;const he=e.libraries.PIXI.TextMetrics.measureText(ie,Dt(this,s)),{width:ne,height:be}=he;Dt(this,A).clear(),Dt(this,A).lineStyle(1,pt("grey"),1,.5),Dt(this,A).beginFill(pt("white"),.8),Dt(this,A).drawRect(this.position[0]+this.dimensions[0]-ne-6-1,this.position[1]+this.dimensions[1]-be-6-1,ne+6,be+6),Dt(this,l).visible=!0,Dt(this,A).visible=!0}else Dt(this,l).visible=!1,Dt(this,A).visible=!1}updateScaleOffsetFromOriginalSpec(Q,ie,he){this.getResolvedTracks().map(ne=>{if(ne._renderingId===Q){const be=ne[he];ut(be)&&(be.scaleOffset=ie)}})}shareScaleOffsetAcrossTracksAndTiles(Q,ie){this.visibleAndFetchedGoslingModels().forEach(ne=>{const be=ne.spec()[ie];ut(be)&&(be.scaleOffset=Q);const pe=ne.originalSpec()[ie];ut(pe)&&(pe.scaleOffset=Q)})}};i=new WeakMap,n=new WeakMap,C=new WeakMap,r=new WeakMap,o=new WeakMap,a=new WeakMap,s=new WeakMap,A=new WeakMap,l=new WeakMap,c=new WeakSet,u=function(te,Q,ie){if(!Q)return te.map(ne=>[ie,ne]);const he=[];return te.forEach(ne=>Q.forEach(be=>he.push([ie,ne,be]))),he},d=new WeakSet,h=function(){let te;return this.tilesetInfo&&(te="bins_per_dimension"in this.tilesetInfo?this.tilesetInfo.bins_per_dimension:this.tilesetInfo.tile_size),te??256},m=new WeakSet,f=function(te,Q=!1){if(Dt(this,n)[te.tileId]&&!Q||!te.tileData.tilePos)return;const ie=mng(),he=this.getResolvedTracks();if(he.length===0)return[];const ne=he[0];if("tabularData"in te.tileData)ie.tabularData=te.tileData.tabularData;else{const{tileX:be,tileY:pe,tileWidth:ve,tileHeight:We}=this.getTilePosAndDimensions(te.tileData.zoomLevel,te.tileData.tilePos),Be="length"in te.tileData?Array.from(te.tileData):[],Je=Object.assign({},te.tileData,{sparse:Be,tileX:be,tileY:pe,tileWidth:ve,tileHeight:We,tileSize:this.tileSize}),Pe=ing(ne,Je);Pe&&(ie.tabularData=Pe)}Dt(this,n)[te.tileId]=ie},b=new WeakSet,p=function(te,Q,ie){var he;WC(this,C,te),WC(this,r,Q);const ne=(he=this.options.spec.experimental)==null?void 0:he.mouseEvents,be=!!ne||Ym(ne)&&!!ne.rangeSelect;WC(this,o,be&&ie),this.pMouseHover.clear()},y=new WeakSet,Z=function(te){this.options.spec.layout!=="circular"&&Dt(this,o)&&this.mRangeBrush.updateRange([te,Dt(this,C)]).drawBrush().visible().disable()},B=new WeakSet,G=function(te,Q){var ie;SI(this,X,W).call(this,"trackClick",te,Q);const he=(ie=this.options.spec.experimental)==null?void 0:ie.mouseEvents,ne=!!he||Ym(he)&&!!he.click,be=Math.sqrt((Dt(this,C)-te)**2+(Dt(this,r)-Q)**2)>1;if(!Dt(this,o)&&!be?(this.mRangeBrush.clear(),this.pMouseSelection.clear()):this.mRangeBrush.enable(),WC(this,o,!1),!!this.tilesetInfo&&!be&&ne){const pe=Uu(Math.floor(this._xScale.invert(te)),Dt(this,i)),ve=SI(this,V,S).call(this,te,Q);ve.length!==0&&this.options.siblingIds.forEach(We=>Hr("click",{id:We,genomicPosition:pe,data:ve.map(Be=>Be.value)}))}},v=new WeakSet,w=function(){WC(this,o,!1),document.body.style.cursor="default",this.pMouseHover.clear()},V=new WeakSet,S=function(te,Q){var ie;const he=this.visibleAndFetchedGoslingModels(),ne=(ie=this.options.spec.experimental)==null?void 0:ie.mouseEvents,be=Ym(ne)&&ne.enableMouseOverOnMultipleMarks,pe=Ym(ne)&&ne.groupMarksByField,ve=he.map(We=>We.getMouseEventModel().findAll(te,Q,!0)).flat();if(be||ve.splice(1,ve.length-1),ve.length!==0&&pe){const We=Array.from(ve);he.forEach(Be=>{const Je=Be.getMouseEventModel().getSiblings(We,pe);ve.push(...Je)})}return ve},X=new WeakSet,W=function(te,Q,ie){const[he,ne]=this.position,[be,pe]=this.dimensions;if(this.options.spec.layout==="circular"){const ve=he+be/2,We=ne+pe/2,Be=this.options.spec.innerRadius,Je=this.options.spec.outerRadius,Pe=this.options.spec.startAngle,De=this.options.spec.endAngle;Agg([Q,ie],[be/2,pe/2],[Be,Je],[Pe,De])&&Hr(te,{id:g.viewUid,spec:structuredClone(this.options.spec),shape:{x:he,y:ne,width:be,height:pe,cx:ve,cy:We,innerRadius:Be,outerRadius:Je,startAngle:Pe,endAngle:De}})}else Hr(te,{id:g.viewUid,spec:structuredClone(this.options.spec),shape:{x:he,y:ne,width:be,height:pe}})},R=new WeakSet,H=function(te,Q=!1){var ie,he,ne,be;if(this.pMouseSelection.clear(),te===null){Q||Hr("rangeSelect",{id:g.viewUid,genomicRange:null,data:[]});return}const pe=this.visibleAndFetchedGoslingModels(),[ve,We]=te;let Be=pe.map(De=>De.getMouseEventModel().findAllWithinRange(ve,We,!0)).flat();const Je=(ie=this.options.spec.experimental)==null?void 0:ie.mouseEvents,Pe=Ym(Je)&&Je.groupMarksByField;if(Be.length!==0&&Pe&&pe.forEach(De=>{const Qe=De.getMouseEventModel().getSiblings(Be,Pe),_e=Array.from(new Set(Qe.map(gt=>gt.value[Pe])));Be=Be.filter(gt=>_e.indexOf(gt.value[Pe])===-1)}),Be.length!==0){const De=this.pMouseSelection;((ne=(he=this.options.spec.style)==null?void 0:he.select)==null?void 0:ne.arrange)!=="behind"&&(this.pMain.removeChild(De),this.pMain.addChild(De)),SI(this,Y,K).call(this,De,Be,Object.assign({},ece,(be=this.options.spec.style)==null?void 0:be.select))}if(!Q){const De=[Uu(Math.floor(this._xScale.invert(ve)),Dt(this,i)),Uu(Math.floor(this._xScale.invert(We)),Dt(this,i))];Hr("rangeSelect",{id:g.viewUid,genomicRange:De,data:Be.map(Qe=>Qe.value)})}this.forceDraw()},Y=new WeakSet,K=function(te,Q,ie){te.lineStyle(ie.strokeWidth,pt(ie.stroke),ie.strokeOpacity,.5),te.beginFill(pt(ie.color),ie.color==="none"?0:ie.opacity),Q.forEach(he=>{if(he.type==="point"){const[ne,be,pe=3]=he.polygon;te.drawCircle(ne,be,pe)}else he.type==="line"?(te.moveTo(he.polygon[0],he.polygon[1]),Uje(he.polygon).map(ne=>te.lineTo(ne[0],ne[1]))):te.drawPolygon(he.polygon)})},F=new WeakSet,J=function(){Hr("onNewTrack",{id:g.viewUid})},fg($,c);let j=$;return new j},C1=F$(fng,png),bng={type:"dummy-track",defaultOptions:{height:0,width:0,title:"",background:"#fff",textFontSize:12,textFontWeight:"normal",textStroke:"#000",textStrokeWidth:.1,outline:"#fff"}},yng=(e,g,I)=>{var i,n,C,r;const{SVGTrack:o}=e.tracks;class a extends o{constructor(){super(g,I),fg(this,i),fg(this,C),SI(this,i,n).call(this),SI(this,C,r).call(this),Hr("onNewTrack",{id:g.viewUid})}}return i=new WeakSet,n=function(){this.gMain.append("rect").attr("fill",I.background).attr("x",0).attr("y",0).attr("width",I.width).attr("height",I.height).style("stroke",I.outline)},C=new WeakSet,r=function(){this.gMain.append("text").attr("x",I.width/2).attr("y",(I.height+I.textFontSize)/2).style("text-anchor","middle").style("font-size",`${I.textFontSize}px`).style("font-weight",I.textFontWeight).style("stroke",I.textStroke).style("stroke-width",I.textStrokeWidth).text(I.title)},new a},tce=F$(bng,yng);let gce=!1;function Zng(){if(!gce){Vu({name:"GoslingTrack",track:C1,config:C1.config}),Vu({name:"Gosling2DTrack",track:C1,config:{...C1.config,type:"gosling-2d-track",orientation:"2d"}}),Vu({name:"AxisTrack",track:ale,config:ale.config}),Vu({name:"TextTrack",track:b3,config:b3.config}),Vu({name:"BrushTrack",track:e_,config:e_.config}),Vu({name:"DummyTrack",track:tce,config:tce.config});for(const e of Object.values(gng)){const{config:g}=e;Vu({dataFetcher:e,config:g},{pluginType:"dataFetcher"})}gce=!0}}function O2e(e){let g=0,I=0;return e.forEach(i=>{const n=i.boundingBox.x+i.boundingBox.width,C=i.boundingBox.y+i.boundingBox.height;I{s.boundingBox.y+=o+a}),n=[{track:vng({width:C.width,height:o},e.title,e.subtitle),boundingBox:{x:0,y:0,width:C.width,height:o},layout:{x:0,y:0,w:12,h:o/C.height*12}},...n]}else C.height=C.height+(8-C.height%8);const r=!(typeof e.responsiveSize!="object"?e.responsiveSize:e.responsiveSize.height);return n.forEach(o=>{o.layout.x=o.boundingBox.x/C.width*12,o.layout.w=o.boundingBox.width/C.width*12,o.layout.y=r?o.boundingBox.y:o.boundingBox.y/C.height*12,o.layout.h=r?o.boundingBox.height:o.boundingBox.height/C.height*12}),{trackInfos:n,size:C}}function s_(e,g,I=0,i=0,n=!0){let C=0,r=0,o=!0,a=!1;pb(e,c=>{a=!0,c.layout!=="circular"&&(o=!1)});let s=!0;Ube(e,c=>{(c.arrangement==="vertical"||c.arrangement==="horizontal")&&(s=!1)});const A=n&&o&&a&&s&&("views"in e&&(e.arrangement==="parallel"||e.arrangement==="serial")||"tracks"in e),l=g.length;if("tracks"in e){const c=e.tracks;e.orientation==="vertical"?(r=Math.max(...c.map(u=>u.height)),c.forEach((u,d,h)=>{ice([u])===1&&(u.width+=Qr),u.height=r,g.push({track:u,boundingBox:{x:I+C,y:i,width:u.width,height:r},layout:{x:0,y:0,w:0,h:0}}),h[d+1]&&h[d+1].overlayOnPreviousTrack||(C+=u.width,d!==h.length-1&&(C+=e.spacing!==void 0?e.spacing:0))})):(C=Math.max(...c.map(u=>u.width)),c.forEach((u,d,h)=>{ice([u])===1&&(u.height+=Qr);const m=T0(u);m.length>0&&nC(m[0])&&Gng([u])===1&&(C+=Qr),u.width=C,g.push({track:u,boundingBox:{x:I,y:i+r,width:C,height:u.height},layout:{x:0,y:0,w:0,h:0}}),h[d+1]&&h[d+1].overlayOnPreviousTrack||(r+=u.height,d!==h.length-1&&(r+=e.spacing!==void 0?e.spacing:0))}))}else if(e.arrangement==="parallel"||e.arrangement==="vertical"){const c=e.spacing!==void 0?e.spacing:T1;e.views.forEach((u,d,h)=>{var m,f,b,p,y;const Z=s_(u,g,I+((m=u.xOffset)!=null?m:0),i+((f=u.yOffset)!=null?f:0)+r,!A&&n);C<((b=u.xOffset)!=null?b:0)+Z.width&&(C=((p=u.xOffset)!=null?p:0)+Z.width),d!==h.length-1&&(r+=c),r+=((y=u.yOffset)!=null?y:0)+Z.height})}else(e.arrangement==="serial"||e.arrangement==="horizontal")&&e.views.forEach((c,u,d)=>{var h,m,f,b,p;const y=e.spacing!==void 0?e.spacing:T1,Z=s_(c,g,I+((h=c.xOffset)!=null?h:0)+C,i+((m=c.yOffset)!=null?m:0),!A&&n);r<((f=c.xOffset)!=null?f:0)+Z.height&&(r=((b=c.xOffset)!=null?b:0)+Z.height),u!==d.length-1&&(C+=y),C+=((p=c.xOffset)!=null?p:0)+Z.width});if(A){const c=g.slice(l),u="views"in e&&(e.arrangement==="parallel"||e.arrangement==="serial")&&e.views.length>1,d=e.spacing!==void 0?e.spacing:T1,h=Tje,m=e.centerRadius!==void 0?e.centerRadius:ube,f=C/2+h,b=f*(1-m);c.forEach((p,y)=>{var Z,B;if(VS(p.track))return;p.track.layout="circular",p.track.outerRadius=f-h-(p.boundingBox.y-i)/r*b,p.track.innerRadius=f-h-(p.boundingBox.y+p.boundingBox.height-i)/r*b;const G=d/C*360;p.track.startAngle=G+(p.boundingBox.x-I)/C*(C-d)/C*360,p.track.endAngle=(p.boundingBox.x+p.boundingBox.width-I)/C*(C-d)/C*360,p.boundingBox.x=I+((Z=p.track.xOffset)!=null?Z:0),p.boundingBox.y=i+((B=p.track.yOffset)!=null?B:0),p.boundingBox.height=p.track.height=p.boundingBox.width=p.track.width=f*2,y!==0&&(p.track.overlayOnPreviousTrack=!0),u&&ui(p.track)&&(p.track._overlay=p.track._overlay.filter(v=>v.mark!=="brush"))}),r=f*2}return e._assignedWidth=C,e._assignedHeight=r,{x:I,y:i,width:C,height:r}}function ice(e){return e.filter(g=>kX(g)).length}function Gng(e){return e.filter(g=>R4e(g)).length}const vng=(e,g,I)=>JSON.parse(JSON.stringify({mark:"header",width:e.width,height:e.height,title:g,subtitle:I}));function Bng(e){if(!e.includes("tileset_info/?d=")||!e.includes("https:")&&!e.includes("http:"))return{server:void 0,tilesetUid:void 0};const g=e.split("tileset_info/?d=")[0],I=e.split("tileset_info/?d=")[1];return{server:g,tilesetUid:I}}function Sng(e,g,I,i,n,C,r){var o,a,s,A,l,c,u,d,h,m,f,b,p,y,Z;if(VS(g))return e.addDefaultView(g.id).setDummyTrack(g).setLayout(i),e;const B=T0(g),G=B[0],v=(o=G.id)!=null?o:ln();G.id||(G.id=v),B.forEach(V=>{V.id&&C.addMapping(V.id,v)});const w=G.assembly;if(Yte(G.data)){let V,S;if(i7(G.data)){const ge=Bng(G.data.url);V=ge.server,S=ge.tilesetUid}const X=D$(G),W=r2e(G),H=(W==="x"||W==="xe")&&ut(X)?X.domain:void 0,Y=nC(G)&&ut(G.y)?G.y.domain:void 0,K=I.width-(G.layout!=="circular"&&G.orientation==="vertical"&&kX(G)?Qr:0),F=I.height-(G.layout!=="circular"&&G.orientation==="horizontal"&&kX(G)?Qr:0),J={uid:`${v}-track`,type:nC(G)?"gosling-2d-track":"gosling-track",server:V,tilesetUid:S,width:K,height:F,options:{id:v,siblingIds:C.getSiblingGoslingIds(v),showMousePosition:G.layout==="circular"?!1:n.root.showMousePosition,mousePositionColor:n.root.mousePositionColor,name:G.layout==="linear"?G.title:" ",labelPosition:G.title?n.track.titleAlign==="left"?"topLeft":"topRight":"none",labelShowResolution:!1,labelColor:n.track.titleColor,labelBackgroundColor:n.track.titleBackground,labelBackgroundOpacity:.5,labelTextOpacity:1,labelLeftMargin:1,labelTopMargin:1,labelRightMargin:0,labelBottomMargin:0,backgroundColor:"transparent",spec:{...g},theme:n}};if(G.data&&Yte(G.data)&&(G.data.type==="csv"||G.data.type==="json"||G.data.type==="bigwig"||G.data.type==="bam"||G.data.type==="vcf"||G.data.type==="gff"||G.data.type==="bed")){const ge=te=>{const Q=G[te];return Q&&ut(Q)?Q.field:void 0},q={x:ge("x"),xe:ge("xe"),x1:ge("x1"),x1e:ge("x1e")},$="url"in G.data&&(r==null?void 0:r[G.data.url])||{},j="indexUrl"in G.data&&(r==null?void 0:r[G.data.indexUrl])||{};J.data={...G.data,...q,urlFetchOptions:$,indexUrlFetchOptions:j,assembly:w}}if(Z4e(G)){J.type="heatmap";const ge=ut(G.color)&&typeof G.color.range=="string"?G.color.range:"viridis";J.options.colorRange=c4e(ge),J.options.trackBorderWidth=(s=(a=G.style)==null?void 0:a.outlineWidth)!=null?s:n.track.outlineWidth,J.options.trackBorderColor=(l=(A=G.style)==null?void 0:A.outline)!=null?l:n.track.outline,J.options.extent=(u=(c=G.style)==null?void 0:c.matrixExtent)!=null?u:"full",J.options.colorbarPosition=(d=G.color)!=null&&d.legend?J.options.extent==="lower-left"?"bottomLeft":"topRight":"hidden"}G.overlayOnPreviousTrack?e.setViewOrientation(G.orientation).addTrackToCombined(J):e.setViewOrientation(G.orientation).setAssembly(w).addDefaultView(v,w).setDomain(H,Y??H).adjustDomain(G.orientation,K,F).setMainTrack(J).addTrackSourceServers(V).setZoomFixed(G.static===!0).setZoomLimits((h=G.zoomLimits)!=null?h:[1,null]).setLayout(i);const P=(ge,q="horizontal",$,j)=>q==="horizontal"?ge==="x"&&$<=200||ge==="y"&&j<=200?"narrower":ge==="x"&&$<=400||ge==="y"&&j<=400?"narrow":"regular":ge==="x"&&j<=200||ge==="y"&&$<=200?"narrower":ge==="x"&&j<=400||ge==="y"&&$<=400?"narrow":"regular";["x","y"].forEach(ge=>{const q=G[ge];if(ut(q)&&"axis"in q&&q.axis&&q.axis!=="none"&&q.type==="genomic"){const $=P(ge,g.orientation,I.width,I.height);e.setAxisTrack(q.axis,$,{id:`${v}-${q.axis}-axis`,layout:G.layout,innerRadius:q.axis==="top"?G.outerRadius-Qr:G.innerRadius,outerRadius:q.axis==="top"?G.outerRadius:G.innerRadius+Qr,width:G.width,height:G.height,startAngle:G.startAngle,endAngle:G.endAngle,theme:n})}}),e.validateSpec(!0)}else G.mark==="header"&&(e.addDefaultView(`${v}-title`).setLayout(i),typeof G.title=="string"&&e.setTextTrack(I.width,((m=n.root.titleFontSize)!=null?m:18)+TX,G.title,n.root.titleColor,(f=n.root.titleFontSize)!=null?f:18,n.root.titleFontWeight,n.root.titleAlign,n.root.titleBackgroundColor,(b=n.root.titleFontFamily)!=null?b:C3.fontFamily),typeof G.subtitle=="string"&&e.setTextTrack(I.width,((p=n.root.subtitleFontSize)!=null?p:14)+TX,G.subtitle,n.root.subtitleColor,(y=n.root.subtitleFontSize)!=null?y:14,n.root.subtitleFontWeight,n.root.subtitleAlign,n.root.subtitleBackgroundColor,(Z=n.root.subtitleFontFamily)!=null?Z:C3.fontFamily));return e}function wng(e){const g=[];return e.spec().views.forEach(I=>{var i,n,C,r,o,a,s,A,l,c,u,d,h,m,f;const b=I.uid;let p=(o=(r=(C=(n=(i=I.tracks.center)==null?void 0:i[0])==null?void 0:n.contents)==null?void 0:C[0])==null?void 0:r.options)==null?void 0:o.spec;if(p||(p=(c=(l=(A=(s=(a=I.tracks.left)==null?void 0:a[0])==null?void 0:s.contents)==null?void 0:A[0])==null?void 0:l.options)==null?void 0:c.spec,p||(p=(f=(m=(h=(d=(u=I.tracks.left)==null?void 0:u[1])==null?void 0:d.contents)==null?void 0:h[0])==null?void 0:m.options)==null?void 0:f.spec)),!b||!p)return;T0(p).forEach(Z=>{Hd.forEach(B=>{var G,v,w,V;const S=Z[B];if(ut(S)&&"linkingId"in S&&S.linkingId){g.push({layout:Z.layout==="circular"?"circular":"linear",hgViewId:b,linkId:S.linkingId,isBrush:Z.mark==="brush",style:{color:(G=Z.color)==null?void 0:G.value,stroke:(v=Z.stroke)==null?void 0:v.value,strokeWidth:(w=Z.strokeWidth)==null?void 0:w.value,opacity:(V=Z.opacity)==null?void 0:V.value,startAngle:Z.startAngle,endAngle:Z.endAngle,innerRadius:Z.innerRadius,outerRadius:Z.outerRadius}});return}})})}),g}class Vng{constructor(){fg(this,jA,{})}addMapping(g,I){Dt(this,jA)[g]&&Dt(this,jA)[g]!==I&&console.warn(`The track ID ${g} already exists but overwriting with a different ID.`),Dt(this,jA)[g]=I}getTable(){return Dt(this,jA)}getGoslingIds(){return Object.keys(Dt(this,jA))}getHiGlassId(g){return Dt(this,jA)[g]}getSiblingGoslingIds(g){return Object.entries(Dt(this,jA)).filter(([,I])=>I===g).map(([I])=>I)}}jA=new WeakMap;function Rng(e){const g=new Set;return e.id&&g.add(e.id),pb(e,I=>{("views"in I||"tracks"in I)&&I.id&&g.add(I.id)}),Array.from(g)}function Wng(e){const g=new Set;return pb(e,I=>{!("views"in I)&&!("tracks"in I)&&I.id&&g.add(I.id)}),Array.from(g)}function Xng(e,g){let I;return e.id===g&&(I=e),pb(e,i=>{i.id===g&&(I=i)}),I}function Hng(e,g){return Rng(e).map(I=>{const i=Xng(e,I),n=Wng(i),C={x:Number.MAX_SAFE_INTEGER,y:Number.MAX_SAFE_INTEGER,xe:-Number.MAX_SAFE_INTEGER,ye:-Number.MAX_SAFE_INTEGER};return n.map(r=>g.find(o=>o.id===r)).forEach(r=>{if(!r)return;const{shape:o}=r;C.x>o.x&&(C.x=o.x),C.y>o.y&&(C.y=o.y),C.xe{const{track:u,boundingBox:d,layout:h}=c;Sng(C,u,d,h,i,r,n)});const o=wng(C);o.filter(c=>c.isBrush).forEach(c=>{var u;C.addBrush(c.layout,c.hgViewId,i,(u=o.find(d=>!d.isBrush&&d.linkId===c.linkId))==null?void 0:u.hgViewId,c.style)}),o.filter(c=>!c.isBrush).forEach(c=>{C.spec().zoomLocks.locksByViewUid[c.hgViewId]=c.linkId,C.spec().locationLocks.locksByViewUid[c.hgViewId]=c.linkId}),Array.from(new Set(o.map(c=>c.linkId))).forEach(c=>{C.spec().zoomLocks.locksDict[c]={uid:c},C.spec().locationLocks.locksDict[c]={uid:c},o.filter(u=>!u.isBrush).filter(u=>u.linkId===c).forEach(u=>{C.spec().zoomLocks.locksDict[c][u.hgViewId]=[1246253105e-1,1246253105e-1,249250.621],C.spec().locationLocks.locksDict[c][u.hgViewId]=[1246253105e-1,1246253105e-1,249250.621]})});const s=g.map(c=>({id:c.track.id,spec:c.track,shape:c.track.layout==="linear"||VS(c.track)?c.boundingBox:{...c.boundingBox,cx:c.boundingBox.x+c.boundingBox.width/2,cy:c.boundingBox.y+c.boundingBox.height/2,innerRadius:c.track.innerRadius,outerRadius:c.track.outerRadius,startAngle:c.track.startAngle,endAngle:c.track.endAngle}})),A=Hng(e,s),l=[...s.map(c=>({...c,type:"track"})),...A.map(c=>({...c,type:"view"}))];I(C.spec(),O2e(g),e,l,r.getTable())}function _2e(e,g,I,i,n){if(typeof e._assignedWidth>"u"||typeof e._assignedHeight>"u")return console.warn("Responsive spec cannot be used when width and height of a view is not determined yet."),!1;let C=!1;const{responsiveSpec:r}=e,o=e._assignedWidth*g,a=e._assignedHeight*I,s={width:o,height:a,aspectRatio:o/a},A={width:i,height:n,aspectRatio:i/n};return r&&r.forEach(l=>{const{spec:c,selectivity:u}=l;if(Nng(u,s,A)&&!C){Object.keys(c).forEach(d=>{e[d]=c[d]}),delete e.responsiveSpec,C=!0;return}}),"views"in e&&e.views.forEach(l=>{C=_2e(l,g,I,i,n)||C}),C}function Nng(e,g,I){if(e.length===0)return!1;let i=!0;return e.forEach(n=>{const{measure:C,operation:r,threshold:o,target:a}=n;i=i&&pG((a==="container"?I:g)[C],r,o)===1}),i}function kng(e,g,I,i,n,C){var r,o;const a=JSON.parse(JSON.stringify(e));i6e(a),Mtg(a,I),h3(a);const s=Ice(a,i);let{trackInfos:A}=s;const{size:l}=s,c=typeof e.responsiveSize=="object"&&((r=e.responsiveSize)==null?void 0:r.width)||e.responsiveSize,u=typeof e.responsiveSize=="object"&&((o=e.responsiveSize)==null?void 0:o.height)||e.responsiveSize,d=c&&n.containerSize?n.containerSize.width/l.width:1,h=u&&n.containerSize?n.containerSize.height/l.height:1,m=n.containerParentSize?n.containerParentSize.width:Number.MAX_SAFE_INTEGER,f=n.containerParentSize?n.containerParentSize.height:Number.MAX_SAFE_INTEGER;_2e(a,d,h,m,f)&&(h3(a),A=Ice(a,i).trackInfos),Hr("specProcessed",{id:a.id,spec:a}),Tng(a,A,g,i,C)}Zng();const L2e=U.forwardRef((e,g)=>{var I;const[i,n]=U.useState((I=e.id)!=null?I:ln());U.useEffect(()=>{var u;n((u=e.id)!=null?u:ln())},[e.id]);const C=e.viewConfig||{},r=!1,o=U.useMemo(()=>N.createElement(uy,{ref:g,options:{pixelPreciseMarginPadding:r,containerPaddingX:0,containerPaddingY:0,viewMarginTop:0,viewMarginBottom:0,viewMarginLeft:0,viewMarginRight:0,viewPaddingTop:0,viewPaddingBottom:0,viewPaddingLeft:0,viewPaddingRight:0,sizeMode:"bounded",rangeSelectionOnAlt:!0},viewConfig:C}),[C,r]),{padding:a=60,margin:s=0,border:A="none",background:l,alt:c="Gosling visualization"}=e.options||{};return N.createElement(N.Fragment,null,N.createElement("div",{id:i,className:`gosling-component ${e.className||""}`,style:{position:"relative",padding:a,margin:s,border:A,background:l,width:e.options.responsiveWidth?`calc(100% - ${a*2}px)`:e.size.width,height:e.options.responsiveHeight?`calc(100% - ${a*2}px)`:e.size.height,textAlign:"left"},"aria-label":c,role:"graphics-document","aria-roledescription":"visualization"},N.createElement("div",{key:JSON.stringify(C),id:"higlass-wrapper",className:"higlass-wrapper",style:{position:"relative",display:"block",background:l,margin:0,padding:0,width:e.options.responsiveWidth?"100%":e.size.width,height:e.options.responsiveHeight?"100%":e.size.height}},o)))});L2e.displayName="HiGlassComponentWrapper";function Yng(e,g,I,i,n){const C=structuredClone(n),r=d=>{const h=C[d];return h||console.warn(`Unable to find the track ID, named ${d}.`),h??d},o=()=>Object.keys(C),a=()=>[...I],s=()=>[...a().filter(d=>d.type==="track")],A=d=>{const h=s().find(m=>m.id===d);return h||console.warn(`[getTrack()] Unable to find a track using the ID (${d})`),h},l=()=>[...a().filter(d=>d.type==="view")],c=d=>{const h=l().find(m=>m.id===d);return h||console.warn(`Unable to find a view with the ID of ${d}`),h},u=d=>{var h,m;const f=(h=d==null?void 0:d.resolution)!=null?h:4,b=(m=d==null?void 0:d.transparentBackground)!=null?m:!1,p=e.pixiRenderer,y=Ys.create({width:p.width/2,height:p.height/2,resolution:f});p.render(e.pixiStage,y);const Z=p.plugins.extract.canvas(y),B=document.createElement("canvas");B.width=Z.width,B.height=Z.height;const G=B.getContext("2d");return b||(G.fillStyle=i.root.background,G.fillRect(0,0,B.width,B.height)),G.drawImage(Z,0,0),{canvas:B,resolution:f,canvasWidth:Z.width,canvasHeight:Z.height}};return{subscribe:dng,unsubscribe:hng,zoomTo:(d,h,m=0,f=1e3)=>{var b;const p=(b=A(d))==null?void 0:b.spec.assembly,Z=u7.fromString(h).toAbsoluteCoordinates(p,m),B=r(d);e.api.zoomTo(B,...Z,...Z,f)},zoomToExtent:(d,h=1e3)=>{var m;const f=(m=A(d))==null?void 0:m.spec.assembly,[b,p]=[0,bI(f).total],y=r(d);e.api.zoomTo(y,b,p,b,p,h)},zoomToGene:(d,h,m=0,f=1e3)=>{const b=r(d);e.api.zoomToGene(b,h,m,f)},suggestGene:(d,h,m)=>{const f=r(d);e.api.suggestGene(f,h,m)},getTrackIds:o,getTracksAndViews:a,getTracks:s,getTrack:A,getView:c,getViews:l,getCanvas:u,exportPng:d=>{const{canvas:h}=u({resolution:4,transparentBackground:d});h.toBlob(m=>{const f=document.createElement("a");document.body.append(f),f.download="gosling-visualization",f.href=URL.createObjectURL(m),f.click(),f.remove()},"image/png")},exportPdf:async d=>{const{jsPDF:h}=await s5e(()=>import("./jspdf.es.min-5cd5e647.js").then(p=>p.j),[]),{canvas:m}=u({resolution:4,transparentBackground:d}),f=m.toDataURL("image/jpeg",1),b=new h({orientation:m.width{I7(I)&&g.forEach(i=>{delete I[i]})})}const Kng=(e,g)=>{e.views.forEach(I=>{var i,n,C;const r=I.uid;if(!g.views.find(a=>a.uid===r)){const{locksByViewUid:a}=e.zoomLocks,s=a[r],A=(i=Object.entries(a).find(([c,u])=>c&&u===s))==null?void 0:i[0],l=!!g.views.find(c=>c.uid===A);A&&l&&(I.initialXDomain=(n=g.views.find(c=>c.uid===A))==null?void 0:n.initialXDomain,I.initialYDomain=(C=g.views.find(c=>c.uid===A))==null?void 0:C.initialYDomain)}})},xng=300,U2e=U.forwardRef((e,g)=>{var I,i,n;const[C,r]=U.useState(),[o,a]=U.useState({width:200,height:200}),s=U.useRef(),A=U.useRef(),l=U.useRef(),c=U.useRef([]),u=U.useRef({}),d=U.useRef(null),h=J2e(e.theme||"light"),m=(I=e.id)!=null?I:ln(),f=Z=>{const B=c.current.filter(V=>V.type=="view"),G=Z.filter(V=>V.type=="view"),v=new Set(B.map(V=>V.id));G.filter(V=>!v.has(V.id)).forEach(V=>{Hr("onNewView",{id:V.id})})};U.useImperativeHandle(g,()=>{const Z=Cce(d),B=Cce(c);return{api:Yng(Z,C,B,h,u.current),hgApi:Z}},[C,h]);const b=U.useCallback(()=>{if(e.spec){if(Ftg(e.spec).state==="error"){console.warn("Gosling spec is not valid. Please refer to the console message.");return}kng(e.spec,(B,G,v,w,V)=>{var S,X;if(l.current&&abe(nce(l.current,["linkingId"]),nce(v,["linkingId"])))return;(S=e.compiled)==null||S.call(e,e.spec,B,{_processedSpec:v}),a(G);const W=typeof C<"u";(X=e.experimental)!=null&&X.reactive&&W?setTimeout(()=>{var R,H;Kng(B,(R=d.current)==null?void 0:R.api.getViewConfig()),(H=d.current)==null||H.api.setViewConfig(B)},xng):r(B),f(w),l.current=v,c.current=w,u.current=V},[...Etg],h,{containerSize:s.current,containerParentSize:A.current},e.urlToFetchOptions)}},[e.spec,h]);U.useEffect(()=>{var Z;if(!((Z=e.spec)!=null&&Z.responsiveSize))return;const B=document.getElementById(m);if(!B)return;const G=new jse.ResizeSensor(B,V=>{(!s.current||s.current.height!==V.height||s.current.width!==V.width)&&(s.current=V,b())}),v=B.parentElement;if(!v)return;const w=new jse.ResizeSensor(v,V=>{(!A.current||A.current.height!==V.height||A.current.width!==V.width)&&(A.current=V,b())});return()=>{G.detach(),w.detach()}}),U.useEffect(()=>{b()},[e.spec,h]);const p=typeof((i=e.spec)==null?void 0:i.responsiveSize)!="object"?(n=e.spec)==null?void 0:n.responsiveSize:e.spec.responsiveSize.height;return U.useMemo(()=>{var Z,B,G;return N.createElement(L2e,{ref:d,viewConfig:C,size:o,id:m,className:e.className,options:{padding:e.padding,border:e.border,margin:e.margin,responsiveWidth:typeof((Z=e.spec)==null?void 0:Z.responsiveSize)!="object"?(B=e.spec)==null?void 0:B.responsiveSize:e.spec.responsiveSize.width,responsiveHeight:p,background:h.root.background,alt:(G=e.spec)==null?void 0:G.description}})},[C,o,h,p])});U2e.displayName="GoslingComponent";function Cce(e){return new Proxy({},{get(g,I,i){if(!e.current)throw Error("ref is not set!");return Reflect.get(e.current,I,i)}})}var rce=jI;rce.createRoot,rce.hydrateRoot;const Dng=["x","xe","x1","x1e","y","ye","y1","y1e","color","size","row","stroke","strokeWidth","opacity","text"];function Fng(e){return typeof e=="object"&&e!==null}function Eng(e){return"alignment"in e&&e.alignment==="overlay"}function Mng(e){return"_overlay"in e}function zng(e){return e!==null&&typeof e=="object"&&"value"in e}function Png(e){return Fng(e)&&!("value"in e)}function oce(e,g){return g in e}function Ec(e){return e.length===1?e[0]:e.slice(0,-1).join(", ")+" and "+e.slice(-1)}function bG(e){return e[0].toUpperCase()+e.slice(1)}const _n=new Map([["point","points"],["line","lines"],["bar","bars"],["rect","rectangles"],["area","area displayed"],["withinLink","connections"],["betweenLink","connections"],["triangleLeft","triangles"],["triangleRight","triangles"],["triangleBottom","triangles"]]),LA=new Map([["y","height"],["color","color"],["strokeWidth","stroke width"],["opacity","opacity"],["text","text"]]);function Jng(e){return e.includes("chr")&&(e=e.replace("chr","")),e}function Q2e(e,g){let I;Array.isArray(e.appearance.details.mark)?I=e.appearance.details.mark[g]:I=e.appearance.details.mark;const i=e.appearance.details.encodings.encodingDeepGenomic.map(r=>r.name),n=e.appearance.details.encodings.encodingDeepQuantitative.map(r=>r.name),C=e.appearance.details.encodings.encodingDeepNominal.map(r=>r.name);if(I==="point"&&n.includes("x")&&n.includes("y"))return"scatter plot";if(I==="line"&&i.includes("x")&&n.includes("y")||I==="line"&&n.includes("x")&&i.includes("y"))return"line chart";if(I==="bar"&&i.includes("x")&&n.includes("y"))return"bar chart";if(I==="rect"&&i.includes("x")&&i.includes("xe")&&n.includes("color"))return"heat map";if(I==="rect"&&i.includes("x")&&i.includes("xe")&&C.includes("color"))return"ideogram"}function Ong(e){const g={};g.tracks={},g.title=e.title,g.subtitle=e.subtitle;const I={nTracks:0,rowViews:0,colViews:0,allPositions:[[0,0]],totalRows:0,totalCols:0,matrix:{}},i={};i.arrangement="vertical",i.layout="linear",j2e(e,g,i,I),$ng(I);const n={description:"",nTracks:I.nTracks,parentValues:i,counter:I};return g.composition=n,g.alt="",g.longDescription="",g}function j2e(e,g,I,i){if("tracks"in e){const n=ace(e,I);if(e.tracks.length>1)if(Eng(e)){const C=e;g.tracks[i.nTracks]=Ung(C,n,i),i.nTracks>0&&(i.allPositions=[...i.allPositions,[i.rowViews,i.colViews]]),i.nTracks++}else for(const C in e.tracks){const r=e.tracks[C];g.tracks[i.nTracks]=l_(r,n,i),i.nTracks>0&&(i.allPositions=[...i.allPositions,[i.rowViews,i.colViews]]),i.nTracks++}else{if(Mng(e.tracks[0])){const C=e.tracks[0];g.tracks[i.nTracks]=Lng(C,I,i)}else{const C=e.tracks[0];g.tracks[i.nTracks]=l_(C,I,i)}i.nTracks>0&&(i.allPositions=[...i.allPositions,[i.rowViews,i.colViews]]),i.nTracks++}}else if("views"in e){const n=i.rowViews,C=i.colViews;e.views.forEach((r,o)=>{o!==0&&(I.arrangement==="vertical"||I.arrangement==="parallel"?i.rowViews++:i.colViews++);const a=ace(r,I);j2e(r,g,a,i)}),I.arrangement==="vertical"||I.arrangement==="parallel"?i.rowViews=n:i.colViews=C}}function ace(e,g){const I=JSON.parse(JSON.stringify(g));return oce(e,"arrangement")&&(I.arrangement=e.arrangement),oce(e,"layout")&&(I.layout=e.layout),I}function l_(e,g,I){const i={};i.alttype="single";let n;e.id!=="unknown"?n=e.id:n="";const C={trackNumber:I.nTracks,rowNumber:I.rowViews,colNumber:I.colViews},r={};r.assembly=e.assembly,r.layout=g.layout,r.overlaid=!1,r.mark=e.mark,r.encodings=q2e(e);const o=$2e(e.data,r.encodings),a={data:e.data,fields:o},s={description:"",details:C},A={description:"",details:r},l={description:"",details:a};return i.uid=n,i.position=s,i.appearance=A,i.title=e.title,i.data=l,i.charttype=Q2e(i),i.description="",i}function _ng(e,g,I){let i={...e,...e._overlay[0]};return delete i._overlay,delete i.overlayOnPreviousTrack,i=i,l_(i,g,I)}function Lng(e,g,I){return _ng(e,g,I)}function Ung(e,g,I){let i=Qbe(e);return i=mbe(i),Qng(e,i,g,I)}function Qng(e,g,I,i){const n={};n.alttype="ov-data";const C={trackNumber:i.nTracks,rowNumber:i.rowViews,colNumber:i.colViews},r=[],o=[];for(const s of g){const A=s;let l;A.id!=="unknown"?l=A.id:l="",r.push(l),o.push(jng(A,I))}const a={description:"",details:C};return n.position=a,n.title=e.title,n.appearance={details:{layout:"linear"}},n.tracks=o,n.uids=r,n.description="",n}function jng(e,g,I){const i={},n={};n.assembly=e.assembly,n.layout=g.layout,n.overlaid=!1,n.mark=e.mark,n.encodings=q2e(e);const C=$2e(e.data,n.encodings),r={data:e.data,fields:C},o={description:"",details:n},a={description:"",details:r};return i.appearance=o,i.data=a,i.charttype=Q2e(i),i.description="",i}function $2e(e,g){const I={};return g.encodingDeepGenomic.length>0&&(g.encodingDeepGenomic[0].details.field?I.genomicField=g.encodingDeepGenomic[0].details.field:I.genomicField),g.encodingDeepQuantitative.length>0&&(g.encodingDeepQuantitative[0].details.field?I.valueField=g.encodingDeepQuantitative[0].details.field:I.valueField),g.encodingDeepNominal.length>0&&(g.encodingDeepNominal[0].details.field?I.categoryField=g.encodingDeepNominal[0].details.field:I.categoryField),I}function q2e(e){const g=[],I=[],i=[],n=[];return Dng.forEach(r=>{const o=e[r];Png(o)?o.type==="genomic"?g.push({name:r,description:"",details:o}):o.type==="quantitative"?I.push({name:r,description:"",details:o}):i.push({name:r,description:"",details:o}):zng(o)&&n.push({name:r,description:"",details:o})}),{encodingDeepGenomic:g,encodingDeepQuantitative:I,encodingDeepNominal:i,encodingValue:n}}function $ng(e){e.totalRows=Math.max(...e.allPositions.map(I=>I[0]))+1,e.totalCols=Math.max(...e.allPositions.map(I=>I[1]))+1;const g={};for(let I=0;IC[0]===I).map(C=>C[1]),n={};for(const C of i)n[C]?n[C]=n[C]+1:n[C]=1;g[I]=n}e.matrix=g}function qng(e){eCg(e),ICg(e)}function eCg(e){e.composition.nTracks==1?(e.tracks[0].position.description="This is the only track.",e.tracks[0].alttype==="single"?e.composition.description="There is one ("+e.tracks[0].appearance.details.layout+") track.":e.composition.description="There is one (overlaid) track."):e.composition.nTracks==2?tCg(e):gCg(e)}function tCg(e){let g="",I="",i="";if(e.tracks[0].appearance.details.layout==="circular"&&e.tracks[1].appearance.details.layout==="circular")switch(e.composition.parentValues.arrangement){case"serial":g="left half of ring",I="right half of ring",i="Two circular tracks form one ring, with both the half of the ring.";break;case"parallel":g="outer ring",I="inner ring",i="Two circular tracks form two rings, one around the other.";break;case"horizontal":g="left",I="right",i="Two circular tracks are shown next to each other.";break;default:g="top",I="bottom",i="Two circular tracks are shown below each other."}else{const n=e.tracks[0].appearance.details.layout===e.tracks[1].appearance.details.layout;switch(e.composition.parentValues.arrangement){case"serial":g="left",I="right",i=" are shown next to each other.";break;default:g="top",I="bottom",i="are shown below each other."}n?i="".concat("Two linear tracks ",i):i="".concat("One linear and one circular track ",i)}e.tracks[0].position.description=g,e.tracks[1].position.description=I,e.composition.description=i}function gCg(e){const g=["first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth"];let I="";if(e.composition.counter.totalRows===1)I=I.concat("There are "+e.composition.counter.nTracks+" tracks, displayed next to each other.");else if(e.composition.counter.totalCols===1)I=I.concat("There are "+e.composition.counter.nTracks+" tracks, displayed below each other.");else{I=I.concat("There are "+e.composition.counter.nTracks+" tracks."),I=I.concat(" There are "+e.composition.counter.totalRows+" rows.");const i=Object.keys(e.composition.counter.matrix).map(C=>Object.keys(e.composition.counter.matrix[C]).length),n=[...new Set(i)];if(n.length==1)I=I.concat(" Each row has "+n[0]+" tracks next to each other");else if(n.length==2){const C=[],r=[];for(let o=0;oo+1))+" have "+n[0]+" column(s) each."),I=I.concat(" The other rows have "+n[1]+" column(s) each.")):(I=I.concat(" Row(s) "+Ec(r.map(o=>o+1))+" have "+n[1]+" column(s) each."),I=I.concat(" The other rows have "+n[0]+" column(s) each."))}else for(let C=0;C9?I=I.concat(" Row number "+C+" has "+e.composition.counter.matrix[C].length+" track(s) next to each other."):I=I.concat(" The "+g[C]+" row has "+e.composition.counter.matrix[C].length+" track(s) next to each other.")}e.composition.description=I;for(const i in e.tracks){let n="";const C=e.tracks[i].position.details,r=e.composition.counter;e.composition.counter.totalRows>1&&(C.rowNumber===0?n=n.concat("top row"):C.rowNumber===r.totalRows-1?n=n.concat("bottom row"):C.rowNumber<10?n=n.concat(g[C.rowNumber]+" row"):n=n.concat("row "+C.rowNumber+1)),e.composition.counter.totalCols>1&&(n.length>1&&(n=n.concat(", ")),r.matrix[C.rowNumber].length>1&&(C.colNumber===1?n=n.concat("left"):C.colNumber===r.matrix[C.rowNumber].length?n=n.concat("right"):C.colNumber===2&&r.matrix[C.rowNumber].length===3?n=n.concat("middle"):n=n.concat(g[C.colNumber]+" from left"))),e.tracks[i].position.description=n}}function ICg(e){for(const g in e.tracks){const I=e.tracks[g];if(I.alttype==="single"){let i="";I.charttype?i=i.concat(bG(I.charttype)+"."):i=i.concat("Chart with "+_n.get(I.appearance.details.mark)+".");const n=iCg(I);i=i.concat(" "+n.desc),I.appearance.description=i,I.appearance.details.encodingsDescList=n.descList}else I.alttype==="ov-mark"&&(I.appearance.details.encodingsDescList=[[]])}}function iCg(e){const g=e.appearance.details.mark;let I="",i="",n="",C="";const r=[],o=e.appearance.details.encodings.encodingDeepGenomic.map(l=>l.name);if(o.includes("x")&&o.includes("y"))I=I.concat("The genome is shown on both the x- and y-axes."),o.includes("xe")&&o.includes("ye")?(I=I.concat(" Each displays genomic intervals."),r.push(["x","The x-axis show genomic intervals."]),r.push(["y","The y-axis show genomic intervals."])):o.includes("xe")?(I=I.concat(" The genome on the x-axis displays genomic intervals."),r.push(["x","The x-axis show genomic intervals."]),r.push(["y","The y-axis shows the genome."])):o.includes("ye")?(I=I.concat(" The genome on the y-axis displays genomic intervals."),r.push(["x","The x-axis shows the genome."]),r.push(["y","The y-axis show genomic intervals."])):(r.push(["x","The x-axis shows the genome."]),r.push(["y","The y-axis shows the genome."]));else{if(o.includes("x")){let l="";o.includes("xe")?(l="in intervals",r.push(["x","The x-axis show genomic intervals."])):r.push(["x","The x-axis shows the genome."]),I=I.concat("The genome is shown "+l+" on the x-axis.")}if(o.includes("y")){let l="";o.includes("ye")?(l="in intervals",r.push(["y","The y-axis show genomic intervals."])):r.push(["y","The y-axis shows the genome."]),I=I.concat("The genome is shown "+l+" on the y-axis.")}}const a=e.appearance.details.encodings.encodingDeepQuantitative.map(l=>l.name);if(a.length>1){i=i.concat("The expression values are shown with "+_n.get(g)+" on the "+Ec(a)+"-axes.");for(const l of a)r.push([l,"The "+l+" of the "+_n.get(g)+" shows the expression values."])}else a.length===1&&(a.includes("y")?(i=i.concat("The expression is shown on the y-axis with "+_n.get(g)+"."),r.push(["y","The y-axis shows the expression with"+_n.get(g)+"."])):a.includes("color")?(i=i.concat("The height of the expression values is shown with color."),r.push(["color","The color of the "+_n.get(g)+" shows the expression values."])):(i=i.concat("The height of the expression values is shown with the "+a[0]+"-axis."),r.push([LA.get(a[0]),"The "+LA.get(a[0])+" of the "+_n.get(g)+" shows the expression values."])));const s=e.appearance.details.encodings.encodingDeepNominal.map(l=>l.name);if(s.length>1)if(s.includes("row")){n=n.concat("The chart is stratified by rows for the categories.");const l=s.filter(c=>c!=="row").map(c=>LA.get(c));n=n.concat(" The categories are also shown with the "+Ec(l)+" of the "+_n.get(g)+"."),r.push(["row","The chart is stratified by rows for the categories."]);for(const c of l)r.push([LA.get(c),"The "+c+" of the "+_n.get(g)+" show the different categories."])}else{const l=s.map(c=>LA.get(c));n=n.concat("The categories are shown with the "+Ec(l)+" of the "+_n.get(g)+".");for(const c of s)r.push([LA.get(c),"The "+c+" of the "+_n.get(g)+" show the different categories."])}else s.length==1&&(s.includes("row")?(n=n.concat("The chart is stratified by rows for the categories."),r.push(["row","The chart is stratified by rows for the categories."])):(n=n.concat("The "+LA.get(s[0])+" of the "+_n.get(g)+" indicates the different categories."),r.push([LA.get(s[0]),"The "+LA.get(s[0])+" of the "+_n.get(g)+" show the different categories."])));for(let l=0;lNv(n,I)))}.`):i=i.concat(` The ${g} value is shown at ${e.length} different genomic positions, the first being ${Nv(e[0],I)}.`),i}function c_(e,g){const I=Uu(e,g);return[Jng(I.chromosome),I.position]}function Nv(e,g){const I=c_(e,g);return I[0]==="unknown"?`absolute position ${I[1]} (on the unmapped part of the genome)`:`chromosome ${I[0]} position ${I[1]}`}function eHe(e,g,I){const i=c_(e,I),n=c_(g,I);return i[0]==="unknown"&&n[0]=="unknown"?` The genomic range is shown from from absolute position ${i[1]} to ${n[1]} on an unmapped part of the genome.`:n[0]==="unknown"?(i[0]==="chr1"||i[0]===1)&&i[1]===0?" The full genome is shown.":i[0]==="chrX"||i[0]==="X"?` The genomic range shown is chromomosome X (from position ${i[1]}), Y and an unmapped part of the genome at the end.`:i[0]==="chrY"||i[0]==="Y"?` The genomic range shown is chromomosome Y (from position ${i[1]}) and an unmapped part of the genome at the end.`:` The genomic range is shown from chromosome ${i[0]} to chromosome 22 and the X and Y chromosomes, as well as an unmapped part of the genome at the end.`:i===n?` The genomic range is shown from position ${i[1]} to position ${n[1]} on chromosome ${i[0]}.`:` The genomic range is shown from chromosome ${i[0]} position ${i[1]} to chromosome ${n[0]} position ${n[1]}.`}function tHe(e){var g,I,i,n,C,r,o,a,s,A,l,c,u,d,h,m,f,b;if((e.alttype==="single"||e.alttype==="ov-mark")&&e.data.details.dataStatistics){let p="";const y=e.appearance.details.assembly;if(((g=e.data.details.dataStatistics)==null?void 0:g.genomicMin)!==void 0&&((I=e.data.details.dataStatistics)==null?void 0:I.genomicMax)!==void 0){const Z=eHe(e.data.details.dataStatistics.genomicMin,e.data.details.dataStatistics.genomicMax,y),B=Nv((i=e.data.details.dataStatistics)==null?void 0:i.genomicMin,y),G=Nv((n=e.data.details.dataStatistics)==null?void 0:n.genomicMax,y);e.data.details.dataStatistics.genomicDescList=[["Minimum",B],["Maximum",G]],p=p.concat(Z)}if(((C=e.data.details.dataStatistics)==null?void 0:C.valueMin)!==void 0&&((r=e.data.details.dataStatistics)==null?void 0:r.valueMax)!==void 0){const Z=(o=e.data.details.dataStatistics)==null?void 0:o.valueMin,B=(a=e.data.details.dataStatistics)==null?void 0:a.valueMax;if(p=p.concat(` The expression values range from ${Z} to ${B}.`),(s=e.data.details.dataStatistics)!=null&&s.valueMaxGenomic&&((A=e.data.details.dataStatistics)!=null&&A.valueMinGenomic)){const G=Ace((l=e.data.details.dataStatistics)==null?void 0:l.valueMinGenomic,"minimum",y),v=Ace((c=e.data.details.dataStatistics)==null?void 0:c.valueMaxGenomic,"maximum",y);p=p.concat(v,G),e.data.details.dataStatistics.valueDescList=[["Minimum",`${Z}. ${G}`],["Maximum",`${B}. ${v}`]]}else e.data.details.dataStatistics.valueDescList=[["Minimum",`${Z}`],["Maximum",`${B}`]]}(u=e.data.details.dataStatistics)!=null&&u.categories&&(p=p.concat(` There are ${(d=e.data.details.dataStatistics)==null?void 0:d.categories.length} categories.`),(h=e.data.details.dataStatistics)!=null&&h.highestCategory&&(((m=e.data.details.dataStatistics)==null?void 0:m.highestCategory.length)===1?p=p.concat(` The highest value is observed in sample ${(f=e.data.details.dataStatistics)==null?void 0:f.highestCategory[0]}.`):p=p.concat(` The highest value is observed in samples ${Ec((b=e.data.details.dataStatistics)==null?void 0:b.highestCategory)}.`))),e.data.description=p}}function q$(e,g){if(g!==!1&&CCg(e),e.alt="Gosling visualization.",e.composition.nTracks===1)e.longDescription=e.tracks[0].description,e.alt=e.longDescription.split(".")[0];else if(e.composition.nTracks===2){let I="",i="";i=i.concat("Figure with two charts.");const n=e.tracks[0].description.split("."),C=n[0],r=n.slice(1).join("."),o=e.tracks[0].description.split("."),a=o[0],s=o.slice(1).join(".");i=i.concat(` ${bG(e.tracks[0].position.description)} track is a ${C.toLowerCase()}. ${r}`),i=i.concat(` ${bG(e.tracks[1].position.description)} track is a ${a.toLowerCase()}. ${s}`),I=I.concat(` Figure with ${C.toLowerCase()} on ${bG(e.tracks[0].position.description)} and ${a.toLowerCase()} on ${bG(e.tracks[1].position.description)}`),e.alt=I,e.longDescription=i}else{let I="";const i=[];for(const n in Object.keys(e.tracks)){const C=e.tracks[n].description.split(".")[0];i.push(C)}I=I.concat(`Figure with ${e.composition.nTracks} individual charts. Briefly, these are a ${Ec(i).toLowerCase()}.`),e.alt=`Gosling visualization with ${e.composition.nTracks} individual charts.`,e.longDescription=I}}function CCg(e){if(Object.keys(e.tracks).length===1)u_(e.tracks[0],!1);else for(const g in Object.keys(e.tracks))u_(e.tracks[g],!0)}function u_(e,g){let I="",i="";e.alttype==="single"||e.alttype==="ov-mark"?(g&&(i=i.concat(e.position.description)),I=i.concat(` ${e.appearance.description} ${e.data.description}`)):(g&&i.concat(e.position.description),I=i.concat(" Overlaid track with different data sources. See individual tracks for details.")),e.description=I}function rCg(e){qng(e),q$(e)}function oCg(e){nCg(e),q$(e)}function aCg(e,g,I){const i={id:e,flatTileData:g};if(I){if(I.genomicField!==void 0){const n=I.genomicField;try{const C=g.map(r=>r[n]).filter(r=>!isNaN(r));i.genomicMin=Math.min(...C),i.genomicMax=Math.max(...C)}catch(C){console.log(C)}}if(I.valueField!==void 0){const n=I.valueField;try{const C=g.map(r=>r[n]).filter(r=>!isNaN(r));i.valueMin=Math.min(...C),i.valueMax=Math.max(...C)}catch(C){console.log(C)}}if(I.genomicField!==void 0&&I.valueField!==void 0){const n=I.genomicField,C=I.valueField;try{i.valueMinGenomic=g.filter(r=>r[C]==i.valueMin).map(r=>r[n]),i.valueMaxGenomic=g.filter(r=>r[C]==i.valueMax).map(r=>r[n])}catch(r){console.log(r)}}if(I.categoryField!==void 0){const n=I.genomicField,C=I.valueField,r=I.categoryField;try{const o=g.map(l=>l[r]),a=[...new Set(o)],s={},A=[];for(const l of a){const c=g.filter(b=>b[r]===l),u=c.map(b=>b[C]).filter(b=>!isNaN(b)),d=Math.min(...u),h=Math.max(...u),m=c.filter(b=>b[C]==d).map(b=>b[n]),f=c.filter(b=>b[C]==h).map(b=>b[n]);s[l]=[d,m,h,f],h===i.valueMax&&A.push(l)}i.categories=a,i.categoryMinMaxWG=s,i.highestCategory=A}catch(o){console.log(o)}}return i}else return i}function ACg(e,g,I){const i=e.tracks.length>1;for(let n=0;n{let s=C.current;s!==r&&console.warn(`WARN: A component changed from ${s?"controlled":"uncontrolled"} to ${r?"controlled":"uncontrolled"}.`),C.current=r},[r]);let o=r?e:i,a=U.useCallback((s,...A)=>{let l=(c,...u)=>{I&&(Object.is(o,c)||I(c,...u)),r||(o=c)};typeof s=="function"?(console.warn("We can not support a function callback. See Github Issues for details https://github.com/adobe/react-spectrum/issues/2320"),n((u,...d)=>{let h=s(r?o:u,...d);return l(h,...A),r?u:h})):(r||n(s),l(s,...A))},[r,o,I]);return[o,a]}const WH={prefix:String(Math.round(Math.random()*1e10)),current:0},IHe=N.createContext(WH),uCg=N.createContext(!1);let dCg=!!(typeof window<"u"&&window.document&&window.document.createElement),YF=new WeakMap;function hCg(e=!1){let g=U.useContext(IHe),I=U.useRef(null);if(I.current===null&&!e){var i,n;let C=(n=N.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED)===null||n===void 0||(i=n.ReactCurrentOwner)===null||i===void 0?void 0:i.current;if(C){let r=YF.get(C);r==null?YF.set(C,{id:g.current,state:C.memoizedState}):C.memoizedState!==r.state&&(g.current=r.id,YF.delete(C))}I.current=++g.current}return I.current}function mCg(e){let g=U.useContext(IHe);g===WH&&!dCg&&console.warn("When server rendering, you must wrap your application in an to ensure consistent ids are generated between the client and server.");let I=hCg(!!e),i=`react-aria${g.prefix}`;return e||`${i}-${I}`}function fCg(e){let g=N.useId(),[I]=U.useState(kw()),i=I?"react-aria":`react-aria${WH.prefix}`;return e||`${i}-${g}`}const pCg=typeof N.useId=="function"?fCg:mCg;function bCg(){return!1}function yCg(){return!0}function ZCg(e){return()=>{}}function kw(){return typeof N.useSyncExternalStore=="function"?N.useSyncExternalStore(ZCg,bCg,yCg):U.useContext(uCg)}function iHe(e){var g,I,i="";if(typeof e=="string"||typeof e=="number")i+=e;else if(typeof e=="object")if(Array.isArray(e))for(g=0;g{};function ar(e){const g=U.useRef(null);return bi(()=>{g.current=e},[e]),U.useCallback((...I)=>{const i=g.current;return i(...I)},[])}function vCg(e){let[g,I]=U.useState(e),i=U.useRef(null),n=ar(()=>{let r=i.current.next();if(r.done){i.current=null;return}g===r.value?n():I(r.value)});bi(()=>{i.current&&n()});let C=ar(r=>{i.current=r(g),n()});return[g,C]}let BCg=!!(typeof window<"u"&&window.document&&window.document.createElement),XH=new Map;function Fh(e){let[g,I]=U.useState(e),i=U.useRef(null),n=pCg(g),C=U.useCallback(r=>{i.current=r},[]);return BCg&&XH.set(n,C),bi(()=>{let r=n;return()=>{XH.delete(r)}},[n]),U.useEffect(()=>{let r=i.current;r&&(i.current=null,I(r))}),n}function SCg(e,g){if(e===g)return e;let I=XH.get(e);if(I)return I(g),g;let i=XH.get(g);return i?(i(e),e):g}function sce(e=[]){let g=Fh(),[I,i]=vCg(g),n=U.useCallback(()=>{i(function*(){yield g,yield document.getElementById(g)?g:void 0})},[g,i]);return bi(n,[g,n,...e]),I}function wCg(...e){return(...g)=>{for(let I of e)typeof I=="function"&&I(...g)}}const Cc=e=>{var g;return(g=e==null?void 0:e.ownerDocument)!==null&&g!==void 0?g:document},HH=e=>e&&"window"in e&&e.window===e?e:Cc(e).defaultView||window;function Gi(...e){let g={...e[0]};for(let I=1;I=65&&n.charCodeAt(2)<=90?g[n]=wCg(C,r):(n==="className"||n==="UNSAFE_className")&&typeof C=="string"&&typeof r=="string"?g[n]=GCg(C,r):n==="id"&&C&&r?g.id=SCg(C,r):g[n]=r!==void 0?r:C}}return g}function VCg(...e){return e.length===1?e[0]:g=>{for(let I of e)typeof I=="function"?I(g):I!=null&&(I.current=g)}}const RCg=new Set(["id"]),WCg=new Set(["aria-label","aria-labelledby","aria-describedby","aria-details"]),XCg=new Set(["href","target","rel","download","ping","referrerPolicy"]),HCg=/^(data-.*)$/;function YA(e,g={}){let{labelable:I,isLink:i,propNames:n}=g,C={};for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&(RCg.has(r)||I&&WCg.has(r)||i&&XCg.has(r)||n!=null&&n.has(r)||HCg.test(r))&&(C[r]=e[r]);return C}function vs(e){if(TCg())e.focus({preventScroll:!0});else{let g=NCg(e);e.focus(),kCg(g)}}let r1=null;function TCg(){if(r1==null){r1=!1;try{var e=document.createElement("div");e.focus({get preventScroll(){return r1=!0,!0}})}catch{}}return r1}function NCg(e){for(var g=e.parentNode,I=[],i=document.scrollingElement||document.documentElement;g instanceof HTMLElement&&g!==i;)(g.offsetHeight"u"||window.navigator==null?!1:((g=window.navigator.userAgentData)===null||g===void 0?void 0:g.brands.some(I=>e.test(I.brand)))||e.test(window.navigator.userAgent)}function t8(e){var g;return typeof window<"u"&&window.navigator!=null?e.test(((g=window.navigator.userAgentData)===null||g===void 0?void 0:g.platform)||window.navigator.platform):!1}function Eh(){return t8(/^Mac/i)}function YCg(){return t8(/^iPhone/i)}function nHe(){return t8(/^iPad/i)||Eh()&&navigator.maxTouchPoints>1}function g8(){return YCg()||nHe()}function KCg(){return Eh()||g8()}function xCg(){return $k(/AppleWebKit/i)&&!DCg()}function DCg(){return $k(/Chrome/i)}function TH(){return $k(/Android/i)}function FCg(){return $k(/Firefox/i)}const ECg=U.createContext({isNative:!0,open:zCg});function CHe(){return U.useContext(ECg)}function Mh(e,g,I=!0){var i,n;let{metaKey:C,ctrlKey:r,altKey:o,shiftKey:a}=g;FCg()&&(!((n=window.event)===null||n===void 0||(i=n.type)===null||i===void 0)&&i.startsWith("key"))&&e.target==="_blank"&&(Eh()?C=!0:r=!0);let s=xCg()&&Eh()&&!nHe()?new KeyboardEvent("keydown",{keyIdentifier:"Enter",metaKey:C,ctrlKey:r,altKey:o,shiftKey:a}):new MouseEvent("click",{metaKey:C,ctrlKey:r,altKey:o,shiftKey:a,bubbles:!0,cancelable:!0});Mh.isOpening=I,vs(e),e.dispatchEvent(s),Mh.isOpening=!1}Mh.isOpening=!1;function MCg(e,g){if(e instanceof HTMLAnchorElement)g(e);else if(e.hasAttribute("data-href")){let I=document.createElement("a");I.href=e.getAttribute("data-href"),e.hasAttribute("data-target")&&(I.target=e.getAttribute("data-target")),e.hasAttribute("data-rel")&&(I.rel=e.getAttribute("data-rel")),e.hasAttribute("data-download")&&(I.download=e.getAttribute("data-download")),e.hasAttribute("data-ping")&&(I.ping=e.getAttribute("data-ping")),e.hasAttribute("data-referrer-policy")&&(I.referrerPolicy=e.getAttribute("data-referrer-policy")),e.appendChild(I),g(I),e.removeChild(I)}}function zCg(e,g){MCg(e,I=>Mh(I,g))}function PCg(e){return{"data-href":e.href,"data-target":e.target,"data-rel":e.rel,"data-download":e.download,"data-ping":e.ping,"data-referrer-policy":e.referrerPolicy}}let Ff=new Map,d_=new Set;function lce(){if(typeof window>"u")return;let e=I=>{let i=Ff.get(I.target);i||(i=new Set,Ff.set(I.target,i),I.target.addEventListener("transitioncancel",g)),i.add(I.propertyName)},g=I=>{let i=Ff.get(I.target);if(i&&(i.delete(I.propertyName),i.size===0&&(I.target.removeEventListener("transitioncancel",g),Ff.delete(I.target)),Ff.size===0)){for(let n of d_)n();d_.clear()}};document.body.addEventListener("transitionrun",e),document.body.addEventListener("transitionend",g)}typeof document<"u"&&(document.readyState!=="loading"?lce():document.addEventListener("DOMContentLoaded",lce));function rHe(e){requestAnimationFrame(()=>{Ff.size===0?e():d_.add(e)})}function oHe(){let e=U.useRef(new Map),g=U.useCallback((n,C,r,o)=>{let a=o!=null&&o.once?(...s)=>{e.current.delete(r),r(...s)}:r;e.current.set(r,{type:C,eventTarget:n,fn:a,options:o}),n.addEventListener(C,r,o)},[]),I=U.useCallback((n,C,r,o)=>{var a;let s=((a=e.current.get(r))===null||a===void 0?void 0:a.fn)||r;n.removeEventListener(C,s,o),e.current.delete(r)},[]),i=U.useCallback(()=>{e.current.forEach((n,C)=>{I(n.eventTarget,n.type,C,n.options)})},[I]);return U.useEffect(()=>i,[i]),{addGlobalListener:g,removeGlobalListener:I,removeAllGlobalListeners:i}}function JCg(e,g){let{id:I,"aria-label":i,"aria-labelledby":n}=e;return I=Fh(I),n&&i?n=[...new Set([I,...n.trim().split(/\s+/)])].join(" "):n&&(n=n.trim().split(/\s+/).join(" ")),!i&&!n&&g&&(i=g),{id:I,"aria-label":i,"aria-labelledby":n}}function Yw(e){const g=U.useRef();return U.useMemo(()=>({get current(){return g.current},set current(I){g.current=I,typeof e=="function"?e(I):e&&(e.current=I)}}),[e])}function aHe(e,g){const I=U.useRef(!0),i=U.useRef(null);U.useEffect(()=>(I.current=!0,()=>{I.current=!1}),[]),U.useEffect(()=>{I.current?I.current=!1:(!i.current||g.some((n,C)=>!Object.is(n,i[C])))&&e(),i.current=g},g)}function AHe(e,g){bi(()=>{if(e&&e.ref&&g)return e.ref.current=g.current,()=>{e.ref.current=null}})}function _l(e){for(NH(e)&&(e=e.parentElement);e&&!NH(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}function NH(e){let g=window.getComputedStyle(e);return/(auto|scroll)/.test(g.overflow+g.overflowX+g.overflowY)}let OCg=0;const KF=new Map;function qk(e){let[g,I]=U.useState(void 0);return bi(()=>{if(!e)return;let i=KF.get(e);if(i)I(i.element.id);else{let n=`react-aria-description-${OCg++}`;I(n);let C=document.createElement("div");C.id=n,C.style.display="none",C.textContent=e,document.body.appendChild(C),i={refCount:0,element:C},KF.set(e,i)}return i.refCount++,()=>{--i.refCount===0&&(i.element.remove(),KF.delete(e))}},[e]),{"aria-describedby":e?g:void 0}}function _Cg(e,g,I,i){let n=ar(I),C=I==null;U.useEffect(()=>{if(C)return;let r=e.current;return r.addEventListener(g,n,i),()=>{r.removeEventListener(g,n,i)}},[e,g,i,C,n])}function sHe(e,g){let I=cce(e,g,"left"),i=cce(e,g,"top"),n=g.offsetWidth,C=g.offsetHeight,r=e.scrollLeft,o=e.scrollTop,{borderTopWidth:a,borderLeftWidth:s}=getComputedStyle(e),A=e.scrollLeft+parseInt(s,10),l=e.scrollTop+parseInt(a,10),c=A+e.clientWidth,u=l+e.clientHeight;I<=r?r=I-parseInt(s,10):I+n>c&&(r+=I+n-c),i<=l?o=i-parseInt(a,10):i+C>u&&(o+=i+C-u),e.scrollLeft=r,e.scrollTop=o}function cce(e,g,I){const i=I==="left"?"offsetLeft":"offsetTop";let n=0;for(;g.offsetParent&&(n+=g[i],g.offsetParent!==e);){if(g.offsetParent.contains(e)){n-=e[i];break}g=g.offsetParent}return n}function Ll(e,g){if(document.contains(e)){let r=document.scrollingElement||document.documentElement;if(window.getComputedStyle(r).overflow==="hidden"){let a=_l(e);for(;e&&a&&e!==r&&a!==r;)sHe(a,e),e=a,a=_l(e)}else{var I;let{left:a,top:s}=e.getBoundingClientRect();e==null||(I=e.scrollIntoView)===null||I===void 0||I.call(e,{block:"nearest"});let{left:A,top:l}=e.getBoundingClientRect();if(Math.abs(a-A)>1||Math.abs(s-l)>1){var i,n,C;g==null||(n=g.containingElement)===null||n===void 0||(i=n.scrollIntoView)===null||i===void 0||i.call(n,{block:"center",inline:"center"}),(C=e.scrollIntoView)===null||C===void 0||C.call(e,{block:"nearest"})}}}}function h_(e){return e.mozInputSource===0&&e.isTrusted?!0:TH()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function LCg(e){return!TH()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function UCg(e,g,I){let i=U.useRef(g),n=ar(()=>{I&&I(i.current)});U.useEffect(()=>{var C;let r=e==null||(C=e.current)===null||C===void 0?void 0:C.form;return r==null||r.addEventListener("reset",n),()=>{r==null||r.removeEventListener("reset",n)}},[e,n])}function QCg(e,g){return g.get?g.get.call(e):g.value}function lHe(e,g,I){if(!g.has(e))throw new TypeError("attempted to "+I+" private field on non-instance");return g.get(e)}function jCg(e,g){var I=lHe(e,g,"get");return QCg(e,I)}function $Cg(e,g){if(g.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}function qCg(e,g,I){$Cg(e,g),g.set(e,I)}function erg(e,g,I){if(g.set)g.set.call(e,I);else{if(!g.writable)throw new TypeError("attempted to set read only private field");g.value=I}}function uce(e,g,I){var i=lHe(e,g,"set");return erg(e,i,I),I}let cp="default",m_="",KW=new WeakMap;function dce(e){if(g8()){if(cp==="default"){const g=Cc(e);m_=g.documentElement.style.webkitUserSelect,g.documentElement.style.webkitUserSelect="none"}cp="disabled"}else(e instanceof HTMLElement||e instanceof SVGElement)&&(KW.set(e,e.style.userSelect),e.style.userSelect="none")}function o1(e){if(g8()){if(cp!=="disabled")return;cp="restoring",setTimeout(()=>{rHe(()=>{if(cp==="restoring"){const g=Cc(e);g.documentElement.style.webkitUserSelect==="none"&&(g.documentElement.style.webkitUserSelect=m_||""),m_="",cp="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&KW.has(e)){let g=KW.get(e);e.style.userSelect==="none"&&g&&(e.style.userSelect=g),e.getAttribute("style")===""&&e.removeAttribute("style"),KW.delete(e)}}const cHe=N.createContext({register:()=>{}});cHe.displayName="PressResponderContext";function trg(e){let g=U.useContext(cHe);if(g){let{register:I,...i}=g;e=Gi(i,e),I()}return AHe(g,e.ref),e}var a1=new WeakMap;class A1{continuePropagation(){uce(this,a1,!1)}get shouldStopPropagation(){return jCg(this,a1)}constructor(g,I,i){qCg(this,a1,{writable:!0,value:void 0}),uce(this,a1,!0),this.type=g,this.pointerType=I,this.target=i.currentTarget,this.shiftKey=i.shiftKey,this.metaKey=i.metaKey,this.ctrlKey=i.ctrlKey,this.altKey=i.altKey}}const hce=Symbol("linkClicked");function I8(e){let{onPress:g,onPressChange:I,onPressStart:i,onPressEnd:n,onPressUp:C,isDisabled:r,isPressed:o,preventFocusOnPress:a,shouldCancelOnPointerExit:s,allowTextSelectionOnPress:A,ref:l,...c}=trg(e),[u,d]=U.useState(!1),h=U.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,ignoreClickAfterPress:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null}),{addGlobalListener:m,removeAllGlobalListeners:f}=oHe(),b=ar((v,w)=>{let V=h.current;if(r||V.didFirePressStart)return!1;let S=!0;if(V.isTriggeringEvent=!0,i){let X=new A1("pressstart",w,v);i(X),S=X.shouldStopPropagation}return I&&I(!0),V.isTriggeringEvent=!1,V.didFirePressStart=!0,d(!0),S}),p=ar((v,w,V=!0)=>{let S=h.current;if(!S.didFirePressStart)return!1;S.ignoreClickAfterPress=!0,S.didFirePressStart=!1,S.isTriggeringEvent=!0;let X=!0;if(n){let W=new A1("pressend",w,v);n(W),X=W.shouldStopPropagation}if(I&&I(!1),d(!1),g&&V&&!r){let W=new A1("press",w,v);g(W),X&&(X=W.shouldStopPropagation)}return S.isTriggeringEvent=!1,X}),y=ar((v,w)=>{let V=h.current;if(r)return!1;if(C){V.isTriggeringEvent=!0;let S=new A1("pressup",w,v);return C(S),V.isTriggeringEvent=!1,S.shouldStopPropagation}return!0}),Z=ar(v=>{let w=h.current;w.isPressed&&w.target&&(w.isOverTarget&&w.pointerType!=null&&p(UA(w.target,v),w.pointerType,!1),w.isPressed=!1,w.isOverTarget=!1,w.activePointerId=null,w.pointerType=null,f(),A||o1(w.target))}),B=ar(v=>{s&&Z(v)}),G=U.useMemo(()=>{let v=h.current,w={onKeyDown(S){if(xF(S.nativeEvent,S.currentTarget)&&S.currentTarget.contains(S.target)){var X;fce(S.target,S.key)&&S.preventDefault();let W=!0;!v.isPressed&&!S.repeat&&(v.target=S.currentTarget,v.isPressed=!0,W=b(S,"keyboard"),m(Cc(S.currentTarget),"keyup",V,!1)),W&&S.stopPropagation(),S.metaKey&&Eh()&&((X=v.metaKeyEvents)===null||X===void 0||X.set(S.key,S.nativeEvent))}else S.key==="Meta"&&(v.metaKeyEvents=new Map)},onKeyUp(S){xF(S.nativeEvent,S.currentTarget)&&!S.repeat&&S.currentTarget.contains(S.target)&&v.target&&y(UA(v.target,S),"keyboard")},onClick(S){if(!(S&&!S.currentTarget.contains(S.target))&&S&&S.button===0&&!v.isTriggeringEvent&&!Mh.isOpening){let X=!0;if(r&&S.preventDefault(),!v.ignoreClickAfterPress&&!v.ignoreEmulatedMouseEvents&&!v.isPressed&&(v.pointerType==="virtual"||h_(S.nativeEvent))){!r&&!a&&vs(S.currentTarget);let W=b(S,"virtual"),R=y(S,"virtual"),H=p(S,"virtual");X=W&&R&&H}v.ignoreEmulatedMouseEvents=!1,v.ignoreClickAfterPress=!1,X&&S.stopPropagation()}}},V=S=>{var X;if(v.isPressed&&v.target&&xF(S,v.target)){var W;fce(S.target,S.key)&&S.preventDefault();let H=S.target,Y=p(UA(v.target,S),"keyboard",v.target.contains(H));f(),Y&&S.stopPropagation(),S.key!=="Enter"&&i8(v.target)&&v.target.contains(H)&&!S[hce]&&(S[hce]=!0,Mh(v.target,S,!1)),v.isPressed=!1,(W=v.metaKeyEvents)===null||W===void 0||W.delete(S.key)}else if(S.key==="Meta"&&(!((X=v.metaKeyEvents)===null||X===void 0)&&X.size)){var R;let H=v.metaKeyEvents;v.metaKeyEvents=void 0;for(let Y of H.values())(R=v.target)===null||R===void 0||R.dispatchEvent(new KeyboardEvent("keyup",Y))}};if(typeof PointerEvent<"u"){w.onPointerDown=R=>{if(R.button!==0||!R.currentTarget.contains(R.target))return;if(LCg(R.nativeEvent)){v.pointerType="virtual";return}DF(R.currentTarget)&&R.preventDefault(),v.pointerType=R.pointerType;let H=!0;v.isPressed||(v.isPressed=!0,v.isOverTarget=!0,v.activePointerId=R.pointerId,v.target=R.currentTarget,!r&&!a&&vs(R.currentTarget),A||dce(v.target),H=b(R,v.pointerType),m(Cc(R.currentTarget),"pointermove",S,!1),m(Cc(R.currentTarget),"pointerup",X,!1),m(Cc(R.currentTarget),"pointercancel",W,!1)),H&&R.stopPropagation()},w.onMouseDown=R=>{R.currentTarget.contains(R.target)&&R.button===0&&(DF(R.currentTarget)&&R.preventDefault(),R.stopPropagation())},w.onPointerUp=R=>{!R.currentTarget.contains(R.target)||v.pointerType==="virtual"||R.button===0&&af(R,R.currentTarget)&&y(R,v.pointerType||R.pointerType)};let S=R=>{R.pointerId===v.activePointerId&&(v.target&&af(R,v.target)?!v.isOverTarget&&v.pointerType!=null&&(v.isOverTarget=!0,b(UA(v.target,R),v.pointerType)):v.target&&v.isOverTarget&&v.pointerType!=null&&(v.isOverTarget=!1,p(UA(v.target,R),v.pointerType,!1),B(R)))},X=R=>{R.pointerId===v.activePointerId&&v.isPressed&&R.button===0&&v.target&&(af(R,v.target)&&v.pointerType!=null?p(UA(v.target,R),v.pointerType):v.isOverTarget&&v.pointerType!=null&&p(UA(v.target,R),v.pointerType,!1),v.isPressed=!1,v.isOverTarget=!1,v.activePointerId=null,v.pointerType=null,f(),A||o1(v.target))},W=R=>{Z(R)};w.onDragStart=R=>{R.currentTarget.contains(R.target)&&Z(R)}}else{w.onMouseDown=W=>{if(W.button!==0||!W.currentTarget.contains(W.target))return;if(DF(W.currentTarget)&&W.preventDefault(),v.ignoreEmulatedMouseEvents){W.stopPropagation();return}v.isPressed=!0,v.isOverTarget=!0,v.target=W.currentTarget,v.pointerType=h_(W.nativeEvent)?"virtual":"mouse",!r&&!a&&vs(W.currentTarget),b(W,v.pointerType)&&W.stopPropagation(),m(Cc(W.currentTarget),"mouseup",S,!1)},w.onMouseEnter=W=>{if(!W.currentTarget.contains(W.target))return;let R=!0;v.isPressed&&!v.ignoreEmulatedMouseEvents&&v.pointerType!=null&&(v.isOverTarget=!0,R=b(W,v.pointerType)),R&&W.stopPropagation()},w.onMouseLeave=W=>{if(!W.currentTarget.contains(W.target))return;let R=!0;v.isPressed&&!v.ignoreEmulatedMouseEvents&&v.pointerType!=null&&(v.isOverTarget=!1,R=p(W,v.pointerType,!1),B(W)),R&&W.stopPropagation()},w.onMouseUp=W=>{W.currentTarget.contains(W.target)&&!v.ignoreEmulatedMouseEvents&&W.button===0&&y(W,v.pointerType||"mouse")};let S=W=>{if(W.button===0){if(v.isPressed=!1,f(),v.ignoreEmulatedMouseEvents){v.ignoreEmulatedMouseEvents=!1;return}v.target&&af(W,v.target)&&v.pointerType!=null?p(UA(v.target,W),v.pointerType):v.target&&v.isOverTarget&&v.pointerType!=null&&p(UA(v.target,W),v.pointerType,!1),v.isOverTarget=!1}};w.onTouchStart=W=>{if(!W.currentTarget.contains(W.target))return;let R=grg(W.nativeEvent);if(!R)return;v.activePointerId=R.identifier,v.ignoreEmulatedMouseEvents=!0,v.isOverTarget=!0,v.isPressed=!0,v.target=W.currentTarget,v.pointerType="touch",!r&&!a&&vs(W.currentTarget),A||dce(v.target),b(W,v.pointerType)&&W.stopPropagation(),m(HH(W.currentTarget),"scroll",X,!0)},w.onTouchMove=W=>{if(!W.currentTarget.contains(W.target))return;if(!v.isPressed){W.stopPropagation();return}let R=mce(W.nativeEvent,v.activePointerId),H=!0;R&&af(R,W.currentTarget)?!v.isOverTarget&&v.pointerType!=null&&(v.isOverTarget=!0,H=b(W,v.pointerType)):v.isOverTarget&&v.pointerType!=null&&(v.isOverTarget=!1,H=p(W,v.pointerType,!1),B(W)),H&&W.stopPropagation()},w.onTouchEnd=W=>{if(!W.currentTarget.contains(W.target))return;if(!v.isPressed){W.stopPropagation();return}let R=mce(W.nativeEvent,v.activePointerId),H=!0;R&&af(R,W.currentTarget)&&v.pointerType!=null?(y(W,v.pointerType),H=p(W,v.pointerType)):v.isOverTarget&&v.pointerType!=null&&(H=p(W,v.pointerType,!1)),H&&W.stopPropagation(),v.isPressed=!1,v.activePointerId=null,v.isOverTarget=!1,v.ignoreEmulatedMouseEvents=!0,v.target&&!A&&o1(v.target),f()},w.onTouchCancel=W=>{W.currentTarget.contains(W.target)&&(W.stopPropagation(),v.isPressed&&Z(W))};let X=W=>{v.isPressed&&W.target.contains(v.target)&&Z({currentTarget:v.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})};w.onDragStart=W=>{W.currentTarget.contains(W.target)&&Z(W)}}return w},[m,r,a,f,A,Z,B,p,b,y]);return U.useEffect(()=>()=>{var v;A||o1((v=h.current.target)!==null&&v!==void 0?v:void 0)},[A]),{isPressed:o||u,pressProps:Gi(c,G)}}function i8(e){return e.tagName==="A"&&e.hasAttribute("href")}function xF(e,g){const{key:I,code:i}=e,n=g,C=n.getAttribute("role");return(I==="Enter"||I===" "||I==="Spacebar"||i==="Space")&&!(n instanceof HH(n).HTMLInputElement&&!uHe(n,I)||n instanceof HH(n).HTMLTextAreaElement||n.isContentEditable)&&!((C==="link"||!C&&i8(n))&&I!=="Enter")}function grg(e){const{targetTouches:g}=e;return g.length>0?g[0]:null}function mce(e,g){const I=e.changedTouches;for(let i=0;ig.right||g.left>e.right||e.top>g.bottom||g.top>e.bottom)}function af(e,g){let I=g.getBoundingClientRect(),i=Irg(e);return irg(I,i)}function DF(e){return!(e instanceof HTMLElement)||!e.hasAttribute("draggable")}function fce(e,g){return e instanceof HTMLInputElement?!uHe(e,g):e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!i8(e)}const nrg=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function uHe(e,g){return e.type==="checkbox"||e.type==="radio"?g===" ":nrg.has(e.type)}class Crg{isDefaultPrevented(){return this.nativeEvent.defaultPrevented}preventDefault(){this.defaultPrevented=!0,this.nativeEvent.preventDefault()}stopPropagation(){this.nativeEvent.stopPropagation(),this.isPropagationStopped=()=>!0}isPropagationStopped(){return!1}persist(){}constructor(g,I){this.nativeEvent=I,this.target=I.target,this.currentTarget=I.currentTarget,this.relatedTarget=I.relatedTarget,this.bubbles=I.bubbles,this.cancelable=I.cancelable,this.defaultPrevented=I.defaultPrevented,this.eventPhase=I.eventPhase,this.isTrusted=I.isTrusted,this.timeStamp=I.timeStamp,this.type=g}}function dHe(e){let g=U.useRef({isFocused:!1,observer:null});bi(()=>{const i=g.current;return()=>{i.observer&&(i.observer.disconnect(),i.observer=null)}},[]);let I=ar(i=>{e==null||e(i)});return U.useCallback(i=>{if(i.target instanceof HTMLButtonElement||i.target instanceof HTMLInputElement||i.target instanceof HTMLTextAreaElement||i.target instanceof HTMLSelectElement){g.current.isFocused=!0;let n=i.target,C=r=>{g.current.isFocused=!1,n.disabled&&I(new Crg("blur",r)),g.current.observer&&(g.current.observer.disconnect(),g.current.observer=null)};n.addEventListener("focusout",C,{once:!0}),g.current.observer=new MutationObserver(()=>{if(g.current.isFocused&&n.disabled){var r;(r=g.current.observer)===null||r===void 0||r.disconnect();let o=n===document.activeElement?null:document.activeElement;n.dispatchEvent(new FocusEvent("blur",{relatedTarget:o})),n.dispatchEvent(new FocusEvent("focusout",{bubbles:!0,relatedTarget:o}))}}),g.current.observer.observe(n,{attributes:!0,attributeFilter:["disabled"]})}},[I])}function hHe(e){let{isDisabled:g,onFocus:I,onBlur:i,onFocusChange:n}=e;const C=U.useCallback(a=>{if(a.target===a.currentTarget)return i&&i(a),n&&n(!1),!0},[i,n]),r=dHe(C),o=U.useCallback(a=>{a.target===a.currentTarget&&document.activeElement===a.target&&(I&&I(a),n&&n(!0),r(a))},[n,I,r]);return{focusProps:{onFocus:!g&&(I||n||i)?o:void 0,onBlur:!g&&(i||n)?C:void 0}}}let _s=null,AS=new Set,pce=!1,zh=!1,f_=!1;const rrg={Tab:!0,Escape:!0};function eY(e,g){for(let I of AS)I(e,g)}function org(e){return!(e.metaKey||!Eh()&&e.altKey||e.ctrlKey||e.key==="Control"||e.key==="Shift"||e.key==="Meta")}function bce(e){zh=!0,org(e)&&(_s="keyboard",eY("keyboard",e))}function Af(e){_s="pointer",(e.type==="mousedown"||e.type==="pointerdown")&&(zh=!0,eY("pointer",e))}function arg(e){h_(e)&&(zh=!0,_s="virtual")}function Arg(e){e.target===window||e.target===document||(!zh&&!f_&&(_s="virtual",eY("virtual",e)),zh=!1,f_=!1)}function srg(){zh=!1,f_=!0}function kH(){if(typeof window>"u"||pce)return;let e=HTMLElement.prototype.focus;HTMLElement.prototype.focus=function(){zh=!0,e.apply(this,arguments)},document.addEventListener("keydown",bce,!0),document.addEventListener("keyup",bce,!0),document.addEventListener("click",arg,!0),window.addEventListener("focus",Arg,!0),window.addEventListener("blur",srg,!1),typeof PointerEvent<"u"?(document.addEventListener("pointerdown",Af,!0),document.addEventListener("pointermove",Af,!0),document.addEventListener("pointerup",Af,!0)):(document.addEventListener("mousedown",Af,!0),document.addEventListener("mousemove",Af,!0),document.addEventListener("mouseup",Af,!0)),pce=!0}typeof document<"u"&&(document.readyState!=="loading"?kH():document.addEventListener("DOMContentLoaded",kH));function n8(){return _s!=="pointer"}function p_(){return _s}function lrg(e){_s=e,eY(e,null)}function crg(){kH();let[e,g]=U.useState(_s);return U.useEffect(()=>{let I=()=>{g(_s)};return AS.add(I),()=>{AS.delete(I)}},[]),kw()?null:e}const urg=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function drg(e,g,I){var i;return e=e||(I==null?void 0:I.target)instanceof HTMLInputElement&&!urg.has(I==null||(i=I.target)===null||i===void 0?void 0:i.type)||(I==null?void 0:I.target)instanceof HTMLTextAreaElement||(I==null?void 0:I.target)instanceof HTMLElement&&(I==null?void 0:I.target.isContentEditable),!(e&&g==="keyboard"&&I instanceof KeyboardEvent&&!rrg[I.key])}function hrg(e,g,I){kH(),U.useEffect(()=>{let i=(n,C)=>{drg(!!(I!=null&&I.isTextInput),n,C)&&e(n8())};return AS.add(i),()=>{AS.delete(i)}},g)}function mHe(e){let{isDisabled:g,onBlurWithin:I,onFocusWithin:i,onFocusWithinChange:n}=e,C=U.useRef({isFocusWithin:!1}),r=U.useCallback(s=>{C.current.isFocusWithin&&!s.currentTarget.contains(s.relatedTarget)&&(C.current.isFocusWithin=!1,I&&I(s),n&&n(!1))},[I,n,C]),o=dHe(r),a=U.useCallback(s=>{!C.current.isFocusWithin&&document.activeElement===s.target&&(i&&i(s),n&&n(!0),C.current.isFocusWithin=!0,o(s))},[i,n,o]);return g?{focusWithinProps:{onFocus:void 0,onBlur:void 0}}:{focusWithinProps:{onFocus:a,onBlur:r}}}let YH=!1,FF=0;function b_(){YH=!0,setTimeout(()=>{YH=!1},50)}function yce(e){e.pointerType==="touch"&&b_()}function mrg(){if(!(typeof document>"u"))return typeof PointerEvent<"u"?document.addEventListener("pointerup",yce):document.addEventListener("touchend",b_),FF++,()=>{FF--,!(FF>0)&&(typeof PointerEvent<"u"?document.removeEventListener("pointerup",yce):document.removeEventListener("touchend",b_))}}function C8(e){let{onHoverStart:g,onHoverChange:I,onHoverEnd:i,isDisabled:n}=e,[C,r]=U.useState(!1),o=U.useRef({isHovered:!1,ignoreEmulatedMouseEvents:!1,pointerType:"",target:null}).current;U.useEffect(mrg,[]);let{hoverProps:a,triggerHoverEnd:s}=U.useMemo(()=>{let A=(u,d)=>{if(o.pointerType=d,n||d==="touch"||o.isHovered||!u.currentTarget.contains(u.target))return;o.isHovered=!0;let h=u.currentTarget;o.target=h,g&&g({type:"hoverstart",target:h,pointerType:d}),I&&I(!0),r(!0)},l=(u,d)=>{if(o.pointerType="",o.target=null,d==="touch"||!o.isHovered)return;o.isHovered=!1;let h=u.currentTarget;i&&i({type:"hoverend",target:h,pointerType:d}),I&&I(!1),r(!1)},c={};return typeof PointerEvent<"u"?(c.onPointerEnter=u=>{YH&&u.pointerType==="mouse"||A(u,u.pointerType)},c.onPointerLeave=u=>{!n&&u.currentTarget.contains(u.target)&&l(u,u.pointerType)}):(c.onTouchStart=()=>{o.ignoreEmulatedMouseEvents=!0},c.onMouseEnter=u=>{!o.ignoreEmulatedMouseEvents&&!YH&&A(u,"mouse"),o.ignoreEmulatedMouseEvents=!1},c.onMouseLeave=u=>{!n&&u.currentTarget.contains(u.target)&&l(u,"mouse")}),{hoverProps:c,triggerHoverEnd:l}},[g,I,i,n,o]);return U.useEffect(()=>{n&&s({currentTarget:o.target},o.pointerType)},[n]),{hoverProps:a,isHovered:C}}function Zce(e){if(!e)return;let g=!0;return I=>{let i={...I,preventDefault(){I.preventDefault()},isDefaultPrevented(){return I.isDefaultPrevented()},stopPropagation(){console.error("stopPropagation is now the default behavior for events in React Spectrum. You can use continuePropagation() to revert this behavior.")},continuePropagation(){g=!1}};e(i),g&&I.stopPropagation()}}function frg(e){return{keyboardProps:e.isDisabled?{}:{onKeyDown:Zce(e.onKeyDown),onKeyUp:Zce(e.onKeyUp)}}}const prg=500;function brg(e){let{isDisabled:g,onLongPressStart:I,onLongPressEnd:i,onLongPress:n,threshold:C=prg,accessibilityDescription:r}=e;const o=U.useRef();let{addGlobalListener:a,removeGlobalListener:s}=oHe(),{pressProps:A}=I8({isDisabled:g,onPressStart(c){if(c.continuePropagation(),(c.pointerType==="mouse"||c.pointerType==="touch")&&(I&&I({...c,type:"longpressstart"}),o.current=setTimeout(()=>{c.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),n&&n({...c,type:"longpress"}),o.current=void 0},C),c.pointerType==="touch")){let u=d=>{d.preventDefault()};a(c.target,"contextmenu",u,{once:!0}),a(window,"pointerup",()=>{setTimeout(()=>{s(c.target,"contextmenu",u)},30)},{once:!0})}},onPressEnd(c){o.current&&clearTimeout(o.current),i&&(c.pointerType==="mouse"||c.pointerType==="touch")&&i({...c,type:"longpressend"})}}),l=qk(n&&!g?r:void 0);return{longPressProps:Gi(A,l)}}function gr(e){if(p_()==="virtual"){let g=document.activeElement;rHe(()=>{document.activeElement===g&&document.contains(e)&&vs(e)})}else vs(e)}function yrg(e){if(!(e instanceof HTMLElement)&&!(e instanceof SVGElement))return!1;let{display:g,visibility:I}=e.style,i=g!=="none"&&I!=="hidden"&&I!=="collapse";if(i){const{getComputedStyle:n}=e.ownerDocument.defaultView;let{display:C,visibility:r}=n(e);i=C!=="none"&&r!=="hidden"&&r!=="collapse"}return i}function Zrg(e,g){return!e.hasAttribute("hidden")&&(e.nodeName==="DETAILS"&&g&&g.nodeName!=="SUMMARY"?e.hasAttribute("open"):!0)}function fHe(e,g){return e.nodeName!=="#comment"&&yrg(e)&&Zrg(e,g)&&(!e.parentElement||fHe(e.parentElement,e))}const Gce=N.createContext(null);let mI=null;function Grg(e){let{children:g,contain:I,restoreFocus:i,autoFocus:n}=e,C=U.useRef(null),r=U.useRef(null),o=U.useRef([]),{parentNode:a}=U.useContext(Gce)||{},s=U.useMemo(()=>new Z_({scopeRef:o}),[o]);bi(()=>{let c=a||di.root;if(di.getTreeNode(c.scopeRef)&&mI&&!KH(mI,c.scopeRef)){let u=di.getTreeNode(mI);u&&(c=u)}c.addChild(s),di.addNode(s)},[s,a]),bi(()=>{let c=di.getTreeNode(o);c&&(c.contain=!!I)},[I]),bi(()=>{var c;let u=(c=C.current)===null||c===void 0?void 0:c.nextSibling,d=[];for(;u&&u!==r.current;)d.push(u),u=u.nextSibling;o.current=d},[g]),Rrg(o,i,I),wrg(o,I),Xrg(o,i,I),Vrg(o,n),U.useEffect(()=>{let c=document.activeElement,u=null;if(Yn(c,o.current)){for(let d of di.traverse())d.scopeRef&&Yn(c,d.scopeRef.current)&&(u=d);u===di.getTreeNode(o)&&(mI=u.scopeRef)}},[o]),bi(()=>()=>{var c,u,d;let h=(d=(u=di.getTreeNode(o))===null||u===void 0||(c=u.parent)===null||c===void 0?void 0:c.scopeRef)!==null&&d!==void 0?d:null;(o===mI||KH(o,mI))&&(!h||di.getTreeNode(h))&&(mI=h),di.removeTreeNode(o)},[o]);let A=U.useMemo(()=>vrg(o),[]),l=U.useMemo(()=>({focusManager:A,parentNode:s}),[s,A]);return N.createElement(Gce.Provider,{value:l},N.createElement("span",{"data-focus-scope-start":!0,hidden:!0,ref:C}),g,N.createElement("span",{"data-focus-scope-end":!0,hidden:!0,ref:r}))}function vrg(e){return{focusNext(g={}){let I=e.current,{from:i,tabbable:n,wrap:C,accept:r}=g,o=i||document.activeElement,a=I[0].previousElementSibling,s=yd(I),A=jr(s,{tabbable:n,accept:r},I);A.currentNode=Yn(o,I)?o:a;let l=A.nextNode();return!l&&C&&(A.currentNode=a,l=A.nextNode()),l&&Bs(l,!0),l},focusPrevious(g={}){let I=e.current,{from:i,tabbable:n,wrap:C,accept:r}=g,o=i||document.activeElement,a=I[I.length-1].nextElementSibling,s=yd(I),A=jr(s,{tabbable:n,accept:r},I);A.currentNode=Yn(o,I)?o:a;let l=A.previousNode();return!l&&C&&(A.currentNode=a,l=A.previousNode()),l&&Bs(l,!0),l},focusFirst(g={}){let I=e.current,{tabbable:i,accept:n}=g,C=yd(I),r=jr(C,{tabbable:i,accept:n},I);r.currentNode=I[0].previousElementSibling;let o=r.nextNode();return o&&Bs(o,!0),o},focusLast(g={}){let I=e.current,{tabbable:i,accept:n}=g,C=yd(I),r=jr(C,{tabbable:i,accept:n},I);r.currentNode=I[I.length-1].nextElementSibling;let o=r.previousNode();return o&&Bs(o,!0),o}}}const r8=["input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","a[href]","area[href]","summary","iframe","object","embed","audio[controls]","video[controls]","[contenteditable]"],Brg=r8.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";r8.push('[tabindex]:not([tabindex="-1"]):not([disabled])');const Srg=r8.join(':not([hidden]):not([tabindex="-1"]),');function yd(e){return e[0].parentElement}function yG(e){let g=di.getTreeNode(mI);for(;g&&g.scopeRef!==e;){if(g.contain)return!1;g=g.parent}return!0}function wrg(e,g){let I=U.useRef(),i=U.useRef();bi(()=>{let n=e.current;if(!g){i.current&&(cancelAnimationFrame(i.current),i.current=void 0);return}let C=a=>{if(a.key!=="Tab"||a.altKey||a.ctrlKey||a.metaKey||!yG(e))return;let s=document.activeElement,A=e.current;if(!A||!Yn(s,A))return;let l=yd(A),c=jr(l,{tabbable:!0},A);if(!s)return;c.currentNode=s;let u=a.shiftKey?c.previousNode():c.nextNode();u||(c.currentNode=a.shiftKey?A[A.length-1].nextElementSibling:A[0].previousElementSibling,u=a.shiftKey?c.previousNode():c.nextNode()),a.preventDefault(),u&&Bs(u,!0)},r=a=>{(!mI||KH(mI,e))&&Yn(a.target,e.current)?(mI=e,I.current=a.target):yG(e)&&!y_(a.target,e)?I.current?I.current.focus():mI&&mI.current&&xH(mI.current):yG(e)&&(I.current=a.target)},o=a=>{i.current&&cancelAnimationFrame(i.current),i.current=requestAnimationFrame(()=>{if(document.activeElement&&yG(e)&&!y_(document.activeElement,e))if(mI=e,document.body.contains(a.target)){var s;I.current=a.target,(s=I.current)===null||s===void 0||s.focus()}else mI.current&&xH(mI.current)})};return document.addEventListener("keydown",C,!1),document.addEventListener("focusin",r,!1),n==null||n.forEach(a=>a.addEventListener("focusin",r,!1)),n==null||n.forEach(a=>a.addEventListener("focusout",o,!1)),()=>{document.removeEventListener("keydown",C,!1),document.removeEventListener("focusin",r,!1),n==null||n.forEach(a=>a.removeEventListener("focusin",r,!1)),n==null||n.forEach(a=>a.removeEventListener("focusout",o,!1))}},[e,g]),bi(()=>()=>{i.current&&cancelAnimationFrame(i.current)},[i])}function pHe(e){return y_(e)}function Yn(e,g){return!e||!g?!1:g.some(I=>I.contains(e))}function y_(e,g=null){if(e instanceof Element&&e.closest("[data-react-aria-top-layer]"))return!0;for(let{scopeRef:I}of di.traverse(di.getTreeNode(g)))if(I&&Yn(e,I.current))return!0;return!1}function KH(e,g){var I;let i=(I=di.getTreeNode(g))===null||I===void 0?void 0:I.parent;for(;i;){if(i.scopeRef===e)return!0;i=i.parent}return!1}function Bs(e,g=!1){if(e!=null&&!g)try{gr(e)}catch{}else if(e!=null)try{e.focus()}catch{}}function xH(e,g=!0){let I=e[0].previousElementSibling,i=yd(e),n=jr(i,{tabbable:g},e);n.currentNode=I;let C=n.nextNode();g&&!C&&(i=yd(e),n=jr(i,{tabbable:!1},e),n.currentNode=I,C=n.nextNode()),Bs(C)}function Vrg(e,g){const I=N.useRef(g);U.useEffect(()=>{I.current&&(mI=e,!Yn(document.activeElement,mI.current)&&e.current&&xH(e.current)),I.current=!1},[e])}function Rrg(e,g,I){bi(()=>{if(g||I)return;let i=e.current,n=C=>{let r=C.target;Yn(r,e.current)?mI=e:pHe(r)||(mI=null)};return document.addEventListener("focusin",n,!1),i==null||i.forEach(C=>C.addEventListener("focusin",n,!1)),()=>{document.removeEventListener("focusin",n,!1),i==null||i.forEach(C=>C.removeEventListener("focusin",n,!1))}},[e,g,I])}function Wrg(e){let g=di.getTreeNode(mI);for(;g&&g.scopeRef!==e;){if(g.nodeToRestore)return!1;g=g.parent}return(g==null?void 0:g.scopeRef)===e}function Xrg(e,g,I){const i=U.useRef(typeof document<"u"?document.activeElement:null);bi(()=>{let n=e.current;if(!g||I)return;let C=()=>{(!mI||KH(mI,e))&&Yn(document.activeElement,e.current)&&(mI=e)};return document.addEventListener("focusin",C,!1),n==null||n.forEach(r=>r.addEventListener("focusin",C,!1)),()=>{document.removeEventListener("focusin",C,!1),n==null||n.forEach(r=>r.removeEventListener("focusin",C,!1))}},[e,I]),bi(()=>{if(!g)return;let n=C=>{if(C.key!=="Tab"||C.altKey||C.ctrlKey||C.metaKey||!yG(e))return;let r=document.activeElement;if(!Yn(r,e.current))return;let o=di.getTreeNode(e);if(!o)return;let a=o.nodeToRestore,s=jr(document.body,{tabbable:!0});s.currentNode=r;let A=C.shiftKey?s.previousNode():s.nextNode();if((!a||!document.body.contains(a)||a===document.body)&&(a=void 0,o.nodeToRestore=void 0),(!A||!Yn(A,e.current))&&a){s.currentNode=a;do A=C.shiftKey?s.previousNode():s.nextNode();while(Yn(A,e.current));C.preventDefault(),C.stopPropagation(),A?Bs(A,!0):pHe(a)?Bs(a,!0):r.blur()}};return I||document.addEventListener("keydown",n,!0),()=>{I||document.removeEventListener("keydown",n,!0)}},[e,g,I]),bi(()=>{if(!g)return;let n=di.getTreeNode(e);if(n){var C;return n.nodeToRestore=(C=i.current)!==null&&C!==void 0?C:void 0,()=>{let r=di.getTreeNode(e);if(!r)return;let o=r.nodeToRestore;if(g&&o&&(Yn(document.activeElement,e.current)||document.activeElement===document.body&&Wrg(e))){let a=di.clone();requestAnimationFrame(()=>{if(document.activeElement===document.body){let s=a.getTreeNode(e);for(;s;){if(s.nodeToRestore&&document.body.contains(s.nodeToRestore)){Bs(s.nodeToRestore);return}s=s.parent}for(s=a.getTreeNode(e);s;){if(s.scopeRef&&s.scopeRef.current&&di.getTreeNode(s.scopeRef)){xH(s.scopeRef.current,!0);return}s=s.parent}}})}}}},[e,g])}function jr(e,g,I){let i=g!=null&&g.tabbable?Srg:Brg,n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode(C){var r;return!(g==null||(r=g.from)===null||r===void 0)&&r.contains(C)?NodeFilter.FILTER_REJECT:C.matches(i)&&fHe(C)&&(!I||Yn(C,I))&&(!(g!=null&&g.accept)||g.accept(C))?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});return g!=null&&g.from&&(n.currentNode=g.from),n}class o8{get size(){return this.fastMap.size}getTreeNode(g){return this.fastMap.get(g)}addTreeNode(g,I,i){let n=this.fastMap.get(I??null);if(!n)return;let C=new Z_({scopeRef:g});n.addChild(C),C.parent=n,this.fastMap.set(g,C),i&&(C.nodeToRestore=i)}addNode(g){this.fastMap.set(g.scopeRef,g)}removeTreeNode(g){if(g===null)return;let I=this.fastMap.get(g);if(!I)return;let i=I.parent;for(let C of this.traverse())C!==I&&I.nodeToRestore&&C.nodeToRestore&&I.scopeRef&&I.scopeRef.current&&Yn(C.nodeToRestore,I.scopeRef.current)&&(C.nodeToRestore=I.nodeToRestore);let n=I.children;i&&(i.removeChild(I),n.size>0&&n.forEach(C=>i&&i.addChild(C))),this.fastMap.delete(I.scopeRef)}*traverse(g=this.root){if(g.scopeRef!=null&&(yield g),g.children.size>0)for(let I of g.children)yield*this.traverse(I)}clone(){var g;let I=new o8;var i;for(let n of this.traverse())I.addTreeNode(n.scopeRef,(i=(g=n.parent)===null||g===void 0?void 0:g.scopeRef)!==null&&i!==void 0?i:null,n.nodeToRestore);return I}constructor(){this.fastMap=new Map,this.root=new Z_({scopeRef:null}),this.fastMap.set(null,this.root)}}class Z_{addChild(g){this.children.add(g),g.parent=this}removeChild(g){this.children.delete(g),g.parent=void 0}constructor(g){this.children=new Set,this.contain=!1,this.scopeRef=g.scopeRef}}let di=new o8;function tY(e={}){let{autoFocus:g=!1,isTextInput:I,within:i}=e,n=U.useRef({isFocused:!1,isFocusVisible:g||n8()}),[C,r]=U.useState(!1),[o,a]=U.useState(()=>n.current.isFocused&&n.current.isFocusVisible),s=U.useCallback(()=>a(n.current.isFocused&&n.current.isFocusVisible),[]),A=U.useCallback(u=>{n.current.isFocused=u,r(u),s()},[s]);hrg(u=>{n.current.isFocusVisible=u,s()},[],{isTextInput:I});let{focusProps:l}=hHe({isDisabled:i,onFocusChange:A}),{focusWithinProps:c}=mHe({isDisabled:!i,onFocusWithinChange:A});return{isFocused:C,isFocusVisible:o,focusProps:i?c:l}}let Hrg=N.createContext(null);function Trg(e){let g=U.useContext(Hrg)||{};AHe(g,e);let{ref:I,...i}=g;return i}function bHe(e,g){let{focusProps:I}=hHe(e),{keyboardProps:i}=frg(e),n=Gi(I,i),C=Trg(g),r=e.isDisabled?{}:C,o=U.useRef(e.autoFocus);return U.useEffect(()=>{o.current&&g.current&&gr(g.current),o.current=!1},[g]),{focusableProps:Gi({...n,tabIndex:e.excludeFromTabOrder&&!e.isDisabled?-1:void 0},r)}}function Nrg(e,g){let I=g==null?void 0:g.isDisabled,[i,n]=U.useState(!1);return bi(()=>{if(e!=null&&e.current&&!I){let C=()=>{if(e.current){let o=jr(e.current,{tabbable:!0});n(!!o.nextNode())}};C();let r=new MutationObserver(C);return r.observe(e.current,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["tabIndex","disabled"]}),()=>{r.disconnect()}}}),I?!1:i}class krg{getStringForLocale(g,I){let i=this.strings[I];i||(i=Yrg(I,this.strings,this.defaultLocale),this.strings[I]=i);let n=i[g];if(!n)throw new Error(`Could not find intl message ${g} in ${I} locale`);return n}constructor(g,I="en-US"){this.strings={...g},this.defaultLocale=I}}function Yrg(e,g,I="en-US"){if(g[e])return g[e];let i=Krg(e);if(g[i])return g[i];for(let n in g)if(n.startsWith(i+"-"))return g[n];return g[I]}function Krg(e){return Intl.Locale?new Intl.Locale(e).language:e.split("-")[0]}const vce=new Map,Bce=new Map;class xrg{format(g,I){let i=this.strings.getStringForLocale(g,this.locale);return typeof i=="function"?i(I,this):i}plural(g,I,i="cardinal"){let n=I["="+g];if(n)return typeof n=="function"?n():n;let C=this.locale+":"+i,r=vce.get(C);r||(r=new Intl.PluralRules(this.locale,{type:i}),vce.set(C,r));let o=r.select(g);return n=I[o]||I.other,typeof n=="function"?n():n}number(g){let I=Bce.get(this.locale);return I||(I=new Intl.NumberFormat(this.locale),Bce.set(this.locale,I)),I.format(g)}select(g,I){let i=g[I]||g.other;return typeof i=="function"?i():i}constructor(g,I){this.locale=g,this.strings=I}}const Drg=new Set(["Arab","Syrc","Samr","Mand","Thaa","Mend","Nkoo","Adlm","Rohg","Hebr"]),Frg=new Set(["ae","ar","arc","bcc","bqi","ckb","dv","fa","glk","he","ku","mzn","nqo","pnb","ps","sd","ug","ur","yi"]);function Erg(e){if(Intl.Locale){let I=new Intl.Locale(e).maximize().script;return I?Drg.has(I):!1}let g=e.split("-")[0];return Frg.has(g)}function yHe(){let e=typeof navigator<"u"&&(navigator.language||navigator.userLanguage)||"en-US";try{Intl.DateTimeFormat.supportedLocalesOf([e])}catch{e="en-US"}return{locale:e,direction:Erg(e)?"rtl":"ltr"}}let G_=yHe(),ZG=new Set;function Sce(){G_=yHe();for(let e of ZG)e(G_)}function Mrg(){let e=kw(),[g,I]=U.useState(G_);return U.useEffect(()=>(ZG.size===0&&window.addEventListener("languagechange",Sce),ZG.add(I),()=>{ZG.delete(I),ZG.size===0&&window.removeEventListener("languagechange",Sce)}),[]),e?{locale:"en-US",direction:"ltr"}:g}const zrg=N.createContext(null);function vm(){let e=Mrg();return U.useContext(zrg)||e}const wce=new WeakMap;function Prg(e){let g=wce.get(e);return g||(g=new krg(e),wce.set(e,g)),g}function hy(e){let{locale:g}=vm(),I=U.useMemo(()=>Prg(e),[e]);return U.useMemo(()=>new xrg(g,I),[g,I])}let EF=new Map;function ZHe(e){let{locale:g}=vm(),I=g+(e?Object.entries(e).sort((n,C)=>n[0]{n.remove()},i)}clear(g){this.node&&((!g||g==="assertive")&&(this.assertiveLog.innerHTML=""),(!g||g==="polite")&&(this.politeLog.innerHTML=""))}constructor(){this.node=document.createElement("div"),this.node.dataset.liveAnnouncer="true",Object.assign(this.node.style,{border:0,clip:"rect(0 0 0 0)",clipPath:"inset(50%)",height:"1px",margin:"-1px",overflow:"hidden",padding:0,position:"absolute",width:"1px",whiteSpace:"nowrap"}),this.assertiveLog=this.createLog("assertive"),this.node.appendChild(this.assertiveLog),this.politeLog=this.createLog("polite"),this.node.appendChild(this.politeLog),document.body.prepend(this.node)}}function Org(e,g,I){let{validationBehavior:i,focus:n}=e;bi(()=>{if(i==="native"&&(I!=null&&I.current)){let a=g.realtimeValidation.isInvalid?g.realtimeValidation.validationErrors.join(" ")||"Invalid value.":"";I.current.setCustomValidity(a),I.current.hasAttribute("title")||(I.current.title=""),g.realtimeValidation.isInvalid||g.updateValidation(Lrg(I.current))}});let C=ar(()=>{g.resetValidation()}),r=ar(a=>{var s;g.displayValidation.isInvalid||g.commitValidation();let A=I==null||(s=I.current)===null||s===void 0?void 0:s.form;if(!a.defaultPrevented&&I&&A&&Urg(A)===I.current){var l;n?n():(l=I.current)===null||l===void 0||l.focus(),lrg("keyboard")}a.preventDefault()}),o=ar(()=>{g.commitValidation()});U.useEffect(()=>{let a=I==null?void 0:I.current;if(!a)return;let s=a.form;return a.addEventListener("invalid",r),a.addEventListener("change",o),s==null||s.addEventListener("reset",C),()=>{a.removeEventListener("invalid",r),a.removeEventListener("change",o),s==null||s.removeEventListener("reset",C)}},[I,r,o,C,i])}function _rg(e){let g=e.validity;return{badInput:g.badInput,customError:g.customError,patternMismatch:g.patternMismatch,rangeOverflow:g.rangeOverflow,rangeUnderflow:g.rangeUnderflow,stepMismatch:g.stepMismatch,tooLong:g.tooLong,tooShort:g.tooShort,typeMismatch:g.typeMismatch,valueMissing:g.valueMissing,valid:g.valid}}function Lrg(e){return{isInvalid:!e.validity.valid,validationDetails:_rg(e),validationErrors:e.validationMessage?[e.validationMessage]:[]}}function Urg(e){for(let g=0;gRce(qrg(r,n)),[r,n]);C!=null&&C.validationDetails.valid&&(C=null);let A=U.useContext(Qrg),l=U.useMemo(()=>i?Array.isArray(i)?i.flatMap(V=>v_(A[V])):v_(A[i]):[],[A,i]),[c,u]=U.useState(A),[d,h]=U.useState(!1);A!==c&&(u(A),h(!1));let m=U.useMemo(()=>Rce(d?[]:l),[d,l]),f=U.useRef(GZ),[b,p]=U.useState(GZ),y=U.useRef(GZ),Z=()=>{if(!B)return;G(!1);let V=s||C||f.current;zF(V,y.current)||(y.current=V,p(V))},[B,G]=U.useState(!1);return U.useEffect(Z),{realtimeValidation:a||m||s||C||GZ,displayValidation:o==="native"?a||m||b:a||m||s||C||b,updateValidation(V){o==="aria"&&!zF(b,V)?p(V):f.current=V},resetValidation(){let V=GZ;zF(V,y.current)||(y.current=V,p(V)),o==="native"&&G(!1),h(!0)},commitValidation(){o==="native"&&G(!0),h(!0)}}}function v_(e){return e?Array.isArray(e)?e:[e]:[]}function qrg(e,g){if(typeof e=="function"){let I=e(g);if(I&&typeof I!="boolean")return v_(I)}return[]}function Rce(e){return e.length?{isInvalid:!0,validationErrors:e,validationDetails:SHe}:null}function zF(e,g){return e===g?!0:e&&g&&e.isInvalid===g.isInvalid&&e.validationErrors.length===g.validationErrors.length&&e.validationErrors.every((I,i)=>I===g.validationErrors[i])&&Object.entries(e.validationDetails).every(([I,i])=>g.validationDetails[I]===i)}function eog(e){let{id:g,label:I,"aria-labelledby":i,"aria-label":n,labelElementType:C="label"}=e;g=Fh(g);let r=Fh(),o={};I?(i=i?`${r} ${i}`:r,o={id:r,htmlFor:C==="label"?g:void 0}):!i&&!n&&console.warn("If you do not provide a visible label, you must specify an aria-label or aria-labelledby attribute for accessibility");let a=JCg({id:g,"aria-label":n,"aria-labelledby":i});return{labelProps:o,fieldProps:a}}function tog(e){let{description:g,errorMessage:I,isInvalid:i,validationState:n}=e,{labelProps:C,fieldProps:r}=eog(e),o=sce([!!g,!!I,i,n]),a=sce([!!g,!!I,i,n]);return r=Gi(r,{"aria-describedby":[o,a,e["aria-describedby"]].filter(Boolean).join(" ")||void 0}),{labelProps:C,fieldProps:r,descriptionProps:{id:o},errorMessageProps:{id:a}}}const Wce={border:0,clip:"rect(0 0 0 0)",clipPath:"inset(50%)",height:"1px",margin:"-1px",overflow:"hidden",padding:0,position:"absolute",width:"1px",whiteSpace:"nowrap"};function a8(e={}){let{style:g,isFocusable:I}=e,[i,n]=U.useState(!1),{focusWithinProps:C}=mHe({isDisabled:!I,onFocusWithinChange:o=>n(o)}),r=U.useMemo(()=>i?g:g?{...Wce,...g}:Wce,[i]);return{visuallyHiddenProps:{...C,style:r}}}function B_(e){return KCg()?e.altKey:e.ctrlKey}function Ef(e){return Eh()?e.metaKey:e.ctrlKey}const gog=1e3;function Iog(e){let{keyboardDelegate:g,selectionManager:I,onTypeSelect:i}=e,n=U.useRef({search:"",timeout:null}).current,C=r=>{let o=iog(r.key);if(!o||r.ctrlKey||r.metaKey||!r.currentTarget.contains(r.target))return;o===" "&&n.search.trim().length>0&&(r.preventDefault(),"continuePropagation"in r||r.stopPropagation()),n.search+=o;let a=g.getKeyForSearch(n.search,I.focusedKey);a==null&&(a=g.getKeyForSearch(n.search)),a!=null&&(I.setFocusedKey(a),i&&i(a)),clearTimeout(n.timeout),n.timeout=setTimeout(()=>{n.search=""},gog)};return{typeSelectProps:{onKeyDownCapture:g.getKeyForSearch?C:null}}}function iog(e){return e.length===1||!/^[A-Z]/i.test(e)?e:""}function nog(e){let{selectionManager:g,keyboardDelegate:I,ref:i,autoFocus:n=!1,shouldFocusWrap:C=!1,disallowEmptySelection:r=!1,disallowSelectAll:o=!1,selectOnFocus:a=g.selectionBehavior==="replace",disallowTypeAhead:s=!1,shouldUseVirtualFocus:A,allowsTabNavigation:l=!1,isVirtualized:c,scrollRef:u=i,linkBehavior:d="action"}=e,{direction:h}=vm(),m=CHe(),f=V=>{if(V.altKey&&V.key==="Tab"&&V.preventDefault(),!i.current.contains(V.target))return;const S=(P,ge)=>{if(P!=null){if(g.isLink(P)&&d==="selection"&&a&&!B_(V)){Aa.flushSync(()=>{g.setFocusedKey(P,ge)});let q=u.current.querySelector(`[data-key="${P}"]`);m.open(q,V);return}if(g.setFocusedKey(P,ge),g.isLink(P)&&d==="override")return;V.shiftKey&&g.selectionMode==="multiple"?g.extendSelection(P):a&&!B_(V)&&g.replaceSelection(P)}};switch(V.key){case"ArrowDown":if(I.getKeyBelow){var X,W;V.preventDefault();let P=g.focusedKey!=null?I.getKeyBelow(g.focusedKey):(X=I.getFirstKey)===null||X===void 0?void 0:X.call(I);P==null&&C&&(P=(W=I.getFirstKey)===null||W===void 0?void 0:W.call(I,g.focusedKey)),S(P)}break;case"ArrowUp":if(I.getKeyAbove){var R,H;V.preventDefault();let P=g.focusedKey!=null?I.getKeyAbove(g.focusedKey):(R=I.getLastKey)===null||R===void 0?void 0:R.call(I);P==null&&C&&(P=(H=I.getLastKey)===null||H===void 0?void 0:H.call(I,g.focusedKey)),S(P)}break;case"ArrowLeft":if(I.getKeyLeftOf){var Y,K;V.preventDefault();let P=I.getKeyLeftOf(g.focusedKey);P==null&&C&&(P=h==="rtl"?(Y=I.getFirstKey)===null||Y===void 0?void 0:Y.call(I,g.focusedKey):(K=I.getLastKey)===null||K===void 0?void 0:K.call(I,g.focusedKey)),S(P,h==="rtl"?"first":"last")}break;case"ArrowRight":if(I.getKeyRightOf){var F,J;V.preventDefault();let P=I.getKeyRightOf(g.focusedKey);P==null&&C&&(P=h==="rtl"?(F=I.getLastKey)===null||F===void 0?void 0:F.call(I,g.focusedKey):(J=I.getFirstKey)===null||J===void 0?void 0:J.call(I,g.focusedKey)),S(P,h==="rtl"?"last":"first")}break;case"Home":if(I.getFirstKey){V.preventDefault();let P=I.getFirstKey(g.focusedKey,Ef(V));g.setFocusedKey(P),Ef(V)&&V.shiftKey&&g.selectionMode==="multiple"?g.extendSelection(P):a&&g.replaceSelection(P)}break;case"End":if(I.getLastKey){V.preventDefault();let P=I.getLastKey(g.focusedKey,Ef(V));g.setFocusedKey(P),Ef(V)&&V.shiftKey&&g.selectionMode==="multiple"?g.extendSelection(P):a&&g.replaceSelection(P)}break;case"PageDown":if(I.getKeyPageBelow){V.preventDefault();let P=I.getKeyPageBelow(g.focusedKey);S(P)}break;case"PageUp":if(I.getKeyPageAbove){V.preventDefault();let P=I.getKeyPageAbove(g.focusedKey);S(P)}break;case"a":Ef(V)&&g.selectionMode==="multiple"&&o!==!0&&(V.preventDefault(),g.selectAll());break;case"Escape":V.preventDefault(),r||g.clearSelection();break;case"Tab":if(!l){if(V.shiftKey)i.current.focus();else{let P=jr(i.current,{tabbable:!0}),ge,q;do q=P.lastChild(),q&&(ge=q);while(q);ge&&!ge.contains(document.activeElement)&&vs(ge)}break}}},b=U.useRef({top:0,left:0});_Cg(u,"scroll",c?null:()=>{b.current={top:u.current.scrollTop,left:u.current.scrollLeft}});let p=V=>{if(g.isFocused){V.currentTarget.contains(V.target)||g.setFocused(!1);return}if(V.currentTarget.contains(V.target)){if(g.setFocused(!0),g.focusedKey==null){let W=H=>{H!=null&&(g.setFocusedKey(H),a&&g.replaceSelection(H))},R=V.relatedTarget;var S,X;R&&V.currentTarget.compareDocumentPosition(R)&Node.DOCUMENT_POSITION_FOLLOWING?W((S=g.lastSelectedKey)!==null&&S!==void 0?S:I.getLastKey()):W((X=g.firstSelectedKey)!==null&&X!==void 0?X:I.getFirstKey())}else c||(u.current.scrollTop=b.current.top,u.current.scrollLeft=b.current.left);if(!c&&g.focusedKey!=null){let W=u.current.querySelector(`[data-key="${g.focusedKey}"]`);W&&(W.contains(document.activeElement)||vs(W),p_()==="keyboard"&&Ll(W,{containingElement:i.current}))}}},y=V=>{V.currentTarget.contains(V.relatedTarget)||g.setFocused(!1)};const Z=U.useRef(n);U.useEffect(()=>{if(Z.current){let V=null;n==="first"&&(V=I.getFirstKey()),n==="last"&&(V=I.getLastKey());let S=g.selectedKeys;S.size&&(V=S.values().next().value),g.setFocused(!0),g.setFocusedKey(V),V==null&&!A&&gr(i.current)}Z.current=!1},[]);let B=U.useRef(g.focusedKey);U.useEffect(()=>{let V=p_();if(g.isFocused&&g.focusedKey!=null&&(u!=null&&u.current)){let S=u.current.querySelector(`[data-key="${g.focusedKey}"]`);S&&V==="keyboard"&&(c||sHe(u.current,S),Ll(S,{containingElement:i.current}))}g.isFocused&&g.focusedKey==null&&B.current!=null&&gr(i.current),B.current=g.focusedKey},[c,u,g.focusedKey,g.isFocused,i]);let G={onKeyDown:f,onFocus:p,onBlur:y,onMouseDown(V){u.current===V.target&&V.preventDefault()}},{typeSelectProps:v}=Iog({keyboardDelegate:I,selectionManager:g});s||(G=Gi(v,G));let w;return A||(w=g.focusedKey==null?0:-1),{collectionProps:{...G,tabIndex:w}}}function wHe(e){let{selectionManager:g,key:I,ref:i,shouldSelectOnPressUp:n,shouldUseVirtualFocus:C,focus:r,isDisabled:o,onAction:a,allowsDifferentPressOrigin:s,linkBehavior:A="action"}=e,l=CHe(),c=K=>{if(K.pointerType==="keyboard"&&B_(K))g.toggleSelection(I);else{if(g.selectionMode==="none")return;if(g.isLink(I)){if(A==="selection"){l.open(i.current,K),g.setSelectedKeys(g.selectedKeys);return}else if(A==="override"||A==="none")return}g.selectionMode==="single"?g.isSelected(I)&&!g.disallowEmptySelection?g.toggleSelection(I):g.replaceSelection(I):K&&K.shiftKey?g.extendSelection(I):g.selectionBehavior==="toggle"||K&&(Ef(K)||K.pointerType==="touch"||K.pointerType==="virtual")?g.toggleSelection(I):g.replaceSelection(I)}};U.useEffect(()=>{I===g.focusedKey&&g.isFocused&&!C&&(r?r():document.activeElement!==i.current&&gr(i.current))},[i,I,g.focusedKey,g.childFocusStrategy,g.isFocused,C]),o=o||g.isDisabled(I);let u={};!C&&!o?u={tabIndex:I===g.focusedKey?0:-1,onFocus(K){K.target===i.current&&g.setFocusedKey(I)}}:o&&(u.onMouseDown=K=>{K.preventDefault()});let d=g.isLink(I)&&A==="override",h=g.isLink(I)&&A!=="selection"&&A!=="none",m=!o&&g.canSelectItem(I)&&!d,f=(a||h)&&!o,b=f&&(g.selectionBehavior==="replace"?!m:!m||g.isEmpty),p=f&&m&&g.selectionBehavior==="replace",y=b||p,Z=U.useRef(null),B=y&&m,G=U.useRef(!1),v=U.useRef(!1),w=K=>{a&&a(),h&&l.open(i.current,K)},V={};n?(V.onPressStart=K=>{Z.current=K.pointerType,G.current=B,K.pointerType==="keyboard"&&(!y||Hce())&&c(K)},s?(V.onPressUp=b?null:K=>{K.pointerType!=="keyboard"&&m&&c(K)},V.onPress=b?w:null):V.onPress=K=>{if(b||p&&K.pointerType!=="mouse"){if(K.pointerType==="keyboard"&&!Xce())return;w(K)}else K.pointerType!=="keyboard"&&m&&c(K)}):(V.onPressStart=K=>{Z.current=K.pointerType,G.current=B,v.current=b,m&&(K.pointerType==="mouse"&&!b||K.pointerType==="keyboard"&&(!f||Hce()))&&c(K)},V.onPress=K=>{(K.pointerType==="touch"||K.pointerType==="pen"||K.pointerType==="virtual"||K.pointerType==="keyboard"&&y&&Xce()||K.pointerType==="mouse"&&v.current)&&(y?w(K):m&&c(K))}),u["data-key"]=I,V.preventFocusOnPress=C;let{pressProps:S,isPressed:X}=I8(V),W=p?K=>{Z.current==="mouse"&&(K.stopPropagation(),K.preventDefault(),w(K))}:void 0,{longPressProps:R}=brg({isDisabled:!B,onLongPress(K){K.pointerType==="touch"&&(c(K),g.setSelectionBehavior("toggle"))}}),H=K=>{Z.current==="touch"&&G.current&&K.preventDefault()},Y=g.isLink(I)?K=>{Mh.isOpening||K.preventDefault()}:void 0;return{itemProps:Gi(u,m||b?S:{},B?R:{},{onDoubleClick:W,onDragStartCapture:H,onClick:Y}),isPressed:X,isSelected:g.isSelected(I),isFocused:g.isFocused&&g.focusedKey===I,isDisabled:o,allowsSelection:m,hasAction:y}}function Xce(){let e=window.event;return(e==null?void 0:e.key)==="Enter"}function Hce(){let e=window.event;return(e==null?void 0:e.key)===" "||(e==null?void 0:e.code)==="Space"}class Cog{getNextKey(g){for(g=this.collection.getKeyAfter(g);g!=null;){if(this.collection.getItem(g).type==="item"&&!this.disabledKeys.has(g))return g;g=this.collection.getKeyAfter(g)}return null}getPreviousKey(g){for(g=this.collection.getKeyBefore(g);g!=null;){if(this.collection.getItem(g).type==="item"&&!this.disabledKeys.has(g))return g;g=this.collection.getKeyBefore(g)}return null}findKey(g,I,i){let n=this.getItem(g);if(!n)return null;let C=n.getBoundingClientRect();do g=I(g),n=this.getItem(g);while(n&&i(C,n.getBoundingClientRect()));return g}isSameRow(g,I){return g.top===I.top||g.left!==I.left}isSameColumn(g,I){return g.left===I.left||g.top!==I.top}getKeyBelow(g){return this.layout==="grid"&&this.orientation==="vertical"?this.findKey(g,I=>this.getNextKey(I),this.isSameRow):this.getNextKey(g)}getKeyAbove(g){return this.layout==="grid"&&this.orientation==="vertical"?this.findKey(g,I=>this.getPreviousKey(I),this.isSameRow):this.getPreviousKey(g)}getNextColumn(g,I){return I?this.getPreviousKey(g):this.getNextKey(g)}getKeyRightOf(g){return this.layout==="grid"?this.orientation==="vertical"?this.getNextColumn(g,this.direction==="rtl"):this.findKey(g,I=>this.getNextColumn(I,this.direction==="rtl"),this.isSameColumn):this.orientation==="horizontal"?this.getNextColumn(g,this.direction==="rtl"):null}getKeyLeftOf(g){return this.layout==="grid"?this.orientation==="vertical"?this.getNextColumn(g,this.direction==="ltr"):this.findKey(g,I=>this.getNextColumn(I,this.direction==="ltr"),this.isSameColumn):this.orientation==="horizontal"?this.getNextColumn(g,this.direction==="ltr"):null}getFirstKey(){let g=this.collection.getFirstKey();for(;g!=null;){if(this.collection.getItem(g).type==="item"&&!this.disabledKeys.has(g))return g;g=this.collection.getKeyAfter(g)}return null}getLastKey(){let g=this.collection.getLastKey();for(;g!=null;){if(this.collection.getItem(g).type==="item"&&!this.disabledKeys.has(g))return g;g=this.collection.getKeyBefore(g)}return null}getItem(g){return this.ref.current.querySelector(`[data-key="${g}"]`)}getKeyPageAbove(g){let I=this.ref.current,i=this.getItem(g);if(!i)return null;if(!NH(I))return this.getFirstKey();let n=I.getBoundingClientRect(),C=i.getBoundingClientRect();if(this.orientation==="horizontal"){let r=n.x-I.scrollLeft,o=Math.max(0,C.x-r+C.width-n.width);for(;i&&C.x-r>o;)g=this.getKeyAbove(g),i=g==null?null:this.getItem(g),C=i==null?void 0:i.getBoundingClientRect()}else{let r=n.y-I.scrollTop,o=Math.max(0,C.y-r+C.height-n.height);for(;i&&C.y-r>o;)g=this.getKeyAbove(g),i=g==null?null:this.getItem(g),C=i==null?void 0:i.getBoundingClientRect()}return g??this.getFirstKey()}getKeyPageBelow(g){let I=this.ref.current,i=this.getItem(g);if(!i)return null;if(!NH(I))return this.getLastKey();let n=I.getBoundingClientRect(),C=i.getBoundingClientRect();if(this.orientation==="horizontal"){let r=n.x-I.scrollLeft,o=Math.min(I.scrollWidth,C.x-r-C.width+n.width);for(;i&&C.x-rthis.iterateCollection(g))}*iterateCollection(g){let{children:I,items:i}=g;if(typeof I=="function"){if(!i)throw new Error("props.children was a function but props.items is missing");for(let n of g.items)yield*this.getFullNode({value:n},{renderer:I})}else{let n=[];N.Children.forEach(I,r=>{n.push(r)});let C=0;for(let r of n){let o=this.getFullNode({element:r,index:C},{});for(let a of o)C++,yield a}}}getKey(g,I,i,n){if(g.key!=null)return g.key;if(I.type==="cell"&&I.key!=null)return`${n}${I.key}`;let C=I.value;if(C!=null){var r;let o=(r=C.key)!==null&&r!==void 0?r:C.id;if(o==null)throw new Error("No key found for item");return o}return n?`${n}.${I.index}`:`$.${I.index}`}getChildState(g,I){return{renderer:I.renderer||g.renderer}}*getFullNode(g,I,i,n){let C=g.element;if(!C&&g.value&&I&&I.renderer){let a=this.cache.get(g.value);if(a&&(!a.shouldInvalidate||!a.shouldInvalidate(this.context))){a.index=g.index,a.parentKey=n?n.key:null,yield a;return}C=I.renderer(g.value)}if(N.isValidElement(C)){let a=C.type;if(typeof a!="function"&&typeof a.getCollectionNode!="function"){let c=typeof C.type=="function"?C.type.name:C.type;throw new Error(`Unknown element <${c}> in collection.`)}let s=a.getCollectionNode(C.props,this.context),A=g.index,l=s.next();for(;!l.done&&l.value;){let c=l.value;g.index=A;let u=c.key;u||(u=c.element?null:this.getKey(C,g,I,i));let h=[...this.getFullNode({...c,key:u,index:A,wrapper:oog(g.wrapper,c.wrapper)},this.getChildState(I,c),i?`${i}${C.key}`:C.key,n)];for(let m of h){if(m.value=c.value||g.value,m.value&&this.cache.set(m.value,m),g.type&&m.type!==g.type)throw new Error(`Unsupported type <${PF(m.type)}> in <${PF(n.type)}>. Only <${PF(g.type)}> is supported.`);A++,yield m}l=s.next(h)}return}if(g.key==null)return;let r=this,o={type:g.type,props:g.props,key:g.key,parentKey:n?n.key:null,value:g.value,level:n?n.level+1:0,index:g.index,rendered:g.rendered,textValue:g.textValue,"aria-label":g["aria-label"],wrapper:g.wrapper,shouldInvalidate:g.shouldInvalidate,hasChildNodes:g.hasChildNodes,childNodes:Tce(function*(){if(!g.hasChildNodes)return;let a=0;for(let s of g.childNodes()){s.key!=null&&(s.key=`${o.key}${s.key}`),s.index=a;let A=r.getFullNode(s,r.getChildState(I,s),o.key,o);for(let l of A)a++,yield l}})};yield o}constructor(){this.cache=new WeakMap}}function Tce(e){let g=[],I=null;return{*[Symbol.iterator](){for(let i of g)yield i;I||(I=e());for(let i of I)g.push(i),yield i}}}function oog(e,g){if(e&&g)return I=>e(g(I));if(e)return e;if(g)return g}function PF(e){return e[0].toUpperCase()+e.slice(1)}function aog(e,g,I){let i=U.useMemo(()=>new rog,[]),{children:n,items:C,collection:r}=e;return U.useMemo(()=>{if(r)return r;let a=i.build({children:n,items:C},I);return g(a)},[i,n,C,r,I,g])}function wi(e,g){return typeof g.getChildren=="function"?g.getChildren(e.key):e.childNodes}function As(e){return Ul(e,0)}function Ul(e,g){if(g<0)return;let I=0;for(let i of e){if(I===g)return i;I++}}function yc(e){let g;for(let I of e)g=I;return g}function JF(e,g,I){if(g.parentKey===I.parentKey)return g.index-I.index;let i=[...Nce(e,g),g],n=[...Nce(e,I),I],C=i.slice(0,n.length).findIndex((r,o)=>r!==n[o]);return C!==-1?(g=i[C],I=n[C],g.index-I.index):i.findIndex(r=>r===I)>=0?1:(n.findIndex(r=>r===g)>=0,-1)}function Nce(e,g){let I=[];for(;(g==null?void 0:g.parentKey)!=null;)g=e.getItem(g.parentKey),I.unshift(g);return I}function Aog(e,g){let{inputElementType:I="input",isDisabled:i=!1,isRequired:n=!1,isReadOnly:C=!1,type:r="text",validationBehavior:o="aria"}=e,[a,s]=gHe(e.value,e.defaultValue||"",e.onChange),{focusableProps:A}=bHe(e,g),l=jrg({...e,value:a}),{isInvalid:c,validationErrors:u,validationDetails:d}=l.displayValidation,{labelProps:h,fieldProps:m,descriptionProps:f,errorMessageProps:b}=tog({...e,isInvalid:c,errorMessage:e.errorMessage||u}),p=YA(e,{labelable:!0});const y={type:r,pattern:e.pattern};return UCg(g,a,s),Org(e,l,g),U.useEffect(()=>{if(g.current instanceof HH(g.current).HTMLTextAreaElement){let Z=g.current;Object.defineProperty(Z,"defaultValue",{get:()=>Z.value,set:()=>{},configurable:!0})}},[g]),{labelProps:h,inputProps:Gi(p,I==="input"&&y,{disabled:i,readOnly:C,required:n&&o==="native","aria-required":n&&o==="aria"||void 0,"aria-invalid":c||void 0,"aria-errormessage":e["aria-errormessage"],"aria-activedescendant":e["aria-activedescendant"],"aria-autocomplete":e["aria-autocomplete"],"aria-haspopup":e["aria-haspopup"],value:a,onChange:Z=>s(Z.target.value),autoComplete:e.autoComplete,maxLength:e.maxLength,minLength:e.minLength,name:e.name,placeholder:e.placeholder,inputMode:e.inputMode,onCopy:e.onCopy,onCut:e.onCut,onPaste:e.onPaste,onCompositionEnd:e.onCompositionEnd,onCompositionStart:e.onCompositionStart,onCompositionUpdate:e.onCompositionUpdate,onSelect:e.onSelect,onBeforeInput:e.onBeforeInput,onInput:e.onInput,...A,...m}),descriptionProps:f,errorMessageProps:b,isInvalid:c,validationErrors:u,validationDetails:d}}class up{copy(){return new up(this.x,this.y)}equals(g){return this.x===g.x&&this.y===g.y}isOrigin(){return this.x===0&&this.y===0}constructor(g=0,I=0){this.x=g,this.y=I}}class dp{get maxX(){return this.x+this.width}get maxY(){return this.y+this.height}get area(){return this.width*this.height}get topLeft(){return new up(this.x,this.y)}get topRight(){return new up(this.maxX,this.y)}get bottomLeft(){return new up(this.x,this.maxY)}get bottomRight(){return new up(this.maxX,this.maxY)}intersects(g){return this.x<=g.x+g.width&&g.x<=this.x+this.width&&this.y<=g.y+g.height&&g.y<=this.y+this.height}containsRect(g){return this.x<=g.x&&this.y<=g.y&&this.maxX>=g.maxX&&this.maxY>=g.maxY}containsPoint(g){return this.x<=g.x&&this.y<=g.y&&this.maxX>=g.x&&this.maxY>=g.y}getCornerInRect(g){for(let I of["topLeft","topRight","bottomLeft","bottomRight"])if(g.containsPoint(this[I]))return I;return null}equals(g){return g.x===this.x&&g.y===this.y&&g.width===this.width&&g.height===this.height}pointEquals(g){return this.x===g.x&&this.y===g.y}sizeEquals(g){return this.width===g.width&&this.height===g.height}union(g){let I=Math.min(this.x,g.x),i=Math.min(this.y,g.y),n=Math.max(this.maxX,g.maxX)-I,C=Math.max(this.maxY,g.maxY)-i;return new dp(I,i,n,C)}intersection(g){if(!this.intersects(g))return new dp(0,0,0,0);let I=Math.max(this.x,g.x),i=Math.max(this.y,g.y);return new dp(I,i,Math.min(this.maxX,g.maxX)-I,Math.min(this.maxY,g.maxY)-i)}copy(){return new dp(this.x,this.y,this.width,this.height)}constructor(g=0,I=0,i=0,n=0){this.x=g,this.y=I,this.width=i,this.height=n}}let Mf=typeof window<"u"?window.performance:null,kce=Mf&&(Mf.now||Mf.webkitNow||Mf.msNow||Mf.mozNow);kce&&kce.bind(Mf);function A8(e){return e&&e.__esModule?e.default:e}class VHe{isCell(g){return g.type==="cell"}isRow(g){return g.type==="row"||g.type==="item"}findPreviousKey(g,I){let i=g!=null?this.collection.getKeyBefore(g):this.collection.getLastKey();for(;i!=null;){let n=this.collection.getItem(i);if(!this.disabledKeys.has(i)&&(!I||I(n)))return i;i=this.collection.getKeyBefore(i)}}findNextKey(g,I){let i=g!=null?this.collection.getKeyAfter(g):this.collection.getFirstKey();for(;i!=null;){let n=this.collection.getItem(i);if(!this.disabledKeys.has(i)&&(!I||I(n)))return i;i=this.collection.getKeyAfter(i)}}getKeyBelow(g){let I=this.collection.getItem(g);if(I&&(this.isCell(I)&&(g=I.parentKey),g=this.findNextKey(g),g!=null)){if(this.isCell(I)){let i=this.collection.getItem(g);return Ul(wi(i,this.collection),I.index).key}if(this.focusMode==="row")return g}}getKeyAbove(g){let I=this.collection.getItem(g);if(I&&(this.isCell(I)&&(g=I.parentKey),g=this.findPreviousKey(g),g!=null)){if(this.isCell(I)){let i=this.collection.getItem(g);return Ul(wi(i,this.collection),I.index).key}if(this.focusMode==="row")return g}}getKeyRightOf(g){let I=this.collection.getItem(g);if(I){if(this.isRow(I)){let i=wi(I,this.collection);return this.direction==="rtl"?yc(i).key:As(i).key}if(this.isCell(I)){let i=this.collection.getItem(I.parentKey),n=wi(i,this.collection),C=this.direction==="rtl"?Ul(n,I.index-1):Ul(n,I.index+1);return C?C.key:this.focusMode==="row"?I.parentKey:this.direction==="rtl"?this.getFirstKey(g):this.getLastKey(g)}}}getKeyLeftOf(g){let I=this.collection.getItem(g);if(I){if(this.isRow(I)){let i=wi(I,this.collection);return this.direction==="rtl"?As(i).key:yc(i).key}if(this.isCell(I)){let i=this.collection.getItem(I.parentKey),n=wi(i,this.collection),C=this.direction==="rtl"?Ul(n,I.index+1):Ul(n,I.index-1);return C?C.key:this.focusMode==="row"?I.parentKey:this.direction==="rtl"?this.getLastKey(g):this.getFirstKey(g)}}}getFirstKey(g,I){let i;if(g!=null){if(i=this.collection.getItem(g),!i)return;if(this.isCell(i)&&!I){let n=this.collection.getItem(i.parentKey);return As(wi(n,this.collection)).key}}if(g=this.findNextKey(),g!=null&&i&&this.isCell(i)&&I||this.focusMode==="cell"){let n=this.collection.getItem(g);g=As(wi(n,this.collection)).key}return g}getLastKey(g,I){let i;if(g!=null){if(i=this.collection.getItem(g),!i)return;if(this.isCell(i)&&!I){let n=this.collection.getItem(i.parentKey),C=wi(n,this.collection);return yc(C).key}}if(g=this.findPreviousKey(),g!=null&&i&&this.isCell(i)&&I||this.focusMode==="cell"){let n=this.collection.getItem(g),C=wi(n,this.collection);g=yc(C).key}return g}getItem(g){return this.ref.current.querySelector(`[data-key="${g}"]`)}getItemRect(g){var I;if(this.layout)return(I=this.layout.getLayoutInfo(g))===null||I===void 0?void 0:I.rect;let i=this.getItem(g);if(i)return new dp(i.offsetLeft,i.offsetTop,i.offsetWidth,i.offsetHeight)}getPageHeight(){var g,I,i;return this.layout?(g=this.layout.virtualizer)===null||g===void 0?void 0:g.visibleRect.height:(i=this.ref)===null||i===void 0||(I=i.current)===null||I===void 0?void 0:I.offsetHeight}getContentHeight(){var g,I;return this.layout?this.layout.getContentSize().height:(I=this.ref)===null||I===void 0||(g=I.current)===null||g===void 0?void 0:g.scrollHeight}getKeyPageAbove(g){let I=this.getItemRect(g);if(!I)return null;let i=Math.max(0,I.maxY-this.getPageHeight());for(;I&&I.y>i;)g=this.getKeyAbove(g),I=this.getItemRect(g);return g}getKeyPageBelow(g){let I=this.getItemRect(g);if(!I)return null;let i=this.getPageHeight(),n=Math.min(this.getContentHeight(),I.y+i);for(;I&&I.maxY`${e.item} غير المحدد`,longPressToSelect:"اضغط مطولًا للدخول إلى وضع التحديد.",select:"تحديد",selectedAll:"جميع العناصر المحددة.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"لم يتم تحديد عناصر",one:()=>`${g.number(e.count)} عنصر محدد`,other:()=>`${g.number(e.count)} عنصر محدد`})}.`,selectedItem:e=>`${e.item} المحدد`};var WHe={};WHe={deselectedItem:e=>`${e.item} не е избран.`,longPressToSelect:"Натиснете и задръжте за да влезете в избирателен режим.",select:"Изберете",selectedAll:"Всички елементи са избрани.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Няма избрани елементи",one:()=>`${g.number(e.count)} избран елемент`,other:()=>`${g.number(e.count)} избрани елементи`})}.`,selectedItem:e=>`${e.item} избран.`};var XHe={};XHe={deselectedItem:e=>`Položka ${e.item} není vybrána.`,longPressToSelect:"Dlouhým stisknutím přejdete do režimu výběru.",select:"Vybrat",selectedAll:"Vybrány všechny položky.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nevybrány žádné položky",one:()=>`Vybrána ${g.number(e.count)} položka`,other:()=>`Vybráno ${g.number(e.count)} položek`})}.`,selectedItem:e=>`Vybrána položka ${e.item}.`};var HHe={};HHe={deselectedItem:e=>`${e.item} ikke valgt.`,longPressToSelect:"Lav et langt tryk for at aktivere valgtilstand.",select:"Vælg",selectedAll:"Alle elementer valgt.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Ingen elementer valgt",one:()=>`${g.number(e.count)} element valgt`,other:()=>`${g.number(e.count)} elementer valgt`})}.`,selectedItem:e=>`${e.item} valgt.`};var THe={};THe={deselectedItem:e=>`${e.item} nicht ausgewählt.`,longPressToSelect:"Gedrückt halten, um Auswahlmodus zu öffnen.",select:"Auswählen",selectedAll:"Alle Elemente ausgewählt.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Keine Elemente ausgewählt",one:()=>`${g.number(e.count)} Element ausgewählt`,other:()=>`${g.number(e.count)} Elemente ausgewählt`})}.`,selectedItem:e=>`${e.item} ausgewählt.`};var NHe={};NHe={deselectedItem:e=>`Δεν επιλέχθηκε το στοιχείο ${e.item}.`,longPressToSelect:"Πατήστε παρατεταμένα για να μπείτε σε λειτουργία επιλογής.",select:"Επιλογή",selectedAll:"Επιλέχθηκαν όλα τα στοιχεία.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Δεν επιλέχθηκαν στοιχεία",one:()=>`Επιλέχθηκε ${g.number(e.count)} στοιχείο`,other:()=>`Επιλέχθηκαν ${g.number(e.count)} στοιχεία`})}.`,selectedItem:e=>`Επιλέχθηκε το στοιχείο ${e.item}.`};var kHe={};kHe={deselectedItem:e=>`${e.item} not selected.`,select:"Select",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"No items selected",one:()=>`${g.number(e.count)} item selected`,other:()=>`${g.number(e.count)} items selected`})}.`,selectedAll:"All items selected.",selectedItem:e=>`${e.item} selected.`,longPressToSelect:"Long press to enter selection mode."};var YHe={};YHe={deselectedItem:e=>`${e.item} no seleccionado.`,longPressToSelect:"Mantenga pulsado para abrir el modo de selección.",select:"Seleccionar",selectedAll:"Todos los elementos seleccionados.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Ningún elemento seleccionado",one:()=>`${g.number(e.count)} elemento seleccionado`,other:()=>`${g.number(e.count)} elementos seleccionados`})}.`,selectedItem:e=>`${e.item} seleccionado.`};var KHe={};KHe={deselectedItem:e=>`${e.item} pole valitud.`,longPressToSelect:"Valikurežiimi sisenemiseks vajutage pikalt.",select:"Vali",selectedAll:"Kõik üksused valitud.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Üksusi pole valitud",one:()=>`${g.number(e.count)} üksus valitud`,other:()=>`${g.number(e.count)} üksust valitud`})}.`,selectedItem:e=>`${e.item} valitud.`};var xHe={};xHe={deselectedItem:e=>`Kohdetta ${e.item} ei valittu.`,longPressToSelect:"Siirry valintatilaan painamalla pitkään.",select:"Valitse",selectedAll:"Kaikki kohteet valittu.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Ei yhtään kohdetta valittu",one:()=>`${g.number(e.count)} kohde valittu`,other:()=>`${g.number(e.count)} kohdetta valittu`})}.`,selectedItem:e=>`${e.item} valittu.`};var DHe={};DHe={deselectedItem:e=>`${e.item} non sélectionné.`,longPressToSelect:"Appuyez de manière prolongée pour passer en mode de sélection.",select:"Sélectionner",selectedAll:"Tous les éléments sélectionnés.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Aucun élément sélectionné",one:()=>`${g.number(e.count)} élément sélectionné`,other:()=>`${g.number(e.count)} éléments sélectionnés`})}.`,selectedItem:e=>`${e.item} sélectionné.`};var FHe={};FHe={deselectedItem:e=>`${e.item} לא נבחר.`,longPressToSelect:"הקשה ארוכה לכניסה למצב בחירה.",select:"בחר",selectedAll:"כל הפריטים נבחרו.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"לא נבחרו פריטים",one:()=>`פריט ${g.number(e.count)} נבחר`,other:()=>`${g.number(e.count)} פריטים נבחרו`})}.`,selectedItem:e=>`${e.item} נבחר.`};var EHe={};EHe={deselectedItem:e=>`Stavka ${e.item} nije odabrana.`,longPressToSelect:"Dugo pritisnite za ulazak u način odabira.",select:"Odaberite",selectedAll:"Odabrane su sve stavke.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nije odabrana nijedna stavka",one:()=>`Odabrana je ${g.number(e.count)} stavka`,other:()=>`Odabrano je ${g.number(e.count)} stavki`})}.`,selectedItem:e=>`Stavka ${e.item} je odabrana.`};var MHe={};MHe={deselectedItem:e=>`${e.item} nincs kijelölve.`,longPressToSelect:"Nyomja hosszan a kijelöléshez.",select:"Kijelölés",selectedAll:"Az összes elem kijelölve.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Egy elem sincs kijelölve",one:()=>`${g.number(e.count)} elem kijelölve`,other:()=>`${g.number(e.count)} elem kijelölve`})}.`,selectedItem:e=>`${e.item} kijelölve.`};var zHe={};zHe={deselectedItem:e=>`${e.item} non selezionato.`,longPressToSelect:"Premi a lungo per passare alla modalità di selezione.",select:"Seleziona",selectedAll:"Tutti gli elementi selezionati.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nessun elemento selezionato",one:()=>`${g.number(e.count)} elemento selezionato`,other:()=>`${g.number(e.count)} elementi selezionati`})}.`,selectedItem:e=>`${e.item} selezionato.`};var PHe={};PHe={deselectedItem:e=>`${e.item} が選択されていません。`,longPressToSelect:"長押しして選択モードを開きます。",select:"選択",selectedAll:"すべての項目を選択しました。",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"項目が選択されていません",one:()=>`${g.number(e.count)} 項目を選択しました`,other:()=>`${g.number(e.count)} 項目を選択しました`})}。`,selectedItem:e=>`${e.item} を選択しました。`};var JHe={};JHe={deselectedItem:e=>`${e.item}이(가) 선택되지 않았습니다.`,longPressToSelect:"선택 모드로 들어가려면 길게 누르십시오.",select:"선택",selectedAll:"모든 항목이 선택되었습니다.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"선택된 항목이 없습니다",one:()=>`${g.number(e.count)}개 항목이 선택되었습니다`,other:()=>`${g.number(e.count)}개 항목이 선택되었습니다`})}.`,selectedItem:e=>`${e.item}이(가) 선택되었습니다.`};var OHe={};OHe={deselectedItem:e=>`${e.item} nepasirinkta.`,longPressToSelect:"Norėdami įjungti pasirinkimo režimą, paspauskite ir palaikykite.",select:"Pasirinkti",selectedAll:"Pasirinkti visi elementai.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nepasirinktas nė vienas elementas",one:()=>`Pasirinktas ${g.number(e.count)} elementas`,other:()=>`Pasirinkta elementų: ${g.number(e.count)}`})}.`,selectedItem:e=>`Pasirinkta: ${e.item}.`};var _He={};_He={deselectedItem:e=>`Vienums ${e.item} nav atlasīts.`,longPressToSelect:"Ilgi turiet nospiestu. lai ieslēgtu atlases režīmu.",select:"Atlasīt",selectedAll:"Atlasīti visi vienumi.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nav atlasīts neviens vienums",one:()=>`Atlasīto vienumu skaits: ${g.number(e.count)}`,other:()=>`Atlasīto vienumu skaits: ${g.number(e.count)}`})}.`,selectedItem:e=>`Atlasīts vienums ${e.item}.`};var LHe={};LHe={deselectedItem:e=>`${e.item} er ikke valgt.`,longPressToSelect:"Bruk et langt trykk for å gå inn i valgmodus.",select:"Velg",selectedAll:"Alle elementer er valgt.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Ingen elementer er valgt",one:()=>`${g.number(e.count)} element er valgt`,other:()=>`${g.number(e.count)} elementer er valgt`})}.`,selectedItem:e=>`${e.item} er valgt.`};var UHe={};UHe={deselectedItem:e=>`${e.item} niet geselecteerd.`,longPressToSelect:"Druk lang om de selectiemodus te openen.",select:"Selecteren",selectedAll:"Alle items geselecteerd.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Geen items geselecteerd",one:()=>`${g.number(e.count)} item geselecteerd`,other:()=>`${g.number(e.count)} items geselecteerd`})}.`,selectedItem:e=>`${e.item} geselecteerd.`};var QHe={};QHe={deselectedItem:e=>`Nie zaznaczono ${e.item}.`,longPressToSelect:"Naciśnij i przytrzymaj, aby wejść do trybu wyboru.",select:"Zaznacz",selectedAll:"Wszystkie zaznaczone elementy.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nie zaznaczono żadnych elementów",one:()=>`${g.number(e.count)} zaznaczony element`,other:()=>`${g.number(e.count)} zaznaczonych elementów`})}.`,selectedItem:e=>`Zaznaczono ${e.item}.`};var jHe={};jHe={deselectedItem:e=>`${e.item} não selecionado.`,longPressToSelect:"Mantenha pressionado para entrar no modo de seleção.",select:"Selecionar",selectedAll:"Todos os itens selecionados.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nenhum item selecionado",one:()=>`${g.number(e.count)} item selecionado`,other:()=>`${g.number(e.count)} itens selecionados`})}.`,selectedItem:e=>`${e.item} selecionado.`};var $He={};$He={deselectedItem:e=>`${e.item} não selecionado.`,longPressToSelect:"Prima continuamente para entrar no modo de seleção.",select:"Selecionar",selectedAll:"Todos os itens selecionados.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nenhum item selecionado",one:()=>`${g.number(e.count)} item selecionado`,other:()=>`${g.number(e.count)} itens selecionados`})}.`,selectedItem:e=>`${e.item} selecionado.`};var qHe={};qHe={deselectedItem:e=>`${e.item} neselectat.`,longPressToSelect:"Apăsați lung pentru a intra în modul de selectare.",select:"Selectare",selectedAll:"Toate elementele selectate.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Niciun element selectat",one:()=>`${g.number(e.count)} element selectat`,other:()=>`${g.number(e.count)} elemente selectate`})}.`,selectedItem:e=>`${e.item} selectat.`};var eTe={};eTe={deselectedItem:e=>`${e.item} не выбрано.`,longPressToSelect:"Нажмите и удерживайте для входа в режим выбора.",select:"Выбрать",selectedAll:"Выбраны все элементы.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Нет выбранных элементов",one:()=>`${g.number(e.count)} элемент выбран`,other:()=>`${g.number(e.count)} элементов выбрано`})}.`,selectedItem:e=>`${e.item} выбрано.`};var tTe={};tTe={deselectedItem:e=>`Nevybraté položky: ${e.item}.`,longPressToSelect:"Dlhším stlačením prejdite do režimu výberu.",select:"Vybrať",selectedAll:"Všetky vybraté položky.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Žiadne vybraté položky",one:()=>`${g.number(e.count)} vybratá položka`,other:()=>`Počet vybratých položiek:${g.number(e.count)}`})}.`,selectedItem:e=>`Vybraté položky: ${e.item}.`};var gTe={};gTe={deselectedItem:e=>`Element ${e.item} ni izbran.`,longPressToSelect:"Za izbirni način pritisnite in dlje časa držite.",select:"Izberite",selectedAll:"Vsi elementi so izbrani.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Noben element ni izbran",one:()=>`${g.number(e.count)} element je izbran`,other:()=>`${g.number(e.count)} elementov je izbranih`})}.`,selectedItem:e=>`Element ${e.item} je izbran.`};var ITe={};ITe={deselectedItem:e=>`${e.item} nije izabrano.`,longPressToSelect:"Dugo pritisnite za ulazak u režim biranja.",select:"Izaberite",selectedAll:"Izabrane su sve stavke.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nije izabrana nijedna stavka",one:()=>`Izabrana je ${g.number(e.count)} stavka`,other:()=>`Izabrano je ${g.number(e.count)} stavki`})}.`,selectedItem:e=>`${e.item} je izabrano.`};var iTe={};iTe={deselectedItem:e=>`${e.item} ej markerat.`,longPressToSelect:"Tryck länge när du vill öppna väljarläge.",select:"Markera",selectedAll:"Alla markerade objekt.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Inga markerade objekt",one:()=>`${g.number(e.count)} markerat objekt`,other:()=>`${g.number(e.count)} markerade objekt`})}.`,selectedItem:e=>`${e.item} markerat.`};var nTe={};nTe={deselectedItem:e=>`${e.item} seçilmedi.`,longPressToSelect:"Seçim moduna girmek için uzun basın.",select:"Seç",selectedAll:"Tüm ögeler seçildi.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Hiçbir öge seçilmedi",one:()=>`${g.number(e.count)} öge seçildi`,other:()=>`${g.number(e.count)} öge seçildi`})}.`,selectedItem:e=>`${e.item} seçildi.`};var CTe={};CTe={deselectedItem:e=>`${e.item} не вибрано.`,longPressToSelect:"Виконайте довге натиснення, щоб перейти в режим вибору.",select:"Вибрати",selectedAll:"Усі елементи вибрано.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Жодних елементів не вибрано",one:()=>`${g.number(e.count)} елемент вибрано`,other:()=>`Вибрано елементів: ${g.number(e.count)}`})}.`,selectedItem:e=>`${e.item} вибрано.`};var rTe={};rTe={deselectedItem:e=>`未选择 ${e.item}。`,longPressToSelect:"长按以进入选择模式。",select:"选择",selectedAll:"已选择所有项目。",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"未选择项目",one:()=>`已选择 ${g.number(e.count)} 个项目`,other:()=>`已选择 ${g.number(e.count)} 个项目`})}。`,selectedItem:e=>`已选择 ${e.item}。`};var oTe={};oTe={deselectedItem:e=>`未選取「${e.item}」。`,longPressToSelect:"長按以進入選擇模式。",select:"選取",selectedAll:"已選取所有項目。",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"未選取任何項目",one:()=>`已選取 ${g.number(e.count)} 個項目`,other:()=>`已選取 ${g.number(e.count)} 個項目`})}。`,selectedItem:e=>`已選取「${e.item}」。`};gY={"ar-AE":RHe,"bg-BG":WHe,"cs-CZ":XHe,"da-DK":HHe,"de-DE":THe,"el-GR":NHe,"en-US":kHe,"es-ES":YHe,"et-EE":KHe,"fi-FI":xHe,"fr-FR":DHe,"he-IL":FHe,"hr-HR":EHe,"hu-HU":MHe,"it-IT":zHe,"ja-JP":PHe,"ko-KR":JHe,"lt-LT":OHe,"lv-LV":_He,"nb-NO":LHe,"nl-NL":UHe,"pl-PL":QHe,"pt-BR":jHe,"pt-PT":$He,"ro-RO":qHe,"ru-RU":eTe,"sk-SK":tTe,"sl-SI":gTe,"sr-SP":ITe,"sv-SE":iTe,"tr-TR":nTe,"uk-UA":CTe,"zh-CN":rTe,"zh-TW":oTe};function sog(e,g){let{getRowText:I=r=>{var o,a,s,A;return(A=(o=(a=g.collection).getTextValue)===null||o===void 0?void 0:o.call(a,r))!==null&&A!==void 0?A:(s=g.collection.getItem(r))===null||s===void 0?void 0:s.textValue}}=e,i=hy(A8(gY)),n=g.selectionManager.rawSelection,C=U.useRef(n);aHe(()=>{var r;if(!g.selectionManager.isFocused){C.current=n;return}let o=Yce(n,C.current),a=Yce(C.current,n),s=g.selectionManager.selectionBehavior==="replace",A=[];if(g.selectionManager.selectedKeys.size===1&&s){if(g.collection.getItem(g.selectionManager.selectedKeys.keys().next().value)){let l=I(g.selectionManager.selectedKeys.keys().next().value);l&&A.push(i.format("selectedItem",{item:l}))}}else if(o.size===1&&a.size===0){let l=I(o.keys().next().value);l&&A.push(i.format("selectedItem",{item:l}))}else if(a.size===1&&o.size===0&&g.collection.getItem(a.keys().next().value)){let l=I(a.keys().next().value);l&&A.push(i.format("deselectedItem",{item:l}))}g.selectionManager.selectionMode==="multiple"&&(A.length===0||n==="all"||n.size>1||C.current==="all"||((r=C.current)===null||r===void 0?void 0:r.size)>1)&&A.push(n==="all"?i.format("selectedAll"):i.format("selectedCount",{count:n.size})),A.length>0&&vHe(A.join(" ")),C.current=n},[n])}function Yce(e,g){let I=new Set;if(e==="all"||g==="all")return I;for(let i of e.keys())g.has(i)||I.add(i);return I}function log(e){let g=hy(A8(gY)),I=crg(),i=(I==="pointer"||I==="virtual"||I==null)&&typeof window<"u"&&"ontouchstart"in window,n=U.useMemo(()=>{let r=e.selectionManager.selectionMode,o=e.selectionManager.selectionBehavior,a;return i&&(a=g.format("longPressToSelect")),o==="replace"&&r!=="none"&&e.hasItemActions?a:void 0},[e.selectionManager.selectionMode,e.selectionManager.selectionBehavior,e.hasItemActions,g,i]);return qk(n)}function cog(e,g,I){let{isVirtualized:i,keyboardDelegate:n,focusMode:C,scrollRef:r,getRowText:o,onRowAction:a,onCellAction:s}=e,{selectionManager:A}=g;!e["aria-label"]&&!e["aria-labelledby"]&&console.warn("An aria-label or aria-labelledby prop is required for accessibility.");let l=ZHe({usage:"search",sensitivity:"base"}),{direction:c}=vm(),u=g.selectionManager.disabledBehavior,d=U.useMemo(()=>n||new VHe({collection:g.collection,disabledKeys:u==="selection"?new Set:g.disabledKeys,ref:I,direction:c,collator:l,focusMode:C}),[n,g.collection,g.disabledKeys,u,I,c,l,C]),{collectionProps:h}=nog({ref:I,selectionManager:A,keyboardDelegate:d,isVirtualized:i,scrollRef:r}),m=Fh(e.id);s8.set(g,{keyboardDelegate:d,actions:{onRowAction:a,onCellAction:s}});let f=log({selectionManager:A,hasItemActions:!!(a||s)}),b=YA(e,{labelable:!0}),p=U.useCallback(G=>{if(A.isFocused){G.currentTarget.contains(G.target)||A.setFocused(!1);return}G.currentTarget.contains(G.target)&&A.setFocused(!0)},[A]),y=U.useMemo(()=>({onBlur:h.onBlur,onFocus:p}),[p,h.onBlur]),Z=Nrg(I,{isDisabled:g.collection.size!==0}),B=Gi(b,{role:"grid",id:m,"aria-multiselectable":A.selectionMode==="multiple"?"true":void 0},g.isKeyboardNavigationDisabled?y:h,g.collection.size===0&&{tabIndex:Z?-1:0},f);return i&&(B["aria-rowcount"]=g.collection.size,B["aria-colcount"]=g.collection.columnCount),sog({getRowText:o},g),{gridProps:B}}function uog(){return{rowGroupProps:{role:"rowgroup"}}}function dog(e,g,I){let{node:i,isVirtualized:n,shouldSelectOnPressUp:C,onAction:r}=e,{actions:{onRowAction:o}}=s8.get(g),{itemProps:a,...s}=wHe({selectionManager:g.selectionManager,key:i.key,ref:I,isVirtualized:n,shouldSelectOnPressUp:C,onAction:o?()=>o(i.key):r,isDisabled:g.collection.size===0}),A=g.selectionManager.isSelected(i.key),l={role:"row","aria-selected":g.selectionManager.selectionMode!=="none"?A:void 0,"aria-disabled":s.isDisabled||void 0,...a};return n&&(l["aria-rowindex"]=i.index+1),{rowProps:l,...s}}function aTe(e,g,I){let{node:i,isVirtualized:n,focusMode:C="child",shouldSelectOnPressUp:r,onAction:o}=e,{direction:a}=vm(),{keyboardDelegate:s,actions:{onCellAction:A}}=s8.get(g),l=U.useRef(null),c=()=>{let p=jr(I.current);if(C==="child"){if(I.current.contains(document.activeElement)&&I.current!==document.activeElement)return;let y=g.selectionManager.childFocusStrategy==="last"?OF(p):p.firstChild();if(y){gr(y);return}}(l.current!=null&&i.key!==l.current||!I.current.contains(document.activeElement))&&gr(I.current)},{itemProps:u,isPressed:d}=wHe({selectionManager:g.selectionManager,key:i.key,ref:I,isVirtualized:n,focus:c,shouldSelectOnPressUp:r,onAction:A?()=>A(i.key):o,isDisabled:g.collection.size===0}),f=Gi(u,{role:"gridcell",onKeyDownCapture:p=>{if(!p.currentTarget.contains(p.target)||g.isKeyboardNavigationDisabled)return;let y=jr(I.current);switch(y.currentNode=document.activeElement,p.key){case"ArrowLeft":{let Z=a==="rtl"?y.nextNode():y.previousNode();if(C==="child"&&Z===I.current&&(Z=null),Z)p.preventDefault(),p.stopPropagation(),gr(Z),Ll(Z,{containingElement:_l(I.current)});else{if(s.getKeyLeftOf(i.key)!==i.key)break;p.preventDefault(),p.stopPropagation(),C==="cell"&&a==="rtl"?(gr(I.current),Ll(I.current,{containingElement:_l(I.current)})):(y.currentNode=I.current,Z=a==="rtl"?y.firstChild():OF(y),Z&&(gr(Z),Ll(Z,{containingElement:_l(I.current)})))}break}case"ArrowRight":{let Z=a==="rtl"?y.previousNode():y.nextNode();if(C==="child"&&Z===I.current&&(Z=null),Z)p.preventDefault(),p.stopPropagation(),gr(Z),Ll(Z,{containingElement:_l(I.current)});else{if(s.getKeyRightOf(i.key)!==i.key)break;p.preventDefault(),p.stopPropagation(),C==="cell"&&a==="ltr"?(gr(I.current),Ll(I.current,{containingElement:_l(I.current)})):(y.currentNode=I.current,Z=a==="rtl"?OF(y):y.firstChild(),Z&&(gr(Z),Ll(Z,{containingElement:_l(I.current)})))}break}case"ArrowUp":case"ArrowDown":!p.altKey&&I.current.contains(p.target)&&(p.stopPropagation(),p.preventDefault(),I.current.parentElement.dispatchEvent(new KeyboardEvent(p.nativeEvent.type,p.nativeEvent)));break}},onFocus:p=>{if(l.current=i.key,p.target!==I.current){n8()||g.selectionManager.setFocusedKey(i.key);return}requestAnimationFrame(()=>{C==="child"&&document.activeElement===I.current&&c()})}});var b;return n&&(f["aria-colindex"]=((b=i.colIndex)!==null&&b!==void 0?b:i.index)+1),r&&f.tabIndex!=null&&f.onPointerDown==null&&(f.onPointerDown=p=>{let y=p.currentTarget,Z=y.getAttribute("tabindex");y.removeAttribute("tabindex"),requestAnimationFrame(()=>{y.setAttribute("tabindex",Z)})}),{gridCellProps:f,isPressed:d}}function OF(e){let g,I;do I=e.lastChild(),I&&(g=I);while(I);return g}function hog(e,g){let{key:I}=e,i=g.selectionManager,n=Fh(),C=!g.selectionManager.canSelectItem(I),r=g.selectionManager.isSelected(I),o=()=>i.select(I);const a=hy(A8(gY));return{checkboxProps:{id:n,"aria-label":a.format("select"),isSelected:r,isDisabled:C,onChange:o}}}let mog=!1;function DH(){return mog}function l8(e){return e&&e.__esModule?e.default:e}const c8=new WeakMap;function S_(e){return typeof e=="string"?e.replace(/\s*/g,""):""+e}function fog(e,g){let I=c8.get(e);if(!I)throw new Error("Unknown grid");return`${I}-${S_(g)}`}function ATe(e,g,I){let i=c8.get(e);if(!i)throw new Error("Unknown grid");return`${i}-${S_(g)}-${S_(I)}`}function sTe(e,g){return[...e.collection.rowHeaderColumnKeys].map(I=>ATe(e,g,I)).join(" ")}var IY={},lTe={};lTe={ascending:"تصاعدي",ascendingSort:e=>`ترتيب حسب العمود ${e.columnName} بترتيب تصاعدي`,columnSize:e=>`${e.value} بالبكسل`,descending:"تنازلي",descendingSort:e=>`ترتيب حسب العمود ${e.columnName} بترتيب تنازلي`,resizerDescription:"اضغط على مفتاح Enter لبدء تغيير الحجم",select:"تحديد",selectAll:"تحديد الكل",sortable:"عمود قابل للترتيب"};var cTe={};cTe={ascending:"възходящ",ascendingSort:e=>`сортирано по колона ${e.columnName} във възходящ ред`,columnSize:e=>`${e.value} пиксела`,descending:"низходящ",descendingSort:e=>`сортирано по колона ${e.columnName} в низходящ ред`,resizerDescription:"Натиснете „Enter“, за да започнете да преоразмерявате",select:"Изберете",selectAll:"Изберете всичко",sortable:"сортираща колона"};var uTe={};uTe={ascending:"vzestupně",ascendingSort:e=>`řazeno vzestupně podle sloupce ${e.columnName}`,columnSize:e=>`${e.value} pixelů`,descending:"sestupně",descendingSort:e=>`řazeno sestupně podle sloupce ${e.columnName}`,resizerDescription:"Stisknutím klávesy Enter začnete měnit velikost",select:"Vybrat",selectAll:"Vybrat vše",sortable:"sloupec s možností řazení"};var dTe={};dTe={ascending:"stigende",ascendingSort:e=>`sorteret efter kolonne ${e.columnName} i stigende rækkefølge`,columnSize:e=>`${e.value} pixels`,descending:"faldende",descendingSort:e=>`sorteret efter kolonne ${e.columnName} i faldende rækkefølge`,resizerDescription:"Tryk på Enter for at ændre størrelse",select:"Vælg",selectAll:"Vælg alle",sortable:"sorterbar kolonne"};var hTe={};hTe={ascending:"aufsteigend",ascendingSort:e=>`sortiert nach Spalte ${e.columnName} in aufsteigender Reihenfolge`,columnSize:e=>`${e.value} Pixel`,descending:"absteigend",descendingSort:e=>`sortiert nach Spalte ${e.columnName} in absteigender Reihenfolge`,resizerDescription:"Eingabetaste zum Starten der Größenänderung drücken",select:"Auswählen",selectAll:"Alles auswählen",sortable:"sortierbare Spalte"};var mTe={};mTe={ascending:"αύξουσα",ascendingSort:e=>`διαλογή ανά στήλη ${e.columnName} σε αύξουσα σειρά`,columnSize:e=>`${e.value} pixel`,descending:"φθίνουσα",descendingSort:e=>`διαλογή ανά στήλη ${e.columnName} σε φθίνουσα σειρά`,resizerDescription:"Πατήστε Enter για έναρξη της αλλαγής μεγέθους",select:"Επιλογή",selectAll:"Επιλογή όλων",sortable:"Στήλη διαλογής"};var fTe={};fTe={select:"Select",selectAll:"Select All",sortable:"sortable column",ascending:"ascending",descending:"descending",ascendingSort:e=>`sorted by column ${e.columnName} in ascending order`,descendingSort:e=>`sorted by column ${e.columnName} in descending order`,columnSize:e=>`${e.value} pixels`,resizerDescription:"Press Enter to start resizing"};var pTe={};pTe={ascending:"de subida",ascendingSort:e=>`ordenado por columna ${e.columnName} en orden de subida`,columnSize:e=>`${e.value} píxeles`,descending:"de bajada",descendingSort:e=>`ordenado por columna ${e.columnName} en orden de bajada`,resizerDescription:"Pulse Intro para empezar a redimensionar",select:"Seleccionar",selectAll:"Seleccionar todos",sortable:"columna ordenable"};var bTe={};bTe={ascending:"tõusev järjestus",ascendingSort:e=>`sorditud veeru järgi ${e.columnName} tõusvas järjestuses`,columnSize:e=>`${e.value} pikslit`,descending:"laskuv järjestus",descendingSort:e=>`sorditud veeru järgi ${e.columnName} laskuvas järjestuses`,resizerDescription:"Suuruse muutmise alustamiseks vajutage klahvi Enter",select:"Vali",selectAll:"Vali kõik",sortable:"sorditav veerg"};var yTe={};yTe={ascending:"nouseva",ascendingSort:e=>`lajiteltu sarakkeen ${e.columnName} mukaan nousevassa järjestyksessä`,columnSize:e=>`${e.value} pikseliä`,descending:"laskeva",descendingSort:e=>`lajiteltu sarakkeen ${e.columnName} mukaan laskevassa järjestyksessä`,resizerDescription:"Aloita koon muutos painamalla Enter-näppäintä",select:"Valitse",selectAll:"Valitse kaikki",sortable:"lajiteltava sarake"};var ZTe={};ZTe={ascending:"croissant",ascendingSort:e=>`trié en fonction de la colonne ${e.columnName} par ordre croissant`,columnSize:e=>`${e.value} pixels`,descending:"décroissant",descendingSort:e=>`trié en fonction de la colonne ${e.columnName} par ordre décroissant`,resizerDescription:"Appuyez sur Entrée pour commencer le redimensionnement.",select:"Sélectionner",selectAll:"Sélectionner tout",sortable:"colonne triable"};var GTe={};GTe={ascending:"עולה",ascendingSort:e=>`מוין לפי עמודה ${e.columnName} בסדר עולה`,columnSize:e=>`${e.value} פיקסלים`,descending:"יורד",descendingSort:e=>`מוין לפי עמודה ${e.columnName} בסדר יורד`,resizerDescription:"הקש Enter כדי לשנות את הגודל",select:"בחר",selectAll:"בחר הכול",sortable:"עמודה שניתן למיין"};var vTe={};vTe={ascending:"rastući",ascendingSort:e=>`razvrstano po stupcima ${e.columnName} rastućem redoslijedom`,columnSize:e=>`${e.value} piksela`,descending:"padajući",descendingSort:e=>`razvrstano po stupcima ${e.columnName} padajućim redoslijedom`,resizerDescription:"Pritisnite Enter da biste započeli promenu veličine",select:"Odaberite",selectAll:"Odaberite sve",sortable:"stupac koji se može razvrstati"};var BTe={};BTe={ascending:"növekvő",ascendingSort:e=>`rendezve a(z) ${e.columnName} oszlop szerint, növekvő sorrendben`,columnSize:e=>`${e.value} képpont`,descending:"csökkenő",descendingSort:e=>`rendezve a(z) ${e.columnName} oszlop szerint, csökkenő sorrendben`,resizerDescription:"Nyomja le az Enter billentyűt az átméretezés megkezdéséhez",select:"Kijelölés",selectAll:"Összes kijelölése",sortable:"rendezendő oszlop"};var STe={};STe={ascending:"crescente",ascendingSort:e=>`in ordine crescente in base alla colonna ${e.columnName}`,columnSize:e=>`${e.value} pixel`,descending:"decrescente",descendingSort:e=>`in ordine decrescente in base alla colonna ${e.columnName}`,resizerDescription:"Premi Invio per iniziare a ridimensionare",select:"Seleziona",selectAll:"Seleziona tutto",sortable:"colonna ordinabile"};var wTe={};wTe={ascending:"昇順",ascendingSort:e=>`列 ${e.columnName} を昇順で並べ替え`,columnSize:e=>`${e.value} ピクセル`,descending:"降順",descendingSort:e=>`列 ${e.columnName} を降順で並べ替え`,resizerDescription:"Enter キーを押してサイズ変更を開始",select:"選択",selectAll:"すべて選択",sortable:"並べ替え可能な列"};var VTe={};VTe={ascending:"오름차순",ascendingSort:e=>`${e.columnName} 열을 기준으로 오름차순으로 정렬됨`,columnSize:e=>`${e.value} 픽셀`,descending:"내림차순",descendingSort:e=>`${e.columnName} 열을 기준으로 내림차순으로 정렬됨`,resizerDescription:"크기 조정을 시작하려면 Enter를 누르세요.",select:"선택",selectAll:"모두 선택",sortable:"정렬 가능한 열"};var RTe={};RTe={ascending:"didėjančia tvarka",ascendingSort:e=>`surikiuota pagal stulpelį ${e.columnName} didėjančia tvarka`,columnSize:e=>`${e.value} piks.`,descending:"mažėjančia tvarka",descendingSort:e=>`surikiuota pagal stulpelį ${e.columnName} mažėjančia tvarka`,resizerDescription:"Paspauskite „Enter“, kad pradėtumėte keisti dydį",select:"Pasirinkti",selectAll:"Pasirinkti viską",sortable:"rikiuojamas stulpelis"};var WTe={};WTe={ascending:"augošā secībā",ascendingSort:e=>`kārtots pēc kolonnas ${e.columnName} augošā secībā`,columnSize:e=>`${e.value} pikseļi`,descending:"dilstošā secībā",descendingSort:e=>`kārtots pēc kolonnas ${e.columnName} dilstošā secībā`,resizerDescription:"Nospiediet Enter, lai sāktu izmēru mainīšanu",select:"Atlasīt",selectAll:"Atlasīt visu",sortable:"kārtojamā kolonna"};var XTe={};XTe={ascending:"stigende",ascendingSort:e=>`sortert etter kolonne ${e.columnName} i stigende rekkefølge`,columnSize:e=>`${e.value} piksler`,descending:"synkende",descendingSort:e=>`sortert etter kolonne ${e.columnName} i synkende rekkefølge`,resizerDescription:"Trykk på Enter for å starte størrelsesendring",select:"Velg",selectAll:"Velg alle",sortable:"kolonne som kan sorteres"};var HTe={};HTe={ascending:"oplopend",ascendingSort:e=>`gesorteerd in oplopende volgorde in kolom ${e.columnName}`,columnSize:e=>`${e.value} pixels`,descending:"aflopend",descendingSort:e=>`gesorteerd in aflopende volgorde in kolom ${e.columnName}`,resizerDescription:"Druk op Enter om het formaat te wijzigen",select:"Selecteren",selectAll:"Alles selecteren",sortable:"sorteerbare kolom"};var TTe={};TTe={ascending:"rosnąco",ascendingSort:e=>`posortowano według kolumny ${e.columnName} w porządku rosnącym`,columnSize:e=>`Liczba pikseli: ${e.value}`,descending:"malejąco",descendingSort:e=>`posortowano według kolumny ${e.columnName} w porządku malejącym`,resizerDescription:"Naciśnij Enter, aby rozpocząć zmienianie rozmiaru",select:"Zaznacz",selectAll:"Zaznacz wszystko",sortable:"kolumna z możliwością sortowania"};var NTe={};NTe={ascending:"crescente",ascendingSort:e=>`classificado pela coluna ${e.columnName} em ordem crescente`,columnSize:e=>`${e.value} pixels`,descending:"decrescente",descendingSort:e=>`classificado pela coluna ${e.columnName} em ordem decrescente`,resizerDescription:"Pressione Enter para começar a redimensionar",select:"Selecionar",selectAll:"Selecionar tudo",sortable:"coluna classificável"};var kTe={};kTe={ascending:"ascendente",ascendingSort:e=>`Ordenar por coluna ${e.columnName} em ordem ascendente`,columnSize:e=>`${e.value} pixels`,descending:"descendente",descendingSort:e=>`Ordenar por coluna ${e.columnName} em ordem descendente`,resizerDescription:"Prima Enter para iniciar o redimensionamento",select:"Selecionar",selectAll:"Selecionar tudo",sortable:"Coluna ordenável"};var YTe={};YTe={ascending:"crescătoare",ascendingSort:e=>`sortate după coloana ${e.columnName} în ordine crescătoare`,columnSize:e=>`${e.value} pixeli`,descending:"descrescătoare",descendingSort:e=>`sortate după coloana ${e.columnName} în ordine descrescătoare`,resizerDescription:"Apăsați pe Enter pentru a începe redimensionarea",select:"Selectare",selectAll:"Selectare totală",sortable:"coloană sortabilă"};var KTe={};KTe={ascending:"возрастание",ascendingSort:e=>`сортировать столбец ${e.columnName} в порядке возрастания`,columnSize:e=>`${e.value} пикс.`,descending:"убывание",descendingSort:e=>`сортировать столбец ${e.columnName} в порядке убывания`,resizerDescription:"Нажмите клавишу Enter для начала изменения размеров",select:"Выбрать",selectAll:"Выбрать все",sortable:"сортируемый столбец"};var xTe={};xTe={ascending:"vzostupne",ascendingSort:e=>`zoradené zostupne podľa stĺpca ${e.columnName}`,columnSize:e=>`Počet pixelov: ${e.value}`,descending:"zostupne",descendingSort:e=>`zoradené zostupne podľa stĺpca ${e.columnName}`,resizerDescription:"Stlačením klávesu Enter začnete zmenu veľkosti",select:"Vybrať",selectAll:"Vybrať všetko",sortable:"zoraditeľný stĺpec"};var DTe={};DTe={ascending:"naraščajoče",ascendingSort:e=>`razvrščeno po stolpcu ${e.columnName} v naraščajočem vrstnem redu`,columnSize:e=>`${e.value} slikovnih pik`,descending:"padajoče",descendingSort:e=>`razvrščeno po stolpcu ${e.columnName} v padajočem vrstnem redu`,resizerDescription:"Pritisnite tipko Enter da začnete spreminjati velikost",select:"Izberite",selectAll:"Izberite vse",sortable:"razvrstljivi stolpec"};var FTe={};FTe={ascending:"rastući",ascendingSort:e=>`sortirano po kolonama ${e.columnName} rastućim redosledom`,columnSize:e=>`${e.value} piksela`,descending:"padajući",descendingSort:e=>`sortirano po kolonama ${e.columnName} padajućim redosledom`,resizerDescription:"Pritisnite Enter da biste započeli promenu veličine",select:"Izaberite",selectAll:"Izaberite sve",sortable:"kolona koja se može sortirati"};var ETe={};ETe={ascending:"stigande",ascendingSort:e=>`sorterat på kolumn ${e.columnName} i stigande ordning`,columnSize:e=>`${e.value} pixlar`,descending:"fallande",descendingSort:e=>`sorterat på kolumn ${e.columnName} i fallande ordning`,resizerDescription:"Tryck på Retur för att börja ändra storlek",select:"Markera",selectAll:"Markera allt",sortable:"sorterbar kolumn"};var MTe={};MTe={ascending:"artan sırada",ascendingSort:e=>`${e.columnName} sütuna göre artan düzende sırala`,columnSize:e=>`${e.value} piksel`,descending:"azalan sırada",descendingSort:e=>`${e.columnName} sütuna göre azalan düzende sırala`,resizerDescription:"Yeniden boyutlandırmak için Enter'a basın",select:"Seç",selectAll:"Tümünü Seç",sortable:"Sıralanabilir sütun"};var zTe={};zTe={ascending:"висхідний",ascendingSort:e=>`відсортовано за стовпцем ${e.columnName} у висхідному порядку`,columnSize:e=>`${e.value} пікс.`,descending:"низхідний",descendingSort:e=>`відсортовано за стовпцем ${e.columnName} у низхідному порядку`,resizerDescription:"Натисніть Enter, щоб почати зміну розміру",select:"Вибрати",selectAll:"Вибрати все",sortable:"сортувальний стовпець"};var PTe={};PTe={ascending:"升序",ascendingSort:e=>`按列 ${e.columnName} 升序排序`,columnSize:e=>`${e.value} 像素`,descending:"降序",descendingSort:e=>`按列 ${e.columnName} 降序排序`,resizerDescription:"按“输入”键开始调整大小。",select:"选择",selectAll:"全选",sortable:"可排序的列"};var JTe={};JTe={ascending:"遞增",ascendingSort:e=>`已依據「${e.columnName}」欄遞增排序`,columnSize:e=>`${e.value} 像素`,descending:"遞減",descendingSort:e=>`已依據「${e.columnName}」欄遞減排序`,resizerDescription:"按 Enter 鍵以開始調整大小",select:"選取",selectAll:"全選",sortable:"可排序的欄"};IY={"ar-AE":lTe,"bg-BG":cTe,"cs-CZ":uTe,"da-DK":dTe,"de-DE":hTe,"el-GR":mTe,"en-US":fTe,"es-ES":pTe,"et-EE":bTe,"fi-FI":yTe,"fr-FR":ZTe,"he-IL":GTe,"hr-HR":vTe,"hu-HU":BTe,"it-IT":STe,"ja-JP":wTe,"ko-KR":VTe,"lt-LT":RTe,"lv-LV":WTe,"nb-NO":XTe,"nl-NL":HTe,"pl-PL":TTe,"pt-BR":NTe,"pt-PT":kTe,"ro-RO":YTe,"ru-RU":KTe,"sk-SK":xTe,"sl-SI":DTe,"sr-SP":FTe,"sv-SE":ETe,"tr-TR":MTe,"uk-UA":zTe,"zh-CN":PTe,"zh-TW":JTe};class pog extends VHe{isCell(g){return g.type==="cell"||g.type==="rowheader"||g.type==="column"}getKeyBelow(g){let I=this.collection.getItem(g);if(I){if(I.type==="column"){let i=As(wi(I,this.collection));if(i)return i.key;let n=this.getFirstKey();if(n==null)return;let C=this.collection.getItem(n);return Ul(wi(C,this.collection),I.index).key}return super.getKeyBelow(g)}}getKeyAbove(g){let I=this.collection.getItem(g);if(!I)return;if(I.type==="column"){let n=this.collection.getItem(I.parentKey);return n&&n.type==="column"?n.key:void 0}let i=super.getKeyAbove(g);return i!=null&&this.collection.getItem(i).type!=="headerrow"?i:this.isCell(I)?this.collection.columns[I.index].key:this.collection.columns[0].key}findNextColumnKey(g){let I=this.findNextKey(g.key,n=>n.type==="column");if(I!=null)return I;let i=this.collection.headerRows[g.level];for(let n of wi(i,this.collection))if(n.type==="column")return n.key}findPreviousColumnKey(g){let I=this.findPreviousKey(g.key,C=>C.type==="column");if(I!=null)return I;let i=this.collection.headerRows[g.level],n=[...wi(i,this.collection)];for(let C=n.length-1;C>=0;C--){let r=n[C];if(r.type==="column")return r.key}}getKeyRightOf(g){let I=this.collection.getItem(g);if(I)return I.type==="column"?this.direction==="rtl"?this.findPreviousColumnKey(I):this.findNextColumnKey(I):super.getKeyRightOf(g)}getKeyLeftOf(g){let I=this.collection.getItem(g);if(I)return I.type==="column"?this.direction==="rtl"?this.findNextColumnKey(I):this.findPreviousColumnKey(I):super.getKeyLeftOf(g)}getKeyForSearch(g,I){if(!this.collator)return null;let i=this.collection,n=I??this.getFirstKey();if(n==null)return null;let C=i.getItem(n);C.type==="cell"&&(n=C.parentKey);let r=!1;for(;n!=null;){let o=i.getItem(n);for(let a of wi(o,this.collection)){let s=i.columns[a.index];if(i.rowHeaderColumnKeys.has(s.key)&&a.textValue){let A=a.textValue.slice(0,g.length);if(this.collator.compare(A,g)===0)return(I!=null?i.getItem(I):C).type==="cell"?a.key:o.key}}n=this.getKeyBelow(n),n==null&&!r&&(n=this.getFirstKey(),r=!0)}return null}}function bog(e,g,I){let{keyboardDelegate:i,isVirtualized:n,layout:C}=e,r=ZHe({usage:"search",sensitivity:"base"}),{direction:o}=vm(),a=g.selectionManager.disabledBehavior,s=U.useMemo(()=>i||new pog({collection:g.collection,disabledKeys:a==="selection"?new Set:g.disabledKeys,ref:I,direction:o,collator:r,layout:C}),[i,g.collection,g.disabledKeys,a,I,o,r,C]),A=Fh(e.id);c8.set(g,A);let{gridProps:l}=cog({...e,id:A,keyboardDelegate:s},g,I);n&&(l["aria-rowcount"]=g.collection.size+g.collection.headerRows.length),DH()&&"expandedKeys"in g&&(l.role="treegrid");let{column:c,direction:u}=g.sortDescriptor||{},d=hy(l8(IY)),h=U.useMemo(()=>{var f;let b=(f=g.collection.columns.find(p=>p.key===c))===null||f===void 0?void 0:f.textValue;return u&&c?d.format(`${u}Sort`,{columnName:b}):void 0},[u,c,g.collection.columns]),m=qk(h);return aHe(()=>{vHe(h,"assertive",500)},[h]),{gridProps:Gi(l,m,{"aria-describedby":[m["aria-describedby"],l["aria-describedby"]].filter(Boolean).join(" ")})}}function yog(e,g,I){var i,n;let{node:C}=e,r=C.props.allowsSorting,{gridCellProps:o}=aTe({...e,focusMode:"child"},g,I),a=C.props.isSelectionCell&&g.selectionManager.selectionMode==="single",{pressProps:s}=I8({isDisabled:!r||a,onPress(){g.sort(C.key)},ref:I}),{focusableProps:A}=bHe({},I),l=null,c=((i=g.sortDescriptor)===null||i===void 0?void 0:i.column)===C.key,u=(n=g.sortDescriptor)===null||n===void 0?void 0:n.direction;C.props.allowsSorting&&!TH()&&(l=c?u:"none");let d=hy(l8(IY)),h;r&&(h=`${d.format("sortable")}`,c&&u&&TH()&&(h=`${h}, ${d.format(u)}`));let m=qk(h),f=g.collection.size===0;return U.useEffect(()=>{f&&g.selectionManager.focusedKey===C.key&&g.selectionManager.setFocusedKey(null)},[f,g.selectionManager,C.key]),{columnHeaderProps:{...Gi(o,s,A,m,f&&{tabIndex:-1}),role:"columnheader",id:fog(g,C.key),"aria-colspan":C.colspan&&C.colspan>1?C.colspan:null,"aria-sort":l}}}const Kce={expand:{ltr:"ArrowRight",rtl:"ArrowLeft"},collapse:{ltr:"ArrowLeft",rtl:"ArrowRight"}};function Zog(e,g,I){let{node:i,isVirtualized:n}=e,{rowProps:C,...r}=dog(e,g,I),{direction:o}=vm();n&&!(DH()&&"expandedKeys"in g)?C["aria-rowindex"]=i.index+1+g.collection.headerRows.length:delete C["aria-rowindex"];let a={};if(DH()&&"expandedKeys"in g){let u=g.keyMap.get(i.key);if(u!=null){var s,A,l;let d=((s=u.props)===null||s===void 0?void 0:s.UNSTABLE_childItems)||((l=u.props)===null||l===void 0||(A=l.children)===null||A===void 0?void 0:A.length)>g.userColumnCount;a={onKeyDown:h=>{(h.key===Kce.expand[o]&&g.selectionManager.focusedKey===u.key&&d&&g.expandedKeys!=="all"&&!g.expandedKeys.has(u.key)||h.key===Kce.collapse[o]&&g.selectionManager.focusedKey===u.key&&d&&(g.expandedKeys==="all"||g.expandedKeys.has(u.key)))&&(g.toggleKey(u.key),h.stopPropagation())},"aria-expanded":d?g.expandedKeys==="all"||g.expandedKeys.has(i.key):void 0,"aria-level":u.level,"aria-posinset":u.indexOfType+1,"aria-setsize":u.level>1?yc(g.keyMap.get(u==null?void 0:u.parentKey).childNodes).indexOfType+1:yc(g.keyMap.get(g.collection.body.key).childNodes).indexOfType+1}}}let c=r.hasAction?PCg(i.props):{};return{rowProps:{...Gi(C,a,c),"aria-labelledby":sTe(g,i.key)},...r}}function Gog(e,g,I){let{node:i,isVirtualized:n}=e,C={role:"row"};return n&&!(DH()&&"expandedKeys"in g)&&(C["aria-rowindex"]=i.index+1),{rowProps:C}}function vog(e,g,I){let{gridCellProps:i,isPressed:n}=aTe(e,g,I),C=e.node.column.key;return g.collection.rowHeaderColumnKeys.has(C)&&(i.role="rowheader",i.id=ATe(g,e.node.parentKey,C)),{gridCellProps:i,isPressed:n}}function Bog(e,g){let{key:I}=e;const{checkboxProps:i}=hog(e,g);return{checkboxProps:{...i,"aria-labelledby":`${i.id} ${sTe(g,I)}`}}}function Sog(e){let{isEmpty:g,isSelectAll:I,selectionMode:i}=e.selectionManager;return{checkboxProps:{"aria-label":hy(l8(IY)).format(i==="single"?"select":"selectAll"),isSelected:I,isDisabled:i!=="multiple"||e.collection.size===0,isIndeterminate:!g&&!I,onChange:()=>e.selectionManager.toggleSelectAll()}}}function OTe(){return uog()}var _Te={exports:{}},LTe={};/** * @license React * use-sync-external-store-shim.production.min.js * @@ -2018,8 +2018,8 @@ ${s}`:s,l=Tet(o).parse(A,c=>SI(this,x$,t2e).call(this,c,r,I,i));if(C&&((g=l[0])! * @license MIT * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */function Csg(e,g){return Y_(e,g)}const rsg=(e,g)=>{Array.isArray(e.__emotion_styles)&&(e.__emotion_styles=g(e.__emotion_styles))},osg=["values","unit","step"],asg=e=>{const g=Object.keys(e).map(I=>({key:I,val:e[I]}))||[];return g.sort((I,i)=>I.val-i.val),g.reduce((I,i)=>Ke({},I,{[i.key]:i.val}),{})};function Asg(e){const{values:g={xs:0,sm:600,md:900,lg:1200,xl:1536},unit:I="px",step:i=5}=e,n=Qt(e,osg),C=asg(g),r=Object.keys(C);function o(c){return`@media (min-width:${typeof g[c]=="number"?g[c]:c}${I})`}function a(c){return`@media (max-width:${(typeof g[c]=="number"?g[c]:c)-i/100}${I})`}function s(c,u){const d=r.indexOf(u);return`@media (min-width:${typeof g[c]=="number"?g[c]:c}${I}) and (max-width:${(d!==-1&&typeof g[r[d]]=="number"?g[r[d]]:u)-i/100}${I})`}function A(c){return r.indexOf(c)+1`@media (min-width:${S8[e]}px)`};function ao(e,g,I){const i=e.theme||{};if(Array.isArray(g)){const C=i.breakpoints||$ce;return g.reduce((r,o,a)=>(r[C.up(C.keys[a])]=I(g[a]),r),{})}if(typeof g=="object"){const C=i.breakpoints||$ce;return Object.keys(g).reduce((r,o)=>{if(Object.keys(C.values||S8).indexOf(o)!==-1){const a=C.up(o);r[a]=I(g[o],o)}else{const a=o;r[a]=g[a]}return r},{})}return I(g)}function csg(e={}){var g;return((g=e.keys)==null?void 0:g.reduce((i,n)=>{const C=e.up(n);return i[C]={},i},{}))||{}}function usg(e,g){return e.reduce((I,i)=>{const n=I[i];return(!n||Object.keys(n).length===0)&&delete I[i],I},g)}function dsg(e,g){if(typeof e!="object")return{};const I={},i=Object.keys(g);return Array.isArray(e)?i.forEach((n,C)=>{C{e[n]!=null&&(I[n]=!0)}),I}function WY({values:e,breakpoints:g,base:I}){const i=I||dsg(e,g),n=Object.keys(i);if(n.length===0)return e;let C;return n.reduce((r,o,a)=>(Array.isArray(e)?(r[o]=e[a]!=null?e[a]:e[C],C=a):typeof e=="object"?(r[o]=e[o]!=null?e[o]:e[C],C=o):r[o]=e,r),{})}function XY(e,g,I=!0){if(!g||typeof g!="string")return null;if(e&&e.vars&&I){const i=`vars.${g}`.split(".").reduce((n,C)=>n&&n[C]?n[C]:null,e);if(i!=null)return i}return g.split(".").reduce((i,n)=>i&&i[n]!=null?i[n]:null,e)}function MH(e,g,I,i=I){let n;return typeof e=="function"?n=e(I):Array.isArray(e)?n=e[I]||i:n=XY(e,I)||i,g&&(n=g(n,i,e)),n}function ci(e){const{prop:g,cssProperty:I=e.prop,themeKey:i,transform:n}=e,C=r=>{if(r[g]==null)return null;const o=r[g],a=r.theme,s=XY(a,i)||{};return ao(r,o,l=>{let c=MH(s,n,l);return l===c&&typeof l=="string"&&(c=MH(s,n,`${g}${l==="default"?"":si(l)}`,l)),I===!1?c:{[I]:c}})};return C.propTypes={},C.filterProps=[g],C}function hsg(e){const g={};return I=>(g[I]===void 0&&(g[I]=e(I)),g[I])}const msg={m:"margin",p:"padding"},fsg={t:"Top",r:"Right",b:"Bottom",l:"Left",x:["Left","Right"],y:["Top","Bottom"]},qce={marginX:"mx",marginY:"my",paddingX:"px",paddingY:"py"},psg=hsg(e=>{if(e.length>2)if(qce[e])e=qce[e];else return[e];const[g,I]=e.split(""),i=msg[g],n=fsg[I]||"";return Array.isArray(n)?n.map(C=>i+C):[i+n]}),w8=["m","mt","mr","mb","ml","mx","my","margin","marginTop","marginRight","marginBottom","marginLeft","marginX","marginY","marginInline","marginInlineStart","marginInlineEnd","marginBlock","marginBlockStart","marginBlockEnd"],V8=["p","pt","pr","pb","pl","px","py","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingX","paddingY","paddingInline","paddingInlineStart","paddingInlineEnd","paddingBlock","paddingBlockStart","paddingBlockEnd"];[...w8,...V8];function Mw(e,g,I,i){var n;const C=(n=XY(e,g,!1))!=null?n:I;return typeof C=="number"?r=>typeof r=="string"?r:C*r:Array.isArray(C)?r=>typeof r=="string"?r:C[r]:typeof C=="function"?C:()=>{}}function WNe(e){return Mw(e,"spacing",8)}function zw(e,g){if(typeof g=="string"||g==null)return g;const I=Math.abs(g),i=e(I);return g>=0?i:typeof i=="number"?-i:`-${i}`}function bsg(e,g){return I=>e.reduce((i,n)=>(i[n]=zw(g,I),i),{})}function ysg(e,g,I,i){if(g.indexOf(I)===-1)return null;const n=psg(I),C=bsg(n,i),r=e[I];return ao(e,r,C)}function XNe(e,g){const I=WNe(e.theme);return Object.keys(e).map(i=>ysg(e,g,i,I)).reduce(kv,{})}function OI(e){return XNe(e,w8)}OI.propTypes={};OI.filterProps=w8;function _I(e){return XNe(e,V8)}_I.propTypes={};_I.filterProps=V8;function Zsg(e=8){if(e.mui)return e;const g=WNe({spacing:e}),I=(...i)=>(i.length===0?[1]:i).map(C=>{const r=g(C);return typeof r=="number"?`${r}px`:r}).join(" ");return I.mui=!0,I}function HY(...e){const g=e.reduce((i,n)=>(n.filterProps.forEach(C=>{i[C]=n}),i),{}),I=i=>Object.keys(i).reduce((n,C)=>g[C]?kv(n,g[C](i)):n,{});return I.propTypes={},I.filterProps=e.reduce((i,n)=>i.concat(n.filterProps),[]),I}function zr(e){return typeof e!="number"?e:`${e}px solid`}function lo(e,g){return ci({prop:e,themeKey:"borders",transform:g})}const Gsg=lo("border",zr),vsg=lo("borderTop",zr),Bsg=lo("borderRight",zr),Ssg=lo("borderBottom",zr),wsg=lo("borderLeft",zr),Vsg=lo("borderColor"),Rsg=lo("borderTopColor"),Wsg=lo("borderRightColor"),Xsg=lo("borderBottomColor"),Hsg=lo("borderLeftColor"),Tsg=lo("outline",zr),Nsg=lo("outlineColor"),TY=e=>{if(e.borderRadius!==void 0&&e.borderRadius!==null){const g=Mw(e.theme,"shape.borderRadius",4),I=i=>({borderRadius:zw(g,i)});return ao(e,e.borderRadius,I)}return null};TY.propTypes={};TY.filterProps=["borderRadius"];HY(Gsg,vsg,Bsg,Ssg,wsg,Vsg,Rsg,Wsg,Xsg,Hsg,TY,Tsg,Nsg);const NY=e=>{if(e.gap!==void 0&&e.gap!==null){const g=Mw(e.theme,"spacing",8),I=i=>({gap:zw(g,i)});return ao(e,e.gap,I)}return null};NY.propTypes={};NY.filterProps=["gap"];const kY=e=>{if(e.columnGap!==void 0&&e.columnGap!==null){const g=Mw(e.theme,"spacing",8),I=i=>({columnGap:zw(g,i)});return ao(e,e.columnGap,I)}return null};kY.propTypes={};kY.filterProps=["columnGap"];const YY=e=>{if(e.rowGap!==void 0&&e.rowGap!==null){const g=Mw(e.theme,"spacing",8),I=i=>({rowGap:zw(g,i)});return ao(e,e.rowGap,I)}return null};YY.propTypes={};YY.filterProps=["rowGap"];const ksg=ci({prop:"gridColumn"}),Ysg=ci({prop:"gridRow"}),Ksg=ci({prop:"gridAutoFlow"}),xsg=ci({prop:"gridAutoColumns"}),Dsg=ci({prop:"gridAutoRows"}),Fsg=ci({prop:"gridTemplateColumns"}),Esg=ci({prop:"gridTemplateRows"}),Msg=ci({prop:"gridTemplateAreas"}),zsg=ci({prop:"gridArea"});HY(NY,kY,YY,ksg,Ysg,Ksg,xsg,Dsg,Fsg,Esg,Msg,zsg);function qp(e,g){return g==="grey"?g:e}const Psg=ci({prop:"color",themeKey:"palette",transform:qp}),Jsg=ci({prop:"bgcolor",cssProperty:"backgroundColor",themeKey:"palette",transform:qp}),Osg=ci({prop:"backgroundColor",themeKey:"palette",transform:qp});HY(Psg,Jsg,Osg);function Ar(e){return e<=1&&e!==0?`${e*100}%`:e}const _sg=ci({prop:"width",transform:Ar}),R8=e=>{if(e.maxWidth!==void 0&&e.maxWidth!==null){const g=I=>{var i,n;const C=((i=e.theme)==null||(i=i.breakpoints)==null||(i=i.values)==null?void 0:i[I])||S8[I];return C?((n=e.theme)==null||(n=n.breakpoints)==null?void 0:n.unit)!=="px"?{maxWidth:`${C}${e.theme.breakpoints.unit}`}:{maxWidth:C}:{maxWidth:Ar(I)}};return ao(e,e.maxWidth,g)}return null};R8.filterProps=["maxWidth"];const Lsg=ci({prop:"minWidth",transform:Ar}),Usg=ci({prop:"height",transform:Ar}),Qsg=ci({prop:"maxHeight",transform:Ar}),jsg=ci({prop:"minHeight",transform:Ar});ci({prop:"size",cssProperty:"width",transform:Ar});ci({prop:"size",cssProperty:"height",transform:Ar});const $sg=ci({prop:"boxSizing"});HY(_sg,R8,Lsg,Usg,Qsg,jsg,$sg);const qsg={border:{themeKey:"borders",transform:zr},borderTop:{themeKey:"borders",transform:zr},borderRight:{themeKey:"borders",transform:zr},borderBottom:{themeKey:"borders",transform:zr},borderLeft:{themeKey:"borders",transform:zr},borderColor:{themeKey:"palette"},borderTopColor:{themeKey:"palette"},borderRightColor:{themeKey:"palette"},borderBottomColor:{themeKey:"palette"},borderLeftColor:{themeKey:"palette"},outline:{themeKey:"borders",transform:zr},outlineColor:{themeKey:"palette"},borderRadius:{themeKey:"shape.borderRadius",style:TY},color:{themeKey:"palette",transform:qp},bgcolor:{themeKey:"palette",cssProperty:"backgroundColor",transform:qp},backgroundColor:{themeKey:"palette",transform:qp},p:{style:_I},pt:{style:_I},pr:{style:_I},pb:{style:_I},pl:{style:_I},px:{style:_I},py:{style:_I},padding:{style:_I},paddingTop:{style:_I},paddingRight:{style:_I},paddingBottom:{style:_I},paddingLeft:{style:_I},paddingX:{style:_I},paddingY:{style:_I},paddingInline:{style:_I},paddingInlineStart:{style:_I},paddingInlineEnd:{style:_I},paddingBlock:{style:_I},paddingBlockStart:{style:_I},paddingBlockEnd:{style:_I},m:{style:OI},mt:{style:OI},mr:{style:OI},mb:{style:OI},ml:{style:OI},mx:{style:OI},my:{style:OI},margin:{style:OI},marginTop:{style:OI},marginRight:{style:OI},marginBottom:{style:OI},marginLeft:{style:OI},marginX:{style:OI},marginY:{style:OI},marginInline:{style:OI},marginInlineStart:{style:OI},marginInlineEnd:{style:OI},marginBlock:{style:OI},marginBlockStart:{style:OI},marginBlockEnd:{style:OI},displayPrint:{cssProperty:!1,transform:e=>({"@media print":{display:e}})},display:{},overflow:{},textOverflow:{},visibility:{},whiteSpace:{},flexBasis:{},flexDirection:{},flexWrap:{},justifyContent:{},alignItems:{},alignContent:{},order:{},flex:{},flexGrow:{},flexShrink:{},alignSelf:{},justifyItems:{},justifySelf:{},gap:{style:NY},rowGap:{style:YY},columnGap:{style:kY},gridColumn:{},gridRow:{},gridAutoFlow:{},gridAutoColumns:{},gridAutoRows:{},gridTemplateColumns:{},gridTemplateRows:{},gridTemplateAreas:{},gridArea:{},position:{},zIndex:{themeKey:"zIndex"},top:{},right:{},bottom:{},left:{},boxShadow:{themeKey:"shadows"},width:{transform:Ar},maxWidth:{style:R8},minWidth:{transform:Ar},height:{transform:Ar},maxHeight:{transform:Ar},minHeight:{transform:Ar},boxSizing:{},fontFamily:{themeKey:"typography"},fontSize:{themeKey:"typography"},fontStyle:{themeKey:"typography"},fontWeight:{themeKey:"typography"},letterSpacing:{},textTransform:{},lineHeight:{},textAlign:{},typography:{cssProperty:!1,themeKey:"typography"}},KY=qsg;function elg(...e){const g=e.reduce((i,n)=>i.concat(Object.keys(n)),[]),I=new Set(g);return e.every(i=>I.size===Object.keys(i).length)}function tlg(e,g){return typeof e=="function"?e(g):e}function glg(){function e(I,i,n,C){const r={[I]:i,theme:n},o=C[I];if(!o)return{[I]:i};const{cssProperty:a=I,themeKey:s,transform:A,style:l}=o;if(i==null)return null;if(s==="typography"&&i==="inherit")return{[I]:i};const c=XY(n,s)||{};return l?l(r):ao(r,i,d=>{let h=MH(c,A,d);return d===h&&typeof d=="string"&&(h=MH(c,A,`${I}${d==="default"?"":si(d)}`,d)),a===!1?h:{[a]:h}})}function g(I){var i;const{sx:n,theme:C={}}=I||{};if(!n)return null;const r=(i=C.unstable_sxConfig)!=null?i:KY;function o(a){let s=a;if(typeof a=="function")s=a(C);else if(typeof a!="object")return a;if(!s)return null;const A=csg(C.breakpoints),l=Object.keys(A);let c=A;return Object.keys(s).forEach(u=>{const d=tlg(s[u],C);if(d!=null)if(typeof d=="object")if(r[u])c=kv(c,e(u,d,C,r));else{const h=ao({theme:C},d,m=>({[u]:m}));elg(h,d)?c[u]=g({sx:d,theme:C}):c=kv(c,h)}else c=kv(c,e(u,d,C,r))}),usg(l,c)}return Array.isArray(n)?n.map(o):o(n)}return g}const HNe=glg();HNe.filterProps=["sx"];const W8=HNe,Ilg=["breakpoints","palette","spacing","shape"];function X8(e={},...g){const{breakpoints:I={},palette:i={},spacing:n,shape:C={}}=e,r=Qt(e,Ilg),o=Asg(I),a=Zsg(n);let s=MC({breakpoints:o,direction:"ltr",components:{},palette:Ke({mode:"light"},i),spacing:a,shape:Ke({},lsg,C)},r);return s=g.reduce((A,l)=>MC(A,l),s),s.unstable_sxConfig=Ke({},KY,r==null?void 0:r.unstable_sxConfig),s.unstable_sx=function(l){return W8({sx:l,theme:this})},s}function ilg(e){return Object.keys(e).length===0}function nlg(e=null){const g=U.useContext(v8);return!g||ilg(g)?e:g}const Clg=X8();function H8(e=Clg){return nlg(e)}function rlg({styles:e,themeId:g,defaultTheme:I={}}){const i=H8(I),n=typeof e=="function"?e(g&&i[g]||i):e;return Oe.jsx(nsg,{styles:n})}const olg=["sx"],alg=e=>{var g,I;const i={systemProps:{},otherProps:{}},n=(g=e==null||(I=e.theme)==null?void 0:I.unstable_sxConfig)!=null?g:KY;return Object.keys(e).forEach(C=>{n[C]?i.systemProps[C]=e[C]:i.otherProps[C]=e[C]}),i};function Alg(e){const{sx:g}=e,I=Qt(e,olg),{systemProps:i,otherProps:n}=alg(I);let C;return Array.isArray(g)?C=[i,...g]:typeof g=="function"?C=(...r)=>{const o=g(...r);return ss(o)?Ke({},i,o):i}:C=Ke({},i,g),Ke({},n,{sx:C})}function TNe(e){var g,I,i="";if(typeof e=="string"||typeof e=="number")i+=e;else if(typeof e=="object")if(Array.isArray(e))for(g=0;g{n==="color"?i+=eue(i)?e[n]:si(e[n]):i+=`${eue(i)?n:si(n)}${si(e[n].toString())}`}),i}const llg=["name","slot","skipVariantsResolver","skipSx","overridesResolver"];function clg(e){return Object.keys(e).length===0}function ulg(e){return typeof e=="string"&&e.charCodeAt(0)>96}const dlg=(e,g)=>g.components&&g.components[e]&&g.components[e].styleOverrides?g.components[e].styleOverrides:null,zH=e=>{const g={};return e&&e.forEach(I=>{const i=NNe(I.props);g[i]=I.style}),g},hlg=(e,g)=>{let I=[];return g&&g.components&&g.components[e]&&g.components[e].variants&&(I=g.components[e].variants),zH(I)},PH=(e,g,I)=>{const{ownerState:i={}}=e,n=[];return I&&I.forEach(C=>{let r=!0;Object.keys(C.props).forEach(o=>{i[o]!==C.props[o]&&e[o]!==C.props[o]&&(r=!1)}),r&&n.push(g[NNe(C.props)])}),n},mlg=(e,g,I,i)=>{var n;const C=I==null||(n=I.components)==null||(n=n[i])==null?void 0:n.variants;return PH(e,g,C)};function Yv(e){return e!=="ownerState"&&e!=="theme"&&e!=="sx"&&e!=="as"}const flg=X8(),plg=e=>e&&e.charAt(0).toLowerCase()+e.slice(1);function MW({defaultTheme:e,theme:g,themeId:I}){return clg(g)?e:g[I]||g}function blg(e){return e?(g,I)=>I[e]:null}const tue=({styledArg:e,props:g,defaultTheme:I,themeId:i})=>{const n=e(Ke({},g,{theme:MW(Ke({},g,{defaultTheme:I,themeId:i}))}));let C;if(n&&n.variants&&(C=n.variants,delete n.variants),C){const r=PH(g,zH(C),C);return[n,...r]}return n};function ylg(e={}){const{themeId:g,defaultTheme:I=flg,rootShouldForwardProp:i=Yv,slotShouldForwardProp:n=Yv}=e,C=r=>W8(Ke({},r,{theme:MW(Ke({},r,{defaultTheme:I,themeId:g}))}));return C.__mui_systemSx=!0,(r,o={})=>{rsg(r,y=>y.filter(Z=>!(Z!=null&&Z.__mui_systemSx)));const{name:a,slot:s,skipVariantsResolver:A,skipSx:l,overridesResolver:c=blg(plg(s))}=o,u=Qt(o,llg),d=A!==void 0?A:s&&s!=="Root"&&s!=="root"||!1,h=l||!1;let m,f=Yv;s==="Root"||s==="root"?f=i:s?f=n:ulg(r)&&(f=void 0);const b=Csg(r,Ke({shouldForwardProp:f,label:m},u)),p=(y,...Z)=>{const B=Z?Z.map(V=>{if(typeof V=="function"&&V.__emotion_real!==V)return S=>tue({styledArg:V,props:S,defaultTheme:I,themeId:g});if(ss(V)){let S=V,X;return V&&V.variants&&(X=V.variants,delete S.variants,S=W=>{let R=V;return PH(W,zH(X),X).forEach(Y=>{R=MC(R,Y)}),R}),S}return V}):[];let G=y;if(ss(y)){let V;y&&y.variants&&(V=y.variants,delete G.variants,G=S=>{let X=y;return PH(S,zH(V),V).forEach(R=>{X=MC(X,R)}),X})}else typeof y=="function"&&y.__emotion_real!==y&&(G=V=>tue({styledArg:y,props:V,defaultTheme:I,themeId:g}));a&&c&&B.push(V=>{const S=MW(Ke({},V,{defaultTheme:I,themeId:g})),X=dlg(a,S);if(X){const W={};return Object.entries(X).forEach(([R,H])=>{W[R]=typeof H=="function"?H(Ke({},V,{theme:S})):H}),c(V,W)}return null}),a&&!d&&B.push(V=>{const S=MW(Ke({},V,{defaultTheme:I,themeId:g}));return mlg(V,hlg(a,S),S,a)}),h||B.push(C);const v=B.length-Z.length;if(Array.isArray(y)&&v>0){const V=new Array(v).fill("");G=[...y,...V],G.raw=[...y.raw,...V]}const w=b(G,...B);return r.muiName&&(w.muiName=r.muiName),w};return b.withConfig&&(p.withConfig=b.withConfig),p}}function Zlg(e){const{theme:g,name:I,props:i}=e;return!g||!g.components||!g.components[I]||!g.components[I].defaultProps?i:ANe(g.components[I].defaultProps,i)}function Glg({props:e,name:g,defaultTheme:I,themeId:i}){let n=H8(I);return i&&(n=n[i]||n),Zlg({theme:n,name:g,props:e})}function T8(e,g=0,I=1){return Math.min(Math.max(g,e),I)}function vlg(e){e=e.slice(1);const g=new RegExp(`.{1,${e.length>=6?2:1}}`,"g");let I=e.match(g);return I&&I[0].length===1&&(I=I.map(i=>i+i)),I?`rgb${I.length===4?"a":""}(${I.map((i,n)=>n<3?parseInt(i,16):Math.round(parseInt(i,16)/255*1e3)/1e3).join(", ")})`:""}function Ph(e){if(e.type)return e;if(e.charAt(0)==="#")return Ph(vlg(e));const g=e.indexOf("("),I=e.substring(0,g);if(["rgb","rgba","hsl","hsla","color"].indexOf(I)===-1)throw new Error(Uc(9,e));let i=e.substring(g+1,e.length-1),n;if(I==="color"){if(i=i.split(" "),n=i.shift(),i.length===4&&i[3].charAt(0)==="/"&&(i[3]=i[3].slice(1)),["srgb","display-p3","a98-rgb","prophoto-rgb","rec-2020"].indexOf(n)===-1)throw new Error(Uc(10,n))}else i=i.split(",");return i=i.map(C=>parseFloat(C)),{type:I,values:i,colorSpace:n}}function xY(e){const{type:g,colorSpace:I}=e;let{values:i}=e;return g.indexOf("rgb")!==-1?i=i.map((n,C)=>C<3?parseInt(n,10):n):g.indexOf("hsl")!==-1&&(i[1]=`${i[1]}%`,i[2]=`${i[2]}%`),g.indexOf("color")!==-1?i=`${I} ${i.join(" ")}`:i=`${i.join(", ")}`,`${g}(${i})`}function Blg(e){e=Ph(e);const{values:g}=e,I=g[0],i=g[1]/100,n=g[2]/100,C=i*Math.min(n,1-n),r=(s,A=(s+I/30)%12)=>n-C*Math.max(Math.min(A-3,9-A,1),-1);let o="rgb";const a=[Math.round(r(0)*255),Math.round(r(8)*255),Math.round(r(4)*255)];return e.type==="hsla"&&(o+="a",a.push(g[3])),xY({type:o,values:a})}function gue(e){e=Ph(e);let g=e.type==="hsl"||e.type==="hsla"?Ph(Blg(e)).values:e.values;return g=g.map(I=>(e.type!=="color"&&(I/=255),I<=.03928?I/12.92:((I+.055)/1.055)**2.4)),Number((.2126*g[0]+.7152*g[1]+.0722*g[2]).toFixed(3))}function Slg(e,g){const I=gue(e),i=gue(g);return(Math.max(I,i)+.05)/(Math.min(I,i)+.05)}function rA(e,g){return e=Ph(e),g=T8(g),(e.type==="rgb"||e.type==="hsl")&&(e.type+="a"),e.type==="color"?e.values[3]=`/${g}`:e.values[3]=g,xY(e)}function wlg(e,g){if(e=Ph(e),g=T8(g),e.type.indexOf("hsl")!==-1)e.values[2]*=1-g;else if(e.type.indexOf("rgb")!==-1||e.type.indexOf("color")!==-1)for(let I=0;I<3;I+=1)e.values[I]*=1-g;return xY(e)}function Vlg(e,g){if(e=Ph(e),g=T8(g),e.type.indexOf("hsl")!==-1)e.values[2]+=(100-e.values[2])*g;else if(e.type.indexOf("rgb")!==-1)for(let I=0;I<3;I+=1)e.values[I]+=(255-e.values[I])*g;else if(e.type.indexOf("color")!==-1)for(let I=0;I<3;I+=1)e.values[I]+=(1-e.values[I])*g;return xY(e)}function Rlg(e,g){return Ke({toolbar:{minHeight:56,[e.up("xs")]:{"@media (orientation: landscape)":{minHeight:48}},[e.up("sm")]:{minHeight:64}}},g)}const Wlg={black:"#000",white:"#fff"},hS=Wlg,Xlg={50:"#fafafa",100:"#f5f5f5",200:"#eeeeee",300:"#e0e0e0",400:"#bdbdbd",500:"#9e9e9e",600:"#757575",700:"#616161",800:"#424242",900:"#212121",A100:"#f5f5f5",A200:"#eeeeee",A400:"#bdbdbd",A700:"#616161"},Hlg=Xlg,Tlg={50:"#f3e5f5",100:"#e1bee7",200:"#ce93d8",300:"#ba68c8",400:"#ab47bc",500:"#9c27b0",600:"#8e24aa",700:"#7b1fa2",800:"#6a1b9a",900:"#4a148c",A100:"#ea80fc",A200:"#e040fb",A400:"#d500f9",A700:"#aa00ff"},sf=Tlg,Nlg={50:"#ffebee",100:"#ffcdd2",200:"#ef9a9a",300:"#e57373",400:"#ef5350",500:"#f44336",600:"#e53935",700:"#d32f2f",800:"#c62828",900:"#b71c1c",A100:"#ff8a80",A200:"#ff5252",A400:"#ff1744",A700:"#d50000"},lf=Nlg,klg={50:"#fff3e0",100:"#ffe0b2",200:"#ffcc80",300:"#ffb74d",400:"#ffa726",500:"#ff9800",600:"#fb8c00",700:"#f57c00",800:"#ef6c00",900:"#e65100",A100:"#ffd180",A200:"#ffab40",A400:"#ff9100",A700:"#ff6d00"},BZ=klg,Ylg={50:"#e3f2fd",100:"#bbdefb",200:"#90caf9",300:"#64b5f6",400:"#42a5f5",500:"#2196f3",600:"#1e88e5",700:"#1976d2",800:"#1565c0",900:"#0d47a1",A100:"#82b1ff",A200:"#448aff",A400:"#2979ff",A700:"#2962ff"},cf=Ylg,Klg={50:"#e1f5fe",100:"#b3e5fc",200:"#81d4fa",300:"#4fc3f7",400:"#29b6f6",500:"#03a9f4",600:"#039be5",700:"#0288d1",800:"#0277bd",900:"#01579b",A100:"#80d8ff",A200:"#40c4ff",A400:"#00b0ff",A700:"#0091ea"},uf=Klg,xlg={50:"#e8f5e9",100:"#c8e6c9",200:"#a5d6a7",300:"#81c784",400:"#66bb6a",500:"#4caf50",600:"#43a047",700:"#388e3c",800:"#2e7d32",900:"#1b5e20",A100:"#b9f6ca",A200:"#69f0ae",A400:"#00e676",A700:"#00c853"},df=xlg,Dlg=["mode","contrastThreshold","tonalOffset"],Iue={text:{primary:"rgba(0, 0, 0, 0.87)",secondary:"rgba(0, 0, 0, 0.6)",disabled:"rgba(0, 0, 0, 0.38)"},divider:"rgba(0, 0, 0, 0.12)",background:{paper:hS.white,default:hS.white},action:{active:"rgba(0, 0, 0, 0.54)",hover:"rgba(0, 0, 0, 0.04)",hoverOpacity:.04,selected:"rgba(0, 0, 0, 0.08)",selectedOpacity:.08,disabled:"rgba(0, 0, 0, 0.26)",disabledBackground:"rgba(0, 0, 0, 0.12)",disabledOpacity:.38,focus:"rgba(0, 0, 0, 0.12)",focusOpacity:.12,activatedOpacity:.12}},QF={text:{primary:hS.white,secondary:"rgba(255, 255, 255, 0.7)",disabled:"rgba(255, 255, 255, 0.5)",icon:"rgba(255, 255, 255, 0.5)"},divider:"rgba(255, 255, 255, 0.12)",background:{paper:"#121212",default:"#121212"},action:{active:hS.white,hover:"rgba(255, 255, 255, 0.08)",hoverOpacity:.08,selected:"rgba(255, 255, 255, 0.16)",selectedOpacity:.16,disabled:"rgba(255, 255, 255, 0.3)",disabledBackground:"rgba(255, 255, 255, 0.12)",disabledOpacity:.38,focus:"rgba(255, 255, 255, 0.12)",focusOpacity:.12,activatedOpacity:.24}};function iue(e,g,I,i){const n=i.light||i,C=i.dark||i*1.5;e[g]||(e.hasOwnProperty(I)?e[g]=e[I]:g==="light"?e.light=Vlg(e.main,n):g==="dark"&&(e.dark=wlg(e.main,C)))}function Flg(e="light"){return e==="dark"?{main:cf[200],light:cf[50],dark:cf[400]}:{main:cf[700],light:cf[400],dark:cf[800]}}function Elg(e="light"){return e==="dark"?{main:sf[200],light:sf[50],dark:sf[400]}:{main:sf[500],light:sf[300],dark:sf[700]}}function Mlg(e="light"){return e==="dark"?{main:lf[500],light:lf[300],dark:lf[700]}:{main:lf[700],light:lf[400],dark:lf[800]}}function zlg(e="light"){return e==="dark"?{main:uf[400],light:uf[300],dark:uf[700]}:{main:uf[700],light:uf[500],dark:uf[900]}}function Plg(e="light"){return e==="dark"?{main:df[400],light:df[300],dark:df[700]}:{main:df[800],light:df[500],dark:df[900]}}function Jlg(e="light"){return e==="dark"?{main:BZ[400],light:BZ[300],dark:BZ[700]}:{main:"#ed6c02",light:BZ[500],dark:BZ[900]}}function Olg(e){const{mode:g="light",contrastThreshold:I=3,tonalOffset:i=.2}=e,n=Qt(e,Dlg),C=e.primary||Flg(g),r=e.secondary||Elg(g),o=e.error||Mlg(g),a=e.info||zlg(g),s=e.success||Plg(g),A=e.warning||Jlg(g);function l(h){return Slg(h,QF.text.primary)>=I?QF.text.primary:Iue.text.primary}const c=({color:h,name:m,mainShade:f=500,lightShade:b=300,darkShade:p=700})=>{if(h=Ke({},h),!h.main&&h[f]&&(h.main=h[f]),!h.hasOwnProperty("main"))throw new Error(Uc(11,m?` (${m})`:"",f));if(typeof h.main!="string")throw new Error(Uc(12,m?` (${m})`:"",JSON.stringify(h.main)));return iue(h,"light",b,i),iue(h,"dark",p,i),h.contrastText||(h.contrastText=l(h.main)),h},u={dark:QF,light:Iue};return MC(Ke({common:Ke({},hS),mode:g,primary:c({color:C,name:"primary"}),secondary:c({color:r,name:"secondary",mainShade:"A400",lightShade:"A200",darkShade:"A700"}),error:c({color:o,name:"error"}),warning:c({color:A,name:"warning"}),info:c({color:a,name:"info"}),success:c({color:s,name:"success"}),grey:Hlg,contrastThreshold:I,getContrastText:l,augmentColor:c,tonalOffset:i},u[g]),n)}const _lg=["fontFamily","fontSize","fontWeightLight","fontWeightRegular","fontWeightMedium","fontWeightBold","htmlFontSize","allVariants","pxToRem"];function Llg(e){return Math.round(e*1e5)/1e5}const nue={textTransform:"uppercase"},Cue='"Roboto", "Helvetica", "Arial", sans-serif';function Ulg(e,g){const I=typeof g=="function"?g(e):g,{fontFamily:i=Cue,fontSize:n=14,fontWeightLight:C=300,fontWeightRegular:r=400,fontWeightMedium:o=500,fontWeightBold:a=700,htmlFontSize:s=16,allVariants:A,pxToRem:l}=I,c=Qt(I,_lg),u=n/14,d=l||(f=>`${f/s*u}rem`),h=(f,b,p,y,Z)=>Ke({fontFamily:i,fontWeight:f,fontSize:d(b),lineHeight:p},i===Cue?{letterSpacing:`${Llg(y/b)}em`}:{},Z,A),m={h1:h(C,96,1.167,-1.5),h2:h(C,60,1.2,-.5),h3:h(r,48,1.167,0),h4:h(r,34,1.235,.25),h5:h(r,24,1.334,0),h6:h(o,20,1.6,.15),subtitle1:h(r,16,1.75,.15),subtitle2:h(o,14,1.57,.1),body1:h(r,16,1.5,.15),body2:h(r,14,1.43,.15),button:h(o,14,1.75,.4,nue),caption:h(r,12,1.66,.4),overline:h(r,12,2.66,1,nue),inherit:{fontFamily:"inherit",fontWeight:"inherit",fontSize:"inherit",lineHeight:"inherit",letterSpacing:"inherit"}};return MC(Ke({htmlFontSize:s,pxToRem:d,fontFamily:i,fontSize:n,fontWeightLight:C,fontWeightRegular:r,fontWeightMedium:o,fontWeightBold:a},m),c,{clone:!1})}const Qlg=.2,jlg=.14,$lg=.12;function BI(...e){return[`${e[0]}px ${e[1]}px ${e[2]}px ${e[3]}px rgba(0,0,0,${Qlg})`,`${e[4]}px ${e[5]}px ${e[6]}px ${e[7]}px rgba(0,0,0,${jlg})`,`${e[8]}px ${e[9]}px ${e[10]}px ${e[11]}px rgba(0,0,0,${$lg})`].join(",")}const qlg=["none",BI(0,2,1,-1,0,1,1,0,0,1,3,0),BI(0,3,1,-2,0,2,2,0,0,1,5,0),BI(0,3,3,-2,0,3,4,0,0,1,8,0),BI(0,2,4,-1,0,4,5,0,0,1,10,0),BI(0,3,5,-1,0,5,8,0,0,1,14,0),BI(0,3,5,-1,0,6,10,0,0,1,18,0),BI(0,4,5,-2,0,7,10,1,0,2,16,1),BI(0,5,5,-3,0,8,10,1,0,3,14,2),BI(0,5,6,-3,0,9,12,1,0,3,16,2),BI(0,6,6,-3,0,10,14,1,0,4,18,3),BI(0,6,7,-4,0,11,15,1,0,4,20,3),BI(0,7,8,-4,0,12,17,2,0,5,22,4),BI(0,7,8,-4,0,13,19,2,0,5,24,4),BI(0,7,9,-4,0,14,21,2,0,5,26,4),BI(0,8,9,-5,0,15,22,2,0,6,28,5),BI(0,8,10,-5,0,16,24,2,0,6,30,5),BI(0,8,11,-5,0,17,26,2,0,6,32,5),BI(0,9,11,-5,0,18,28,2,0,7,34,6),BI(0,9,12,-6,0,19,29,2,0,7,36,6),BI(0,10,13,-6,0,20,31,3,0,8,38,7),BI(0,10,13,-6,0,21,33,3,0,8,40,7),BI(0,10,14,-6,0,22,35,3,0,8,42,7),BI(0,11,14,-7,0,23,36,3,0,9,44,8),BI(0,11,15,-7,0,24,38,3,0,9,46,8)],ecg=qlg,tcg=["duration","easing","delay"],gcg={easeInOut:"cubic-bezier(0.4, 0, 0.2, 1)",easeOut:"cubic-bezier(0.0, 0, 0.2, 1)",easeIn:"cubic-bezier(0.4, 0, 1, 1)",sharp:"cubic-bezier(0.4, 0, 0.6, 1)"},kNe={shortest:150,shorter:200,short:250,standard:300,complex:375,enteringScreen:225,leavingScreen:195};function rue(e){return`${Math.round(e)}ms`}function Icg(e){if(!e)return 0;const g=e/36;return Math.round((4+15*g**.25+g/5)*10)}function icg(e){const g=Ke({},gcg,e.easing),I=Ke({},kNe,e.duration);return Ke({getAutoHeightDuration:Icg,create:(n=["all"],C={})=>{const{duration:r=I.standard,easing:o=g.easeInOut,delay:a=0}=C;return Qt(C,tcg),(Array.isArray(n)?n:[n]).map(s=>`${s} ${typeof r=="string"?r:rue(r)} ${o} ${typeof a=="string"?a:rue(a)}`).join(",")}},e,{easing:g,duration:I})}const ncg={mobileStepper:1e3,fab:1050,speedDial:1050,appBar:1100,drawer:1200,modal:1300,snackbar:1400,tooltip:1500},Ccg=ncg,rcg=["breakpoints","mixins","spacing","palette","transitions","typography","shape"];function ocg(e={},...g){const{mixins:I={},palette:i={},transitions:n={},typography:C={}}=e,r=Qt(e,rcg);if(e.vars)throw new Error(Uc(18));const o=Olg(i),a=X8(e);let s=MC(a,{mixins:Rlg(a.breakpoints,I),palette:o,shadows:ecg.slice(),typography:Ulg(o,C),transitions:icg(n),zIndex:Ke({},Ccg)});return s=MC(s,r),s=g.reduce((A,l)=>MC(A,l),s),s.unstable_sxConfig=Ke({},KY,r==null?void 0:r.unstable_sxConfig),s.unstable_sx=function(l){return W8({sx:l,theme:this})},s}const acg=ocg(),DY=acg;function fy(){const e=H8(DY);return e[hY]||e}function gi({props:e,name:g}){return Glg({props:e,name:g,defaultTheme:DY,themeId:hY})}const va=e=>Yv(e)&&e!=="classes",Acg=Yv,scg=ylg({themeId:hY,defaultTheme:DY,rootShouldForwardProp:va}),qt=scg,lcg=e=>{let g;return e<1?g=5.11916*e**2:g=4.5*Math.log(e+1)+2,(g/100).toFixed(2)},oue=lcg;function YNe(e,g,I=void 0){const i={};return Object.keys(e).forEach(n=>{i[n]=e[n].reduce((C,r)=>{if(r){const o=g(r);o!==""&&C.push(o),I&&I[r]&&C.push(I[r])}return C},[]).join(" ")}),i}function ccg(e){return typeof e=="string"}function ucg(e,g,I){return e===void 0||ccg(e)?g:Ke({},g,{ownerState:Ke({},g.ownerState,I)})}function dcg(e,g=[]){if(e===void 0)return{};const I={};return Object.keys(e).filter(i=>i.match(/^on[A-Z]/)&&typeof e[i]=="function"&&!g.includes(i)).forEach(i=>{I[i]=e[i]}),I}function hcg(e,g,I){return typeof e=="function"?e(g,I):e}function KNe(e){return e&&e.ownerDocument||document}function mcg(e,g){typeof e=="function"?e(g):e&&(e.current=g)}const fcg=typeof window<"u"?U.useLayoutEffect:U.useEffect,xNe=fcg;let aue=0;function pcg(e){const[g,I]=U.useState(e),i=e||g;return U.useEffect(()=>{g==null&&(aue+=1,I(`mui-${aue}`))},[g]),i}const Aue=zW["useId".toString()];function bcg(e){if(Aue!==void 0){const g=Aue();return e??g}return pcg(e)}function mS(e){const g=U.useRef(e);return xNe(()=>{g.current=e}),U.useRef((...I)=>(0,g.current)(...I)).current}function N8(...e){return U.useMemo(()=>e.every(g=>g==null)?null:g=>{e.forEach(I=>{mcg(I,g)})},e)}const sue=e=>e,ycg=()=>{let e=sue;return{configure(g){e=g},generate(g){return e(g)},reset(){e=sue}}},Zcg=ycg(),Gcg=Zcg,vcg={active:"active",checked:"checked",completed:"completed",disabled:"disabled",error:"error",expanded:"expanded",focused:"focused",focusVisible:"focusVisible",open:"open",readOnly:"readOnly",required:"required",selected:"selected"};function k8(e,g,I="Mui"){const i=vcg[g];return i?`${I}-${i}`:`${Gcg.generate(e)}-${g}`}function DNe(e,g,I="Mui"){const i={};return g.forEach(n=>{i[n]=k8(e,n,I)}),i}function lue(e){if(e===void 0)return{};const g={};return Object.keys(e).filter(I=>!(I.match(/^on[A-Z]/)&&typeof e[I]=="function")).forEach(I=>{g[I]=e[I]}),g}function Bcg(e){const{getSlotProps:g,additionalProps:I,externalSlotProps:i,externalForwardedProps:n,className:C}=e;if(!g){const u=ug(I==null?void 0:I.className,C,n==null?void 0:n.className,i==null?void 0:i.className),d=Ke({},I==null?void 0:I.style,n==null?void 0:n.style,i==null?void 0:i.style),h=Ke({},I,n,i);return u.length>0&&(h.className=u),Object.keys(d).length>0&&(h.style=d),{props:h,internalRef:void 0}}const r=dcg(Ke({},n,i)),o=lue(i),a=lue(n),s=g(r),A=ug(s==null?void 0:s.className,I==null?void 0:I.className,C,n==null?void 0:n.className,i==null?void 0:i.className),l=Ke({},s==null?void 0:s.style,I==null?void 0:I.style,n==null?void 0:n.style,i==null?void 0:i.style),c=Ke({},s,I,a,o);return A.length>0&&(c.className=A),Object.keys(l).length>0&&(c.style=l),{props:c,internalRef:s.ref}}const Scg=["elementType","externalSlotProps","ownerState","skipResolvingSlotProps"];function wcg(e){var g;const{elementType:I,externalSlotProps:i,ownerState:n,skipResolvingSlotProps:C=!1}=e,r=Qt(e,Scg),o=C?{}:hcg(i,n),{props:a,internalRef:s}=Bcg(Ke({},r,{externalSlotProps:o})),A=N8(s,o==null?void 0:o.ref,(g=e.additionalProps)==null?void 0:g.ref);return ucg(I,Ke({},a,{ref:A}),n)}function Vcg(e){return k8("MuiTreeView",e)}DNe("MuiTreeView",["root"]);const FNe={instance:null,multiSelect:!1,disabledItemsFocusable:!1,treeId:void 0,icons:{defaultCollapseIcon:null,defaultExpandIcon:null,defaultParentIcon:null,defaultEndIcon:null}},ENe=U.createContext(FNe),Rcg=(e,g)=>{const I=U.useRef({}),[i,n]=U.useState(()=>{const r={};return e.forEach(o=>{o.models&&Object.entries(o.models).forEach(([a,s])=>{I.current[a]={controlledProp:s.controlledProp,defaultProp:s.defaultProp,isControlled:g[s.controlledProp]!==void 0},r[a]=g[s.defaultProp]})}),r});return Object.fromEntries(Object.entries(I.current).map(([r,o])=>{const a=o.isControlled?g[o.controlledProp]:i[r];return[r,{value:a,setValue:s=>{o.isControlled||n(A=>Ke({},A,{[r]:s}))}}]}))};class Wcg{constructor(){this.maxListeners=20,this.warnOnce=!1,this.events={}}on(g,I,i={}){let n=this.events[g];n||(n={highPriority:new Map,regular:new Map},this.events[g]=n),i.isFirst?n.highPriority.set(I,!0):n.regular.set(I,!0)}removeListener(g,I){this.events[g]&&(this.events[g].regular.delete(I),this.events[g].highPriority.delete(I))}removeAllListeners(){this.events={}}emit(g,...I){const i=this.events[g];if(!i)return;const n=Array.from(i.highPriority.keys()),C=Array.from(i.regular.keys());for(let r=n.length-1;r>=0;r-=1){const o=n[r];i.highPriority.has(o)&&o.apply(this,I)}for(let r=0;r{const I=e.getNode(g),i=e.getNavigableChildrenIds(I.parentId),n=i.indexOf(g);if(n===0)return I.parentId;let C=i[n-1];for(;e.isNodeExpanded(C)&&e.getNavigableChildrenIds(C).length>0;)C=e.getNavigableChildrenIds(C).pop();return C},GG=(e,g)=>{if(e.isNodeExpanded(g)&&e.getNavigableChildrenIds(g).length>0)return e.getNavigableChildrenIds(g)[0];let I=e.getNode(g);for(;I!=null;){const i=e.getNavigableChildrenIds(I.parentId),n=i[i.indexOf(I.id)+1];if(n)return n;I=e.getNode(I.parentId)}return null},K_=e=>{let g=e.getNavigableChildrenIds(null).pop();for(;e.isNodeExpanded(g);)g=e.getNavigableChildrenIds(g).pop();return g},x_=e=>e.getNavigableChildrenIds(null)[0],py=(e,g)=>{Object.assign(e,g)},Xcg=e=>e.isPropagationStopped!==void 0,Hcg=({instance:e})=>{const[g]=U.useState(()=>new Wcg),I=U.useCallback((...n)=>{const[C,r,o={}]=n;o.defaultMuiPrevented=!1,!(Xcg(o)&&o.isPropagationStopped())&&g.emit(C,r,o)},[g]),i=U.useCallback((n,C)=>(g.on(n,C),()=>{g.removeListener(n,C)}),[g]);py(e,{$$publishEvent:I,$$subscribeEvent:i})},Tcg=[Hcg],Ncg=e=>{const g=[...Tcg,...e.plugins],I=g.reduce((d,h)=>h.getDefaultizedParams?h.getDefaultizedParams(d):d,e),i=Rcg(g,I),C=U.useRef({}).current,r=U.useRef(null),o=N8(r,e.rootRef),[a,s]=U.useState(()=>{const d={};return g.forEach(h=>{h.getInitialState&&Object.assign(d,h.getInitialState(I))}),d}),A=[];let l=FNe;const c=d=>{const h=d({instance:C,params:I,state:a,setState:s,rootRef:r,models:i})||{};h.getRootProps&&A.push(h.getRootProps),h.contextValue&&(l=h.contextValue)};return g.forEach(c),{getRootProps:(d={})=>{const h=Ke({role:"tree",tabIndex:0},d,{ref:o});return A.forEach(m=>{Object.assign(h,m(d))}),h},rootRef:o,contextValue:l}},kcg=["element"];function Ycg(e,g){for(let I=0;I{g.current=e},[e]),g.current}const cue=()=>{};function Dcg(e){const[,g]=U.useState(),{registerDescendant:I=cue,unregisterDescendant:i=cue,descendants:n=[],parentId:C=null}=U.useContext(MNe),r=Ycg(n,s=>s.element===e.element),o=xcg(n),a=n.some((s,A)=>o&&o[A]&&o[A].element!==s.element);return xNe(()=>{if(e.element)return I(Ke({},e,{index:r})),()=>{i(e.element)};g({})},[I,i,r,a,e]),{parentId:C,index:r}}function zNe(e){const{children:g,id:I}=e,[i,n]=U.useState([]),C=U.useCallback(a=>{let{element:s}=a,A=Qt(a,kcg);n(l=>{if(l.length===0)return[Ke({},A,{element:s,index:0})];const c=Kcg(l,s);let u;if(l[c]&&l[c].element===s)u=l;else{const d=Ke({},A,{element:s,index:c});u=l.slice(),u.splice(c,0,d)}return u.forEach((d,h)=>{d.index=h}),u})},[]),r=U.useCallback(a=>{n(s=>s.filter(A=>a!==A.element))},[]),o=U.useMemo(()=>({descendants:i,registerDescendant:C,unregisterDescendant:r,parentId:I}),[i,C,r,I]);return Oe.jsx(MNe.Provider,{value:o,children:g})}function Fcg(e){const{value:g,children:I}=e;return Oe.jsx(ENe.Provider,{value:g,children:Oe.jsx(zNe,{children:I})})}const Ecg=(e,g,I)=>{e.$$publishEvent(g,I)},Mcg=({instance:e,params:g})=>{const I=U.useRef({}),i=U.useCallback(s=>I.current[s],[]),n=U.useCallback(s=>{I.current[s.id]=s},[]),C=U.useCallback(s=>{const A=Ke({},I.current);delete A[s],I.current=A,Ecg(e,"removeNode",{id:s})},[e]),r=U.useCallback(s=>{if(s==null)return!1;let A=e.getNode(s);if(!A)return!1;if(A.disabled)return!0;for(;A.parentId!=null;)if(A=e.getNode(A.parentId),A.disabled)return!0;return!1},[e]),o=mS(s=>Object.values(I.current).filter(A=>A.parentId===s).sort((A,l)=>A.index-l.index).map(A=>A.id));py(e,{getNode:i,updateNode:n,removeNode:C,getChildrenIds:o,getNavigableChildrenIds:s=>{let A=e.getChildrenIds(s);return g.disabledItemsFocusable||(A=A.filter(l=>!e.isNodeDisabled(l))),A},isNodeDisabled:r})},Y8=({instance:e,params:g,models:I})=>{const i=U.useCallback(o=>Array.isArray(I.expanded.value)?I.expanded.value.indexOf(o)!==-1:!1,[I.expanded.value]),n=U.useCallback(o=>{var a;return!!((a=e.getNode(o))!=null&&a.expandable)},[e]),C=mS((o,a)=>{if(a==null)return;let s;I.expanded.value.indexOf(a)!==-1?s=I.expanded.value.filter(A=>A!==a):s=[a].concat(I.expanded.value),g.onNodeToggle&&g.onNodeToggle(o,s),I.expanded.setValue(s)});py(e,{isNodeExpanded:i,isNodeExpandable:n,toggleNodeExpansion:C,expandAllSiblings:(o,a)=>{const s=e.getNode(a),l=e.getChildrenIds(s.parentId).filter(u=>e.isNodeExpandable(u)&&!e.isNodeExpanded(u)),c=I.expanded.value.concat(l);l.length>0&&(I.expanded.setValue(c),g.onNodeToggle&&g.onNodeToggle(o,c))}})};Y8.models={expanded:{controlledProp:"expanded",defaultProp:"defaultExpanded"}};const zcg=[];Y8.getDefaultizedParams=e=>{var g;return Ke({},e,{defaultExpanded:(g=e.defaultExpanded)!=null?g:zcg})};const Pcg=(e,g,I)=>{if(g===I)return[g,I];const i=e.getNode(g),n=e.getNode(I);if(i.parentId===n.id||n.parentId===i.id)return n.parentId===i.id?[i.id,n.id]:[n.id,i.id];const C=[i.id],r=[n.id];let o=i.parentId,a=n.parentId,s=r.indexOf(o)!==-1,A=C.indexOf(a)!==-1,l=!0,c=!0;for(;!A&&!s;)l&&(C.push(o),s=r.indexOf(o)!==-1,l=o!==null,!s&&l&&(o=e.getNode(o).parentId)),c&&!s&&(r.push(a),A=C.indexOf(a)!==-1,c=a!==null,!A&&c&&(a=e.getNode(a).parentId));const u=s?o:a,d=e.getChildrenIds(u),h=C[C.indexOf(u)-1],m=r[r.indexOf(u)-1];return d.indexOf(h){const i=U.useRef(null),n=U.useRef(!1),C=U.useRef([]),r=d=>Array.isArray(I.selected.value)?I.selected.value.indexOf(d)!==-1:I.selected.value===d,o=(d,h,m=!1)=>{if(!g.disableSelection){if(m){if(Array.isArray(I.selected.value)){let f;I.selected.value.indexOf(h)!==-1?f=I.selected.value.filter(b=>b!==h):f=[h].concat(I.selected.value),g.onNodeSelect&&g.onNodeSelect(d,f),I.selected.setValue(f)}}else{const f=g.multiSelect?[h]:h;g.onNodeSelect&&g.onNodeSelect(d,f),I.selected.setValue(f)}i.current=h,n.current=!1,C.current=[]}},a=(d,h)=>{const[m,f]=Pcg(e,d,h),b=[m];let p=m;for(;p!==f;)p=GG(e,p),b.push(p);return b},s=(d,h)=>{let m=I.selected.value.slice();const{start:f,next:b,current:p}=h;!b||!p||(C.current.indexOf(p)===-1&&(C.current=[]),n.current?C.current.indexOf(b)!==-1?(m=m.filter(y=>y===f||y!==p),C.current=C.current.filter(y=>y===f||y!==p)):(m.push(b),C.current.push(b)):(m.push(b),C.current.push(p,b)),g.onNodeSelect&&g.onNodeSelect(d,m),I.selected.setValue(m))},A=(d,h)=>{let m=I.selected.value.slice();const{start:f,end:b}=h;n.current&&(m=m.filter(Z=>C.current.indexOf(Z)===-1));let p=a(f,b);p=p.filter(Z=>!e.isNodeDisabled(Z)),C.current=p;let y=m.concat(p);y=y.filter((Z,B)=>y.indexOf(Z)===B),g.onNodeSelect&&g.onNodeSelect(d,y),I.selected.setValue(y)};return py(e,{isNodeSelected:r,selectNode:o,selectRange:(d,h,m=!1)=>{if(g.disableSelection)return;const{start:f=i.current,end:b,current:p}=h;m?s(d,{start:f,next:b,current:p}):f!=null&&b!=null&&A(d,{start:f,end:b}),n.current=!0},rangeSelectToLast:(d,h)=>{i.current||(i.current=h);const m=n.current?i.current:h;e.selectRange(d,{start:m,end:K_(e)})},rangeSelectToFirst:(d,h)=>{i.current||(i.current=h);const m=n.current?i.current:h;e.selectRange(d,{start:m,end:x_(e)})}}),{getRootProps:()=>({"aria-multiselectable":g.multiSelect})}};K8.models={selected:{controlledProp:"selected",defaultProp:"defaultSelected"}};const Jcg=[];K8.getDefaultizedParams=e=>{var g,I,i;return Ke({},e,{disableSelection:(g=e.disableSelection)!=null?g:!1,multiSelect:(I=e.multiSelect)!=null?I:!1,defaultSelected:(i=e.defaultSelected)!=null?i:e.multiSelect?Jcg:null})};const uue=1e3;class Ocg{constructor(g=uue){this.timeouts=new Map,this.cleanupTimeout=uue,this.cleanupTimeout=g}register(g,I,i){this.timeouts||(this.timeouts=new Map);const n=setTimeout(()=>{typeof I=="function"&&I(),this.timeouts.delete(i.cleanupToken)},this.cleanupTimeout);this.timeouts.set(i.cleanupToken,n)}unregister(g){const I=this.timeouts.get(g.cleanupToken);I&&(this.timeouts.delete(g.cleanupToken),clearTimeout(I))}reset(){this.timeouts&&(this.timeouts.forEach((g,I)=>{this.unregister({cleanupToken:I})}),this.timeouts=void 0)}}class _cg{constructor(){this.registry=new FinalizationRegistry(g=>{typeof g=="function"&&g()})}register(g,I,i){this.registry.register(g,I,i)}unregister(g){this.registry.unregister(g)}reset(){}}class Lcg{}function Ucg(e){let g=0;return function(i,n,C){e.registry===null&&(e.registry=typeof FinalizationRegistry<"u"?new _cg:new Ocg);const[r]=U.useState(new Lcg),o=U.useRef(null),a=U.useRef();a.current=C;const s=U.useRef(null);if(!o.current&&a.current){const A=(l,c)=>{if(!c.defaultMuiPrevented){var u;(u=a.current)==null||u.call(a,l,c)}};o.current=i.$$subscribeEvent(n,A),g+=1,s.current={cleanupToken:g},e.registry.register(r,()=>{var l;(l=o.current)==null||l.call(o),o.current=null,s.current=null},s.current)}else!a.current&&o.current&&(o.current(),o.current=null,s.current&&(e.registry.unregister(s.current),s.current=null));U.useEffect(()=>{if(!o.current&&a.current){const A=(l,c)=>{if(!c.defaultMuiPrevented){var u;(u=a.current)==null||u.call(a,l,c)}};o.current=i.$$subscribeEvent(n,A)}return s.current&&e.registry&&(e.registry.unregister(s.current),s.current=null),()=>{var A;(A=o.current)==null||A.call(o),o.current=null}},[i,n])}}const Qcg={registry:null},jcg=Ucg(Qcg),x8=({instance:e,params:g,state:I,setState:i,models:n,rootRef:C})=>{const r=mS(u=>{const d=typeof u=="function"?u(I.focusedNodeId):u;i(h=>Ke({},h,{focusedNodeId:d}))}),o=U.useCallback(u=>I.focusedNodeId===u,[I.focusedNodeId]),a=mS((u,d)=>{d&&(r(d),g.onNodeFocus&&g.onNodeFocus(u,d))});py(e,{isNodeFocused:o,focusNode:a}),jcg(e,"removeNode",({id:u})=>{r(d=>d===u&&C.current===KNe(C.current).activeElement?e.getChildrenIds(null)[0]:d)});const s=u=>d=>{var h;if((h=u.onFocus)==null||h.call(u,d),d.target===d.currentTarget){const m=b=>{const p=e.getNode(b);return p&&(p.parentId==null||e.isNodeExpanded(p.parentId))};let f;Array.isArray(n.selected.value)?f=n.selected.value.find(m):n.selected.value!=null&&m(n.selected.value)&&(f=n.selected.value),f==null&&(f=e.getNavigableChildrenIds(null)[0]),e.focusNode(d,f)}},A=u=>d=>{var h;(h=u.onBlur)==null||h.call(u,d),r(null)},l=e.getNode(I.focusedNodeId),c=l?l.idAttribute:null;return{getRootProps:u=>({onFocus:s(u),onBlur:A(u),"aria-activedescendant":c??void 0})}};x8.getInitialState=()=>({focusedNodeId:null});x8.getDefaultizedParams=e=>{var g;return Ke({},e,{disabledItemsFocusable:(g=e.disabledItemsFocusable)!=null?g:!1})};function $cg(e){return e&&e.length===1&&e.match(/\S/)}function due(e,g,I){for(let i=g;i{const n=fy().direction==="rtl",C=U.useRef({}),r=mS((u,d)=>(C.current[u]=d,()=>{const h=Ke({},C.current);delete h[u],C.current=h}));py(e,{mapFirstChar:r});const o=u=>(I.focusedNodeId!=null&&e.isNodeExpandable(I.focusedNodeId)&&(e.isNodeExpanded(I.focusedNodeId)?e.focusNode(u,GG(e,I.focusedNodeId)):e.isNodeDisabled(I.focusedNodeId)||e.toggleNodeExpansion(u,I.focusedNodeId)),!0),a=u=>{if(I.focusedNodeId==null)return!1;if(e.isNodeExpanded(I.focusedNodeId)&&!e.isNodeDisabled(I.focusedNodeId))return e.toggleNodeExpansion(u,I.focusedNodeId),!0;const d=e.getNode(I.focusedNodeId).parentId;return d?(e.focusNode(u,d),!0):!1},s=(u,d,h)=>{let m,f;const b=h.toLowerCase(),p=[],y=[];Object.keys(C.current).forEach(Z=>{const B=e.getNode(Z),G=B.parentId?e.isNodeExpanded(B.parentId):!0,v=g.disabledItemsFocusable?!1:e.isNodeDisabled(Z);G&&!v&&(p.push(Z),y.push(C.current[Z]))}),m=p.indexOf(d)+1,m>=p.length&&(m=0),f=due(y,m,b),f===-1&&(f=due(y,0,b)),f>-1&&e.focusNode(u,p[f])},A=(u,d)=>{e.isNodeDisabled(GG(e,d))||e.selectRange(u,{end:GG(e,d),current:d},!0)},l=(u,d)=>{e.isNodeDisabled(jF(e,d))||e.selectRange(u,{end:jF(e,d),current:d},!0)},c=u=>d=>{var h;(h=u.onKeyDown)==null||h.call(u,d);let m=!1;const f=d.key;if(d.altKey||d.currentTarget!==d.target||I.focusedNodeId==null)return;const b=d.ctrlKey||d.metaKey;switch(f){case" ":!g.disableSelection&&!e.isNodeDisabled(I.focusedNodeId)&&(m=!0,g.multiSelect&&d.shiftKey?e.selectRange(d,{end:I.focusedNodeId}):g.multiSelect?e.selectNode(d,I.focusedNodeId,!0):e.selectNode(d,I.focusedNodeId)),d.stopPropagation();break;case"Enter":e.isNodeDisabled(I.focusedNodeId)||(e.isNodeExpandable(I.focusedNodeId)?(e.toggleNodeExpansion(d,I.focusedNodeId),m=!0):g.disableSelection||(m=!0,g.multiSelect?e.selectNode(d,I.focusedNodeId,!0):e.selectNode(d,I.focusedNodeId))),d.stopPropagation();break;case"ArrowDown":g.multiSelect&&d.shiftKey&&!g.disableSelection&&A(d,I.focusedNodeId),e.focusNode(d,GG(e,I.focusedNodeId)),m=!0;break;case"ArrowUp":g.multiSelect&&d.shiftKey&&!g.disableSelection&&l(d,I.focusedNodeId),e.focusNode(d,jF(e,I.focusedNodeId)),m=!0;break;case"ArrowRight":n?m=a(d):m=o(d);break;case"ArrowLeft":n?m=o(d):m=a(d);break;case"Home":g.multiSelect&&b&&d.shiftKey&&!g.disableSelection&&!e.isNodeDisabled(I.focusedNodeId)&&e.rangeSelectToFirst(d,I.focusedNodeId),e.focusNode(d,x_(e)),m=!0;break;case"End":g.multiSelect&&b&&d.shiftKey&&!g.disableSelection&&!e.isNodeDisabled(I.focusedNodeId)&&e.rangeSelectToLast(d,I.focusedNodeId),e.focusNode(d,K_(e)),m=!0;break;default:f==="*"?(e.expandAllSiblings(d,I.focusedNodeId),m=!0):g.multiSelect&&b&&f.toLowerCase()==="a"&&!g.disableSelection?(e.selectRange(d,{start:x_(e),end:K_(e)}),m=!0):!b&&!d.shiftKey&&$cg(f)&&(s(d,I.focusedNodeId,f),m=!0)}m&&(d.preventDefault(),d.stopPropagation())};return{getRootProps:u=>({onKeyDown:c(u)})}},eug=({instance:e,params:g})=>{const I=bcg(g.id);return{getRootProps:()=>({id:I}),contextValue:{treeId:I,instance:e,multiSelect:g.multiSelect,disabledItemsFocusable:g.disabledItemsFocusable,icons:{defaultCollapseIcon:g.defaultCollapseIcon,defaultEndIcon:g.defaultEndIcon,defaultExpandIcon:g.defaultExpandIcon,defaultParentIcon:g.defaultParentIcon}}}},tug=[Mcg,Y8,K8,x8,qcg,eug],gug=["disabledItemsFocusable","expanded","defaultExpanded","onNodeToggle","onNodeFocus","disableSelection","defaultSelected","selected","multiSelect","onNodeSelect","id","defaultCollapseIcon","defaultEndIcon","defaultExpandIcon","defaultParentIcon","children"],Iug=e=>{const{classes:g}=e;return YNe({root:["root"]},Vcg,g)},hue=qt("ul",{name:"MuiTreeView",slot:"Root",overridesResolver:(e,g)=>g.root})({padding:0,margin:0,listStyle:"none",outline:0}),PNe=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiTreeView"}),n=i,C=i,{disabledItemsFocusable:r,expanded:o,defaultExpanded:a,onNodeToggle:s,onNodeFocus:A,disableSelection:l,defaultSelected:c,selected:u,multiSelect:d,onNodeSelect:h,id:m,defaultCollapseIcon:f,defaultEndIcon:b,defaultExpandIcon:p,defaultParentIcon:y,children:Z}=C,B=Qt(C,gug),{getRootProps:G,contextValue:v}=Ncg({disabledItemsFocusable:r,expanded:o,defaultExpanded:a,onNodeToggle:s,onNodeFocus:A,disableSelection:l,defaultSelected:c,selected:u,multiSelect:d,onNodeSelect:h,id:m,defaultCollapseIcon:f,defaultEndIcon:b,defaultExpandIcon:p,defaultParentIcon:y,plugins:tug,rootRef:I}),w=Iug(i),V=wcg({elementType:hue,externalSlotProps:{},externalForwardedProps:B,className:w.root,getSlotProps:G,ownerState:n});return Oe.jsx(Fcg,{value:v,children:Oe.jsx(hue,Ke({},V,{children:Z}))})});function D_(e,g){return D_=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(i,n){return i.__proto__=n,i},D_(e,g)}function JNe(e,g){e.prototype=Object.create(g.prototype),e.prototype.constructor=e,D_(e,g)}const mue={disabled:!1},JH=N.createContext(null);var iug=function(g){return g.scrollTop},vG="unmounted",td="exited",gd="entering",zf="entered",F_="exiting",sl=function(e){JNe(g,e);function g(i,n){var C;C=e.call(this,i,n)||this;var r=n,o=r&&!r.isMounting?i.enter:i.appear,a;return C.appearStatus=null,i.in?o?(a=td,C.appearStatus=gd):a=zf:i.unmountOnExit||i.mountOnEnter?a=vG:a=td,C.state={status:a},C.nextCallback=null,C}g.getDerivedStateFromProps=function(n,C){var r=n.in;return r&&C.status===vG?{status:td}:null};var I=g.prototype;return I.componentDidMount=function(){this.updateStatus(!0,this.appearStatus)},I.componentDidUpdate=function(n){var C=null;if(n!==this.props){var r=this.state.status;this.props.in?r!==gd&&r!==zf&&(C=gd):(r===gd||r===zf)&&(C=F_)}this.updateStatus(!1,C)},I.componentWillUnmount=function(){this.cancelNextCallback()},I.getTimeouts=function(){var n=this.props.timeout,C,r,o;return C=r=o=n,n!=null&&typeof n!="number"&&(C=n.exit,r=n.enter,o=n.appear!==void 0?n.appear:r),{exit:C,enter:r,appear:o}},I.updateStatus=function(n,C){if(n===void 0&&(n=!1),C!==null)if(this.cancelNextCallback(),C===gd){if(this.props.unmountOnExit||this.props.mountOnEnter){var r=this.props.nodeRef?this.props.nodeRef.current:jI.findDOMNode(this);r&&iug(r)}this.performEnter(n)}else this.performExit();else this.props.unmountOnExit&&this.state.status===td&&this.setState({status:vG})},I.performEnter=function(n){var C=this,r=this.props.enter,o=this.context?this.context.isMounting:n,a=this.props.nodeRef?[o]:[jI.findDOMNode(this),o],s=a[0],A=a[1],l=this.getTimeouts(),c=o?l.appear:l.enter;if(!n&&!r||mue.disabled){this.safeSetState({status:zf},function(){C.props.onEntered(s)});return}this.props.onEnter(s,A),this.safeSetState({status:gd},function(){C.props.onEntering(s,A),C.onTransitionEnd(c,function(){C.safeSetState({status:zf},function(){C.props.onEntered(s,A)})})})},I.performExit=function(){var n=this,C=this.props.exit,r=this.getTimeouts(),o=this.props.nodeRef?void 0:jI.findDOMNode(this);if(!C||mue.disabled){this.safeSetState({status:td},function(){n.props.onExited(o)});return}this.props.onExit(o),this.safeSetState({status:F_},function(){n.props.onExiting(o),n.onTransitionEnd(r.exit,function(){n.safeSetState({status:td},function(){n.props.onExited(o)})})})},I.cancelNextCallback=function(){this.nextCallback!==null&&(this.nextCallback.cancel(),this.nextCallback=null)},I.safeSetState=function(n,C){C=this.setNextCallback(C),this.setState(n,C)},I.setNextCallback=function(n){var C=this,r=!0;return this.nextCallback=function(o){r&&(r=!1,C.nextCallback=null,n(o))},this.nextCallback.cancel=function(){r=!1},this.nextCallback},I.onTransitionEnd=function(n,C){this.setNextCallback(C);var r=this.props.nodeRef?this.props.nodeRef.current:jI.findDOMNode(this),o=n==null&&!this.props.addEndListener;if(!r||o){setTimeout(this.nextCallback,0);return}if(this.props.addEndListener){var a=this.props.nodeRef?[this.nextCallback]:[r,this.nextCallback],s=a[0],A=a[1];this.props.addEndListener(s,A)}n!=null&&setTimeout(this.nextCallback,n)},I.render=function(){var n=this.state.status;if(n===vG)return null;var C=this.props,r=C.children;C.in,C.mountOnEnter,C.unmountOnExit,C.appear,C.enter,C.exit,C.timeout,C.addEndListener,C.onEnter,C.onEntering,C.onEntered,C.onExit,C.onExiting,C.onExited,C.nodeRef;var o=Qt(C,["children","in","mountOnEnter","unmountOnExit","appear","enter","exit","timeout","addEndListener","onEnter","onEntering","onEntered","onExit","onExiting","onExited","nodeRef"]);return N.createElement(JH.Provider,{value:null},typeof r=="function"?r(n,o):N.cloneElement(N.Children.only(r),o))},g}(N.Component);sl.contextType=JH;sl.propTypes={};function hf(){}sl.defaultProps={in:!1,mountOnEnter:!1,unmountOnExit:!1,appear:!1,enter:!0,exit:!0,onEnter:hf,onEntering:hf,onEntered:hf,onExit:hf,onExiting:hf,onExited:hf};sl.UNMOUNTED=vG;sl.EXITED=td;sl.ENTERING=gd;sl.ENTERED=zf;sl.EXITING=F_;const D8=sl;function nug(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function F8(e,g){var I=function(C){return g&&U.isValidElement(C)?g(C):C},i=Object.create(null);return e&&U.Children.map(e,function(n){return n}).forEach(function(n){i[n.key]=I(n)}),i}function Cug(e,g){e=e||{},g=g||{};function I(A){return A in g?g[A]:e[A]}var i=Object.create(null),n=[];for(var C in e)C in g?n.length&&(i[C]=n,n=[]):n.push(C);var r,o={};for(var a in g){if(i[a])for(r=0;re.scrollTop;function f0(e,g){var I,i;const{timeout:n,easing:C,style:r={}}=e;return{duration:(I=r.transitionDuration)!=null?I:typeof n=="number"?n:n[g.mode]||0,easing:(i=r.transitionTimingFunction)!=null?i:typeof C=="object"?C[g.mode]:C,delay:r.transitionDelay}}function lug(e){return li("MuiSvgIcon",e)}HI("MuiSvgIcon",["root","colorPrimary","colorSecondary","colorAction","colorError","colorDisabled","fontSizeInherit","fontSizeSmall","fontSizeMedium","fontSizeLarge"]);const cug=["children","className","color","component","fontSize","htmlColor","inheritViewBox","titleAccess","viewBox"],uug=e=>{const{color:g,fontSize:I,classes:i}=e,n={root:["root",g!=="inherit"&&`color${si(g)}`,`fontSize${si(I)}`]};return vi(n,lug,i)},dug=qt("svg",{name:"MuiSvgIcon",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[g.root,I.color!=="inherit"&&g[`color${si(I.color)}`],g[`fontSize${si(I.fontSize)}`]]}})(({theme:e,ownerState:g})=>{var I,i,n,C,r,o,a,s,A,l,c,u,d;return{userSelect:"none",width:"1em",height:"1em",display:"inline-block",fill:g.hasSvgAsChild?void 0:"currentColor",flexShrink:0,transition:(I=e.transitions)==null||(i=I.create)==null?void 0:i.call(I,"fill",{duration:(n=e.transitions)==null||(n=n.duration)==null?void 0:n.shorter}),fontSize:{inherit:"inherit",small:((C=e.typography)==null||(r=C.pxToRem)==null?void 0:r.call(C,20))||"1.25rem",medium:((o=e.typography)==null||(a=o.pxToRem)==null?void 0:a.call(o,24))||"1.5rem",large:((s=e.typography)==null||(A=s.pxToRem)==null?void 0:A.call(s,35))||"2.1875rem"}[g.fontSize],color:(l=(c=(e.vars||e).palette)==null||(c=c[g.color])==null?void 0:c.main)!=null?l:{action:(u=(e.vars||e).palette)==null||(u=u.action)==null?void 0:u.active,disabled:(d=(e.vars||e).palette)==null||(d=d.action)==null?void 0:d.disabled,inherit:void 0}[g.color]}}),_Ne=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiSvgIcon"}),{children:n,className:C,color:r="inherit",component:o="svg",fontSize:a="medium",htmlColor:s,inheritViewBox:A=!1,titleAccess:l,viewBox:c="0 0 24 24"}=i,u=Qt(i,cug),d=U.isValidElement(n)&&n.type==="svg",h=Ke({},i,{color:r,component:o,fontSize:a,instanceFontSize:g.fontSize,inheritViewBox:A,viewBox:c,hasSvgAsChild:d}),m={};A||(m.viewBox=c);const f=uug(h);return Oe.jsxs(dug,Ke({as:o,className:ug(f.root,C),focusable:"false",color:s,"aria-hidden":l?void 0:!0,role:l?"img":void 0,ref:I},m,u,d&&n.props,{ownerState:h,children:[d?n.props.children:n,l?Oe.jsx("title",{children:l}):null]}))});_Ne.muiName="SvgIcon";const fue=_Ne;function LNe(e,g){function I(i,n){return Oe.jsx(fue,Ke({"data-testid":`${g}Icon`,ref:n},i,{children:e}))}return I.muiName=fue.muiName,U.memo(U.forwardRef(I))}const hug={configure:e=>{sNe.configure(e)}},mug=Object.freeze(Object.defineProperty({__proto__:null,capitalize:si,createChainedFunction:W_,createSvgIcon:LNe,debounce:h8,deprecatedPropType:zag,isMuiElement:xW,ownerDocument:zC,ownerWindow:Qc,requirePropFactory:Pag,setRef:FH,unstable_ClassNameGenerator:hug,unstable_useEnhancedEffect:Ls,unstable_useId:rNe,unsupportedProp:_ag,useControlled:X_,useEventCallback:Zd,useForkRef:pn,useIsFocusVisible:oNe},Symbol.toStringTag,{value:"Module"}));function fug(e){return li("MuiCollapse",e)}HI("MuiCollapse",["root","horizontal","vertical","entered","hidden","wrapper","wrapperInner"]);const pug=["addEndListener","children","className","collapsedSize","component","easing","in","onEnter","onEntered","onEntering","onExit","onExited","onExiting","orientation","style","timeout","TransitionComponent"],bug=e=>{const{orientation:g,classes:I}=e,i={root:["root",`${g}`],entered:["entered"],hidden:["hidden"],wrapper:["wrapper",`${g}`],wrapperInner:["wrapperInner",`${g}`]};return vi(i,fug,I)},yug=qt("div",{name:"MuiCollapse",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[g.root,g[I.orientation],I.state==="entered"&&g.entered,I.state==="exited"&&!I.in&&I.collapsedSize==="0px"&&g.hidden]}})(({theme:e,ownerState:g})=>Ke({height:0,overflow:"hidden",transition:e.transitions.create("height")},g.orientation==="horizontal"&&{height:"auto",width:0,transition:e.transitions.create("width")},g.state==="entered"&&Ke({height:"auto",overflow:"visible"},g.orientation==="horizontal"&&{width:"auto"}),g.state==="exited"&&!g.in&&g.collapsedSize==="0px"&&{visibility:"hidden"})),Zug=qt("div",{name:"MuiCollapse",slot:"Wrapper",overridesResolver:(e,g)=>g.wrapper})(({ownerState:e})=>Ke({display:"flex",width:"100%"},e.orientation==="horizontal"&&{width:"auto",height:"100%"})),Gug=qt("div",{name:"MuiCollapse",slot:"WrapperInner",overridesResolver:(e,g)=>g.wrapperInner})(({ownerState:e})=>Ke({width:"100%"},e.orientation==="horizontal"&&{width:"auto",height:"100%"})),UNe=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiCollapse"}),{addEndListener:n,children:C,className:r,collapsedSize:o="0px",component:a,easing:s,in:A,onEnter:l,onEntered:c,onEntering:u,onExit:d,onExited:h,onExiting:m,orientation:f="vertical",style:b,timeout:p=kNe.standard,TransitionComponent:y=D8}=i,Z=Qt(i,pug),B=Ke({},i,{orientation:f,collapsedSize:o}),G=bug(B),v=fy(),w=U.useRef(),V=U.useRef(null),S=U.useRef(),X=typeof o=="number"?`${o}px`:o,W=f==="horizontal",R=W?"width":"height";U.useEffect(()=>()=>{clearTimeout(w.current)},[]);const H=U.useRef(null),Y=pn(I,H),K=Q=>ie=>{if(Q){const he=H.current;ie===void 0?Q(he):Q(he,ie)}},F=()=>V.current?V.current[W?"clientWidth":"clientHeight"]:0,J=K((Q,ie)=>{V.current&&W&&(V.current.style.position="absolute"),Q.style[R]=X,l&&l(Q,ie)}),P=K((Q,ie)=>{const he=F();V.current&&W&&(V.current.style.position="");const{duration:ne,easing:be}=f0({style:b,timeout:p,easing:s},{mode:"enter"});if(p==="auto"){const pe=v.transitions.getAutoHeightDuration(he);Q.style.transitionDuration=`${pe}ms`,S.current=pe}else Q.style.transitionDuration=typeof ne=="string"?ne:`${ne}ms`;Q.style[R]=`${he}px`,Q.style.transitionTimingFunction=be,u&&u(Q,ie)}),ge=K((Q,ie)=>{Q.style[R]="auto",c&&c(Q,ie)}),q=K(Q=>{Q.style[R]=`${F()}px`,d&&d(Q)}),$=K(h),j=K(Q=>{const ie=F(),{duration:he,easing:ne}=f0({style:b,timeout:p,easing:s},{mode:"exit"});if(p==="auto"){const be=v.transitions.getAutoHeightDuration(ie);Q.style.transitionDuration=`${be}ms`,S.current=be}else Q.style.transitionDuration=typeof he=="string"?he:`${he}ms`;Q.style[R]=X,Q.style.transitionTimingFunction=ne,m&&m(Q)}),te=Q=>{p==="auto"&&(w.current=setTimeout(Q,S.current||0)),n&&n(H.current,Q)};return Oe.jsx(y,Ke({in:A,onEnter:J,onEntered:ge,onEntering:P,onExit:q,onExited:$,onExiting:j,addEndListener:te,nodeRef:H,timeout:p==="auto"?null:p},Z,{children:(Q,ie)=>Oe.jsx(yug,Ke({as:a,className:ug(G.root,r,{entered:G.entered,exited:!A&&X==="0px"&&G.hidden}[Q]),style:Ke({[W?"minWidth":"minHeight"]:X},b),ownerState:Ke({},B,{state:Q}),ref:Y},ie,{children:Oe.jsx(Zug,{ownerState:Ke({},B,{state:Q}),className:G.wrapper,ref:V,children:Oe.jsx(Gug,{ownerState:Ke({},B,{state:Q}),className:G.wrapperInner,children:C})})}))}))});UNe.muiSupportAuto=!0;const QNe=UNe;var jNe={exports:{}};(function(e){function g(I){return I&&I.__esModule?I:{default:I}}e.exports=g,e.exports.__esModule=!0,e.exports.default=e.exports})(jNe);var $Ne=jNe.exports;const qNe=()=>U.useContext(ENe);function vug(e){const{instance:g,multiSelect:I}=qNe(),i=g?g.isNodeExpandable(e):!1,n=g?g.isNodeExpanded(e):!1,C=g?g.isNodeFocused(e):!1,r=g?g.isNodeSelected(e):!1,o=g?g.isNodeDisabled(e):!1;return{disabled:o,expanded:n,selected:r,focused:C,handleExpansion:l=>{if(g&&!o){C||g.focusNode(l,e);const c=I&&(l.shiftKey||l.ctrlKey||l.metaKey);i&&!(c&&g.isNodeExpanded(e))&&g.toggleNodeExpansion(l,e)}},handleSelection:l=>{g&&!o&&(C||g.focusNode(l,e),I&&(l.shiftKey||l.ctrlKey||l.metaKey)?l.shiftKey?g.selectRange(l,{end:e}):g.selectNode(l,e,!0):g.selectNode(l,e))},preventSelection:l=>{(l.shiftKey||l.ctrlKey||l.metaKey||o)&&l.preventDefault()}}}const Bug=["classes","className","displayIcon","expansionIcon","icon","label","nodeId","onClick","onMouseDown"],eke=U.forwardRef(function(g,I){const{classes:i,className:n,displayIcon:C,expansionIcon:r,icon:o,label:a,nodeId:s,onClick:A,onMouseDown:l}=g,c=Qt(g,Bug),{disabled:u,expanded:d,selected:h,focused:m,handleExpansion:f,handleSelection:b,preventSelection:p}=vug(s),y=o||r||C,Z=G=>{p(G),l&&l(G)},B=G=>{f(G),b(G),A&&A(G)};return Oe.jsxs("div",Ke({},c,{className:ug(n,i.root,d&&i.expanded,h&&i.selected,m&&i.focused,u&&i.disabled),onClick:B,onMouseDown:Z,ref:I,children:[Oe.jsx("div",{className:i.iconContainer,children:y}),Oe.jsx("div",{className:i.label,children:a})]}))});function Sug(e){return k8("MuiTreeItem",e)}const Vl=DNe("MuiTreeItem",["root","group","content","expanded","selected","focused","disabled","iconContainer","label"]),wug=["children","className","collapseIcon","ContentComponent","ContentProps","endIcon","expandIcon","disabled","icon","id","label","nodeId","onClick","onMouseDown","TransitionComponent","TransitionProps"],Vug=e=>{const{classes:g}=e;return YNe({root:["root"],content:["content"],expanded:["expanded"],selected:["selected"],focused:["focused"],disabled:["disabled"],iconContainer:["iconContainer"],label:["label"],group:["group"]},Sug,g)},Rug=qt("li",{name:"MuiTreeItem",slot:"Root",overridesResolver:(e,g)=>g.root})({listStyle:"none",margin:0,padding:0,outline:0}),Wug=qt(eke,{name:"MuiTreeItem",slot:"Content",overridesResolver:(e,g)=>[g.content,g.iconContainer&&{[`& .${Vl.iconContainer}`]:g.iconContainer},g.label&&{[`& .${Vl.label}`]:g.label}]})(({theme:e})=>({padding:"0 8px",width:"100%",boxSizing:"border-box",display:"flex",alignItems:"center",cursor:"pointer",WebkitTapHighlightColor:"transparent","&:hover":{backgroundColor:(e.vars||e).palette.action.hover,"@media (hover: none)":{backgroundColor:"transparent"}},[`&.${Vl.disabled}`]:{opacity:(e.vars||e).palette.action.disabledOpacity,backgroundColor:"transparent"},[`&.${Vl.focused}`]:{backgroundColor:(e.vars||e).palette.action.focus},[`&.${Vl.selected}`]:{backgroundColor:e.vars?`rgba(${e.vars.palette.primary.mainChannel} / ${e.vars.palette.action.selectedOpacity})`:rA(e.palette.primary.main,e.palette.action.selectedOpacity),"&:hover":{backgroundColor:e.vars?`rgba(${e.vars.palette.primary.mainChannel} / calc(${e.vars.palette.action.selectedOpacity} + ${e.vars.palette.action.hoverOpacity}))`:rA(e.palette.primary.main,e.palette.action.selectedOpacity+e.palette.action.hoverOpacity),"@media (hover: none)":{backgroundColor:e.vars?`rgba(${e.vars.palette.primary.mainChannel} / ${e.vars.palette.action.selectedOpacity})`:rA(e.palette.primary.main,e.palette.action.selectedOpacity)}},[`&.${Vl.focused}`]:{backgroundColor:e.vars?`rgba(${e.vars.palette.primary.mainChannel} / calc(${e.vars.palette.action.selectedOpacity} + ${e.vars.palette.action.focusOpacity}))`:rA(e.palette.primary.main,e.palette.action.selectedOpacity+e.palette.action.focusOpacity)}},[`& .${Vl.iconContainer}`]:{marginRight:4,width:15,display:"flex",flexShrink:0,justifyContent:"center","& svg":{fontSize:18}},[`& .${Vl.label}`]:Ke({paddingLeft:4,width:"100%",boxSizing:"border-box",minWidth:0,position:"relative"},e.typography.body1)})),Xug=qt(QNe,{name:"MuiTreeItem",slot:"Group",overridesResolver:(e,g)=>g.group})({margin:0,padding:0,marginLeft:17}),rc=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiTreeItem"}),{children:n,className:C,collapseIcon:r,ContentComponent:o=eke,ContentProps:a,endIcon:s,expandIcon:A,disabled:l,icon:c,id:u,label:d,nodeId:h,onClick:m,onMouseDown:f,TransitionComponent:b=QNe,TransitionProps:p}=i,y=Qt(i,wug),{icons:Z,multiSelect:B,disabledItemsFocusable:G,treeId:v,instance:w}=qNe();let V;u!=null?V=u:v&&h&&(V=`${v}-${h}`);const[S,X]=U.useState(null),W=U.useRef(null),R=N8(X,I),H=U.useMemo(()=>({element:S,id:h}),[h,S]),{index:Y,parentId:K}=Dcg(H),F=!!(Array.isArray(n)?n.length:n),J=w?w.isNodeExpanded(h):!1,P=w?w.isNodeFocused(h):!1,ge=w?w.isNodeSelected(h):!1,q=w?w.isNodeDisabled(h):!1,$=Ke({},i,{expanded:J,focused:P,selected:ge,disabled:q}),j=Vug($);let te,Q;F&&(J?Q=r||Z.defaultCollapseIcon:Q=A||Z.defaultExpandIcon),F?te=Z.defaultParentIcon:te=s||Z.defaultEndIcon,U.useEffect(()=>{if(w&&Y!==-1)return w.updateNode({id:h,idAttribute:V,index:Y,parentId:K,expandable:F,disabled:l}),()=>w.removeNode(h)},[w,K,Y,h,F,l,V]),U.useEffect(()=>{if(w&&d){var ne,be;return w.mapFirstChar(h,((ne=(be=W.current)==null?void 0:be.textContent)!=null?ne:"").substring(0,1).toLowerCase())}},[w,h,d]);let ie;B?ie=ge:ge&&(ie=!0);function he(ne){if(ne.target===ne.currentTarget){let pe;typeof ne.target.getRootNode=="function"?pe=ne.target.getRootNode():pe=KNe(ne.target),pe.getElementById(v).focus({preventScroll:!0})}const be=!G&&q;w&&!P&&ne.currentTarget===ne.target&&!be&&w.focusNode(ne,h)}return Oe.jsxs(Rug,Ke({className:ug(j.root,C),role:"treeitem","aria-expanded":F?J:void 0,"aria-selected":ie,"aria-disabled":q||void 0,id:V,tabIndex:-1},y,{ownerState:$,onFocus:he,ref:R,children:[Oe.jsx(Wug,Ke({as:o,ref:W,classes:{root:j.content,expanded:j.expanded,selected:j.selected,focused:j.focused,disabled:j.disabled,iconContainer:j.iconContainer,label:j.label},label:d,nodeId:h,onClick:m,onMouseDown:f,icon:c,expansionIcon:Q,displayIcon:te,ownerState:$},a)),n&&Oe.jsx(zNe,{id:h,children:Oe.jsx(Xug,Ke({as:b,unmountOnExit:!0,className:j.group,in:J,component:"ul",role:"group"},p,{children:n}))})]}))});var M8={},$F={};const Hug=P_(mug);var pue;function tke(){return pue||(pue=1,function(e){"use client";Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"default",{enumerable:!0,get:function(){return g.createSvgIcon}});var g=Hug}($F)),$F}var Tug=$Ne;Object.defineProperty(M8,"__esModule",{value:!0});var z8=M8.default=void 0,Nug=Tug(tke()),kug=Oe,Yug=(0,Nug.default)((0,kug.jsx)("path",{d:"M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z"}),"ExpandMore");z8=M8.default=Yug;var P8={},Kug=$Ne;Object.defineProperty(P8,"__esModule",{value:!0});var J8=P8.default=void 0,xug=Kug(tke()),Dug=Oe,Fug=(0,xug.default)((0,Dug.jsx)("path",{d:"M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}),"ChevronRight");J8=P8.default=Fug;class Sg{constructor(g,I,i,n,C,r){Gu(this,"name");Gu(this,"key");Gu(this,"always_show");Gu(this,"collapsing");Gu(this,"children_type");Gu(this,"children");this.name=g,this.key=I,this.always_show=i,this.collapsing=n,this.children_type=C,this.children=r}}const Eug=(e,g,I,i,n)=>{const C=zug(e);return Mug(C,g,I,i,n)},Mug=(e,g,I,i,n)=>{const[C,r]=U.useState(g),[o,a]=U.useState(i);U.useEffect(()=>{I(C)},[C]),U.useEffect(()=>{n(o)},[o]);const s=O8(e);return Oe.jsx(PNe,{className:"tree-view","aria-label":"Hierarchical tree describing displayed Gosling visualization.",defaultCollapseIcon:Oe.jsx(z8,{}),defaultExpanded:g,onNodeToggle:(A,l)=>{r(l)},defaultSelected:i,onNodeFocus:(A,l)=>{a(l)},defaultExpandIcon:Oe.jsx(J8,{}),children:s})};function O8(e){if(!e.children)if(e.always_show)e.children="This information cannot be displayed.";else return Oe.jsx(Oe.Fragment,{});if(typeof e.children=="string")return e.collapsing?Oe.jsx(rc,{nodeId:e.key,label:e.name,children:Oe.jsx(rc,{nodeId:e.key+"-item",label:e.children})}):Oe.jsx(rc,{nodeId:e.key,label:e.name+": "+e.children});if(e.children_type==="altnodelist"){const g=e.children,I=Object.keys(e.children).map((i,n)=>O8(g[n]));return Oe.jsxs(rc,{nodeId:e.key,label:e.name,children:[...I]})}else{const g=e.children;return Oe.jsx(rc,{nodeId:e.key,label:e.name,children:iNe(g)})}}function zug(e){return new Sg("Automatic description","tree",!0,!0,"altnodelist",[new Sg("Alt-text","alt",!0,!0,"value",e.alt),new Sg("Description","long",!0,!0,"value",e.longDescription),new Sg("Details","details",!0,!0,"altnodelist",[new Sg("Title","title",!1,!0,"value",e.title),new Sg("Subtitle","subtitle",!1,!0,"value",e.subtitle),...Pug(e)])])}function Pug(e){if(e.composition.nTracks===1)return Jug(e.tracks[0]);{const g=Object.keys(e.tracks).map((I,i)=>Oug(e.tracks[i]));return[new Sg("Composition","composition",!0,!0,"value",e.composition.description),new Sg("Tracks","tracks",!0,!0,"altnodelist",g)]}}function Jug(e){return[new Sg("Description","T-1-desc",!0,!0,"value",e.description),new Sg("Details","T-1-det",!0,!0,"altnodelist",[new Sg("Title","T-1-det-title",!1,!0,"value",e.title),gke(e,"1"),Ike(e,"1"),ike(e,"1")])]}function Oug(e){const g=e.position.details.trackNumber;return new Sg("Track "+e.position.description,"T-"+g,!0,!0,"altnodelist",[new Sg("Description","T-"+g+"-desc",!0,!0,"value",e.description),new Sg("Details","T-"+g+"-det",!0,!0,"altnodelist",[new Sg("Title","T-"+g+"-det-title",!1,!0,"value",e.title),new Sg("Position","T-"+g+"-det-pos",!0,!0,"altnodelist",[new Sg("Description","T-"+g+"-det-pos-desc",!0,!1,"value",e.position.description),new Sg("Track number","T-"+g+"-det-pos-trackN",!0,!1,"value",(e.position.details.trackNumber+1).toString())]),gke(e,g),Ike(e,g),ike(e,g)])])}function gke(e,g){let I;return e.alttype==="single"?I=e.charttype:e.alttype==="ov-mark"&&e.charttype&&(I=e8(e.charttype)),new Sg("Type","T-"+g+"-det-type",!1,!1,"value",I)}function Ike(e,g){return e.alttype==="single"||e.alttype==="ov-mark"?new Sg("Appearance","T-"+g+"-det-app",!1,!0,"altnodelist",[new Sg("Description","T-"+g+"-det-app-desc",!1,!0,"value",e.appearance.description),new Sg("Details","T-"+g+"-det-app-det",!1,!0,"altnodelist",[_ug(e,g),new Sg("Layout (linear or circular)","T-"+g+"-det-app-lay",!1,!1,"value",e.appearance.details.layout),new Sg("overlaid","T-"+g+"-det-app-overlaid",!1,!1,"value",cCg(e.appearance.details.overlaid)),...Lug(e,g)])]):FY()}function _ug(e,g){let I;return e.alttype==="ov-mark"?I=e8(e.appearance.details.mark):I=e.appearance.details.mark,new Sg("Mark","T-"+g+"-det-pos-app-mark",!1,!1,"value",I)}function Lug(e,g){return e.appearance.details.encodingsDescList.map((i,n)=>new Sg(i[0],"T-"+g+"-det-pos-enc"+i[0]+n,!1,!0,"value",i[1]))}function ike(e,g){var I;return(e.alttype==="single"||e.alttype==="ov-mark")&&e.data.details.dataStatistics?new Sg("Data","T-"+g+"-det-data",!0,!0,"altnodelist",[new Sg("Description","T-"+g+"-det-data-desc",!0,!0,"value",e.data.description),nke(e.data.details.dataStatistics,g),new Sg("Raw data","T-"+g+"-det-data-raw-data",!0,!0,"rawData",(I=e.data.details.dataStatistics)==null?void 0:I.flatTileData)]):FY()}function bue(e,g){return g?g.map((i,n)=>new Sg(i[0],"T-"+e+"-det-pos-enc"+i[0]+n,!1,!1,"value",i[1])):[FY()]}function nke(e,g){return new Sg("Data statistics","T-"+g+"-det-data-stats",!1,!0,"altnodelist",[new Sg("Genomic range","T-"+g+"-det-data-stats-genomic",!1,!0,"altnodelist",[...bue("T-"+g+"-det-data-stats-genomic",e.genomicDescList)]),new Sg("Value range","T-"+g+"-det-data-stats-value",!1,!0,"altnodelist",[...bue("T-"+g+"-det-data-stats-value",e.valueDescList)]),Uug(e,g)])}function Uug(e,g){return e.categories?new Sg("Categories","T-"+g+"-det-data-stats-categories",!1,!1,"value",e8(e.categories)):FY()}function FY(){return new Sg("","",!1,!1,"value",void 0)}function yue(e,g,I,i,n,C,r){const[o,a]=U.useState(e),[s,A]=U.useState(I);if(U.useEffect(()=>{g(o)},[o]),U.useEffect(()=>{i(s)},[s]),n.alttype=="ov-data")return console.log("overlaid with data not yet supported"),Oe.jsx(Oe.Fragment,{});let l;r?r.id==C.id?C.genomicMin&&C.genomicMax&&(l=`Genomic range has been changed, now showing ${eHe(C.genomicMin,C.genomicMax)}.`):l=`Showing track ${C.id}`:l=`Showing track ${C.id}`;const c=nke(C,n.uid),u=iNe(C.flatTileData);return Oe.jsx(PNe,{className:"data-panel-tree","aria-label":"Hierarchical tree describing updated data.",defaultCollapseIcon:Oe.jsx(z8,{}),defaultExpanded:e,onNodeToggle:(d,h)=>{a(h)},defaultSelected:I,onNodeFocus:(d,h)=>{A(h)},defaultExpandIcon:Oe.jsx(J8,{}),children:Oe.jsxs(rc,{nodeId:"tree",label:"Data panel",children:[Oe.jsx(rc,{nodeId:"desc",label:l}),O8(c),Oe.jsx(rc,{nodeId:"rawData",label:"Raw Data",children:u})]})})}const Qug=U.createContext(),Zue=Qug;function jug(e){return li("MuiGrid",e)}const $ug=[0,1,2,3,4,5,6,7,8,9,10],qug=["column-reverse","column","row-reverse","row"],edg=["nowrap","wrap-reverse","wrap"],SZ=["auto",!0,1,2,3,4,5,6,7,8,9,10,11,12],fS=HI("MuiGrid",["root","container","item","zeroMinWidth",...$ug.map(e=>`spacing-xs-${e}`),...qug.map(e=>`direction-xs-${e}`),...edg.map(e=>`wrap-xs-${e}`),...SZ.map(e=>`grid-xs-${e}`),...SZ.map(e=>`grid-sm-${e}`),...SZ.map(e=>`grid-md-${e}`),...SZ.map(e=>`grid-lg-${e}`),...SZ.map(e=>`grid-xl-${e}`)]),tdg=["className","columns","columnSpacing","component","container","direction","item","rowSpacing","spacing","wrap","zeroMinWidth"];function eb(e){const g=parseFloat(e);return`${g}${String(e).replace(String(g),"")||"px"}`}function gdg({theme:e,ownerState:g}){let I;return e.breakpoints.keys.reduce((i,n)=>{let C={};if(g[n]&&(I=g[n]),!I)return i;if(I===!0)C={flexBasis:0,flexGrow:1,maxWidth:"100%"};else if(I==="auto")C={flexBasis:"auto",flexGrow:0,flexShrink:0,maxWidth:"none",width:"auto"};else{const r=WY({values:g.columns,breakpoints:e.breakpoints.values}),o=typeof r=="object"?r[n]:r;if(o==null)return i;const a=`${Math.round(I/o*1e8)/1e6}%`;let s={};if(g.container&&g.item&&g.columnSpacing!==0){const A=e.spacing(g.columnSpacing);if(A!=="0px"){const l=`calc(${a} + ${eb(A)})`;s={flexBasis:l,maxWidth:l}}}C=Ke({flexBasis:a,flexGrow:0,maxWidth:a},s)}return e.breakpoints.values[n]===0?Object.assign(i,C):i[e.breakpoints.up(n)]=C,i},{})}function Idg({theme:e,ownerState:g}){const I=WY({values:g.direction,breakpoints:e.breakpoints.values});return ao({theme:e},I,i=>{const n={flexDirection:i};return i.indexOf("column")===0&&(n[`& > .${fS.item}`]={maxWidth:"none"}),n})}function Cke({breakpoints:e,values:g}){let I="";Object.keys(g).forEach(n=>{I===""&&g[n]!==0&&(I=n)});const i=Object.keys(e).sort((n,C)=>e[n]-e[C]);return i.slice(0,i.indexOf(I))}function idg({theme:e,ownerState:g}){const{container:I,rowSpacing:i}=g;let n={};if(I&&i!==0){const C=WY({values:i,breakpoints:e.breakpoints.values});let r;typeof C=="object"&&(r=Cke({breakpoints:e.breakpoints.values,values:C})),n=ao({theme:e},C,(o,a)=>{var s;const A=e.spacing(o);return A!=="0px"?{marginTop:`-${eb(A)}`,[`& > .${fS.item}`]:{paddingTop:eb(A)}}:(s=r)!=null&&s.includes(a)?{}:{marginTop:0,[`& > .${fS.item}`]:{paddingTop:0}}})}return n}function ndg({theme:e,ownerState:g}){const{container:I,columnSpacing:i}=g;let n={};if(I&&i!==0){const C=WY({values:i,breakpoints:e.breakpoints.values});let r;typeof C=="object"&&(r=Cke({breakpoints:e.breakpoints.values,values:C})),n=ao({theme:e},C,(o,a)=>{var s;const A=e.spacing(o);return A!=="0px"?{width:`calc(100% + ${eb(A)})`,marginLeft:`-${eb(A)}`,[`& > .${fS.item}`]:{paddingLeft:eb(A)}}:(s=r)!=null&&s.includes(a)?{}:{width:"100%",marginLeft:0,[`& > .${fS.item}`]:{paddingLeft:0}}})}return n}function Cdg(e,g,I={}){if(!e||e<=0)return[];if(typeof e=="string"&&!Number.isNaN(Number(e))||typeof e=="number")return[I[`spacing-xs-${String(e)}`]];const i=[];return g.forEach(n=>{const C=e[n];Number(C)>0&&i.push(I[`spacing-${n}-${String(C)}`])}),i}const rdg=qt("div",{name:"MuiGrid",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e,{container:i,direction:n,item:C,spacing:r,wrap:o,zeroMinWidth:a,breakpoints:s}=I;let A=[];i&&(A=Cdg(r,s,g));const l=[];return s.forEach(c=>{const u=I[c];u&&l.push(g[`grid-${c}-${String(u)}`])}),[g.root,i&&g.container,C&&g.item,a&&g.zeroMinWidth,...A,n!=="row"&&g[`direction-xs-${String(n)}`],o!=="wrap"&&g[`wrap-xs-${String(o)}`],...l]}})(({ownerState:e})=>Ke({boxSizing:"border-box"},e.container&&{display:"flex",flexWrap:"wrap",width:"100%"},e.item&&{margin:0},e.zeroMinWidth&&{minWidth:0},e.wrap!=="wrap"&&{flexWrap:e.wrap}),Idg,idg,ndg,gdg);function odg(e,g){if(!e||e<=0)return[];if(typeof e=="string"&&!Number.isNaN(Number(e))||typeof e=="number")return[`spacing-xs-${String(e)}`];const I=[];return g.forEach(i=>{const n=e[i];if(Number(n)>0){const C=`spacing-${i}-${String(n)}`;I.push(C)}}),I}const adg=e=>{const{classes:g,container:I,direction:i,item:n,spacing:C,wrap:r,zeroMinWidth:o,breakpoints:a}=e;let s=[];I&&(s=odg(C,a));const A=[];a.forEach(c=>{const u=e[c];u&&A.push(`grid-${c}-${String(u)}`)});const l={root:["root",I&&"container",n&&"item",o&&"zeroMinWidth",...s,i!=="row"&&`direction-xs-${String(i)}`,r!=="wrap"&&`wrap-xs-${String(r)}`,...A]};return vi(l,jug,g)},Adg=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiGrid"}),{breakpoints:n}=fy(),C=Alg(i),{className:r,columns:o,columnSpacing:a,component:s="div",container:A=!1,direction:l="row",item:c=!1,rowSpacing:u,spacing:d=0,wrap:h="wrap",zeroMinWidth:m=!1}=C,f=Qt(C,tdg),b=u||d,p=a||d,y=U.useContext(Zue),Z=A?o||12:y,B={},G=Ke({},f);n.keys.forEach(V=>{f[V]!=null&&(B[V]=f[V],delete G[V])});const v=Ke({},C,{columns:Z,container:A,direction:l,item:c,rowSpacing:b,columnSpacing:p,wrap:h,zeroMinWidth:m,spacing:d},B,{breakpoints:n.keys}),w=adg(v);return Oe.jsx(Zue.Provider,{value:Z,children:Oe.jsx(rdg,Ke({ownerState:v,className:ug(w.root,r),as:s,ref:I},G))})}),vd=Adg,sdg=e=>{const g=U.useRef(null),[I,i]=U.useState(),n=U.useRef([]),[C,r]=U.useState(-1),[o,a]=U.useState(),[s,A]=U.useState(),l=U.useRef(["tree"]),c=U.useRef("tree"),u=S=>{l.current=S},d=S=>{c.current=S},h=U.useRef(["tree"]),m=U.useRef("tree"),f=S=>{h.current=S},b=S=>{m.current=S},[p,y]=U.useState({width:0,height:0}),[Z,B]=U.useState([0,0,0]);U.useEffect(()=>{const S=[12,12,12];let X=e.layout,W=e.layoutPanels;X||(p.width>p.height?X="vertical":X="horizontal"),W||(X==="vertical"?W="horizontal":W="vertical"),X==="vertical"?(S[0]=12,W=="vertical"?(S[1]=12,S[2]=12):(S[1]=6,S[2]=6)):(S[0]=6,W=="vertical"?(S[1]=6,S[2]=6):(S[1]=3,S[2]=3)),B(S)},[p]),U.useEffect(()=>{if(I){const S=sCg(I);y({width:I._assignedWidth,height:I._assignedHeight}),G(S),a(void 0),A(void 0)}},[I]);function G(S){const X=JSON.stringify(S),W={id:X,data:S},R=n.current.filter(H=>H.id!==X);n.current=[...R,{...W}],r(n.current.length-1)}function v(S,X){const W={altTrack:S,altDataStatistics:X};A(o),a(W)}U.useEffect(()=>(g.current&&g.current.api.subscribe("rawData",(X,W)=>{const R=lCg(n.current[C].data,W.id,W.data);G(R);let H;for(const Y in R.tracks)R.tracks[Y].alttype=="ov-data"?(H=R.tracks[Y],W.id in H.uids):(H=R.tracks[Y],W.id==H.uid&&H.data.details.dataStatistics&&v(H,H.data.details.dataStatistics))}),()=>{var S;(S=g.current)==null||S.api.unsubscribe("rawData")}),[g.current]);const w=()=>{let S=["tree"];l.current&&(S=l.current);let X="tree";return c.current&&(X=c.current),Oe.jsx("div",{className:"editor-alt-text-panel",children:C>=0&&n.current[C]&&Object.keys(n.current[C].data).length>0?Oe.jsx(Oe.Fragment,{children:Oe.jsx("div",{className:"editor-alt-text-body",children:Oe.jsx("div",{children:Eug(n.current[C].data,S,u,X,d)})})}):null})},V=()=>{let S=["tree"];h.current&&(S=h.current);let X="tree";m.current&&(X=m.current);let W;return o?(s?W=yue(S,f,X,b,o.altTrack,o.altDataStatistics,s.altDataStatistics):W=yue(S,f,X,b,o.altTrack,o.altDataStatistics),Oe.jsx("div",{className:"editor-data-panel",children:Oe.jsx("div",{className:"editor-alt-text-body",children:Oe.jsx("div",{children:W})})})):Oe.jsx(Oe.Fragment,{})};return Oe.jsx(Oe.Fragment,{children:Oe.jsxs(vd,{container:!0,rowSpacing:3,columnSpacing:{xs:1,sm:1},"aria-label":"altgosling-component-container",children:[Oe.jsx(vd,{item:!0,xs:Z[0],children:Oe.jsx("div",{"aria-label":"gosling-component-container",children:Oe.jsx(U2e,{ref:g,...e,compiled:(S,X,W)=>{i(W._processedSpec)}})})}),Oe.jsx(vd,{item:!0,xs:Z[1],children:Oe.jsx(w,{})}),Oe.jsx(vd,{item:!0,xs:Z[2],children:Oe.jsx(V,{})})]})})},ldg={title:"Basic Marks: bar",subtitle:"Tutorial Examples",tracks:[{layout:"linear",width:800,height:180,data:{url:"https://resgen.io/api/v1/tileset_info/?d=UvVPeLHuRDiYA3qwFlm7xQ",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1"],binSize:5},mark:"bar",x:{field:"start",type:"genomic",axis:"bottom"},xe:{field:"end",type:"genomic"},y:{field:"peak",type:"quantitative",axis:"right"},size:{value:5}}]},cdg={title:"Visual Encoding",subtitle:"Gosling provides diverse visual encoding methods",layout:"linear",arrangement:"vertical",centerRadius:.8,xDomain:{chromosome:"chr1",interval:[1,3000500]},views:[{tracks:[{id:"track-1",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"],binSize:4},mark:"rect",x:{field:"start",type:"genomic",axis:"top"},xe:{field:"end",type:"genomic"},row:{field:"sample",type:"nominal",legend:!0},color:{field:"peak",type:"quantitative",legend:!0},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},{tracks:[{id:"track-2",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]},mark:"bar",x:{field:"position",type:"genomic",axis:"top"},y:{field:"peak",type:"quantitative"},row:{field:"sample",type:"nominal"},color:{field:"sample",type:"nominal",legend:!0},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},{tracks:[{id:"track-3",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]},mark:"bar",x:{field:"position",type:"genomic",axis:"top"},y:{field:"peak",type:"quantitative",grid:!0},color:{field:"sample",type:"nominal",legend:!0},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},{id:"track-4",alignment:"overlay",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]},x:{field:"position",type:"genomic",axis:"top"},y:{field:"peak",type:"quantitative"},row:{field:"sample",type:"nominal"},color:{field:"sample",type:"nominal",legend:!0},tracks:[{mark:"line"},{mark:"point",size:{field:"peak",type:"quantitative",range:[0,2]}}],tooltip:[{field:"position",type:"genomic",alt:"Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130},{tracks:[{id:"track-5",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]},mark:"point",x:{field:"position",type:"genomic",axis:"top"},y:{field:"peak",type:"quantitative"},row:{field:"sample",type:"nominal"},size:{field:"peak",type:"quantitative"},color:{field:"sample",type:"nominal",legend:!0},opacity:{value:.5},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},{tracks:[{id:"track-6",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]},mark:"point",x:{field:"position",type:"genomic",axis:"top"},y:{field:"peak",type:"quantitative",grid:!0},size:{field:"peak",type:"quantitative"},color:{field:"sample",type:"nominal",legend:!0},opacity:{value:.5},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},{tracks:[{id:"track-7",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]},mark:"area",x:{field:"position",type:"genomic",axis:"top"},y:{field:"peak",type:"quantitative"},row:{field:"sample",type:"nominal"},color:{field:"sample",type:"nominal",legend:!0},stroke:{value:"white"},strokeWidth:{value:.5},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},{tracks:[{id:"track-8",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"],binSize:4},mark:"bar",x:{field:"start",type:"genomic",axis:"top"},xe:{field:"end",type:"genomic",axis:"top"},y:{field:"peak_min",type:"quantitative"},ye:{field:"peak_max",type:"quantitative"},row:{field:"sample",type:"nominal"},color:{field:"sample",type:"nominal",legend:!0},stroke:{value:"black"},strokeWidth:{value:.2},tooltip:[{field:"position",type:"genomic",alt:"Position"},{field:"peak_min",type:"quantitative",alt:"min(Value)",format:".2"},{field:"peak_max",type:"quantitative",alt:"max(Value)",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},{tracks:[{id:"track-9",data:{url:"https://raw.githubusercontent.com/sehilyi/gemini-datasets/master/data/circos-segdup-edited.txt",type:"csv",chromosomeField:"c2",genomicFields:["s1","e1","s2","e2"]},mark:"withinLink",x:{field:"s1",type:"genomic",domain:{chromosome:"chr1",interval:[1039e5,1041e5]}},xe:{field:"e1",type:"genomic"},x1:{field:"s2",type:"genomic",domain:{chromosome:"chr1"}},x1e:{field:"e2",type:"genomic"},color:{field:"s1",type:"nominal"},stroke:{value:"black"},strokeWidth:{value:.5},opacity:{value:.2},width:600,height:130}]}]},udg={title:"Visual Encoding",subtitle:"Gosling provides diverse visual encoding methods",layout:"linear",arrangement:"vertical",centerRadius:.8,xDomain:{chromosome:"chr1",interval:[1,3000500]},views:[{tracks:[{id:"track-1",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"],binSize:4},mark:"rect",x:{field:"start",type:"genomic",axis:"top"},xe:{field:"end",type:"genomic"},row:{field:"sample",type:"nominal",legend:!0},color:{field:"peak",type:"quantitative",legend:!0},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},{tracks:[{id:"track-2",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]},mark:"bar",x:{field:"position",type:"genomic",axis:"top"},y:{field:"peak",type:"quantitative"},row:{field:"sample",type:"nominal"},color:{field:"sample",type:"nominal",legend:!0},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]}]},ddg={title:"Visual Encoding",subtitle:"Gosling provides diverse visual encoding methods",layout:"linear",arrangement:"vertical",centerRadius:.8,xDomain:{chromosome:"chr1",interval:[1,3000500]},views:[{id:"track-4",alignment:"overlay",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]},x:{field:"position",type:"genomic",axis:"top"},y:{field:"peak",type:"quantitative"},row:{field:"sample",type:"nominal"},color:{field:"sample",type:"nominal",legend:!0},tracks:[{mark:"line"},{mark:"point",size:{field:"peak",type:"quantitative",range:[0,2]}}],tooltip:[{field:"position",type:"genomic",alt:"Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},hdg={title:"Visual Encoding",subtitle:"Gosling provides diverse visual encoding methods",layout:"linear",arrangement:"vertical",centerRadius:.8,xDomain:{chromosome:"chr1",interval:[1,3000500]},views:[{id:"track-4",alignment:"overlay",x:{field:"position",type:"genomic",axis:"top"},y:{field:"peak",type:"quantitative"},row:{field:"sample",type:"nominal"},color:{field:"sample",type:"nominal",legend:!0},tracks:[{mark:"line",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]}},{mark:"point",size:{field:"peak",type:"quantitative",range:[0,2]},data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]}}],tooltip:[{field:"position",type:"genomic",alt:"Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},mdg={title:"Rule Mark",subtitle:"Annotate visualization with horizontal and vertical lines",style:{dashed:[3,3]},views:[{alignment:"overlay",tracks:[{data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1"],binSize:4},mark:"bar",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},y:{field:"peak",type:"quantitative",domain:[0,.003]},color:{value:"lightgray"}},{data:{type:"json",values:[{c:"chr2",p:1e5,v:1e-4},{c:"chr5",p:1e5,v:4e-4},{c:"chr10",p:1e5,v:9e-4}],chromosomeField:"c",genomicFields:["p"]},mark:"rule",x:{field:"p",type:"genomic"},y:{field:"v",type:"quantitative",domain:[0,.003]},strokeWidth:{field:"v",type:"quantitative"},color:{value:"red"}},{data:{type:"json",values:[{c:"chr2",p:1e5,v:1e-4},{c:"chr5",p:1e5,v:4e-4},{c:"chr10",p:1e5,v:9e-4}],chromosomeField:"c",genomicFields:["p"]},mark:"rule",x:{field:"p",type:"genomic"},strokeWidth:{value:2},color:{value:"blue"}}],width:500,height:200}]},fdg={title:"Rule Mark",subtitle:"Annotate visualization with horizontal and vertical lines",style:{dashed:[3,3]},views:[{alignment:"overlay",tracks:[{data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1"],binSize:4},mark:"bar",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},y:{field:"peak",type:"quantitative",domain:[0,.003]},color:{value:"lightgray"}},{data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1"],binSize:4},mark:"point",x:{field:"start",type:"genomic"},y:{field:"peak",type:"quantitative",domain:[0,.003]},color:{value:"red"}}],width:500,height:200}]},pdg={title:"GIVE",subtitle:"Reimplementation of GenoCAT examples",spacing:60,arrangement:"vertical",views:[{layout:"linear",tracks:[{alignment:"overlay",title:"Genes",data:{url:"https://resgen.io/api/v1/tileset_info/?d=M9A9klpwTci5Vf4bHZ864g",type:"beddb",genomicFields:[{index:1,name:"start"},{index:2,name:"end"}],valueFields:[{index:5,name:"strand",type:"nominal"},{index:3,name:"name",type:"nominal"}],exonIntervalFields:[{index:12,name:"start"},{index:13,name:"end"}]},tracks:[{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["+"]}],mark:"rect",x:{field:"end",type:"genomic",domain:{chromosome:"chr17",interval:[2e5,8e5]},axis:"top"},size:{value:7}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["-"]}],mark:"rect",x:{field:"start",type:"genomic"},size:{value:7}},{dataTransform:[{type:"filter",field:"type",oneOf:["exon"]}],mark:"rect",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},size:{value:14}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]}],mark:"rule",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},strokeWidth:{value:3}}],row:{field:"strand",type:"nominal",domain:["+","-"]},color:{value:"#4050B4"},width:700,height:50},{data:{url:"https://resgen.io/api/v1/tileset_info/?d=Zz3CBDSqQ3ySrOSe2yj1eg",type:"vector",column:"position",value:"peak",binSize:4},mark:"bar",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},y:{field:"peak",type:"quantitative"},color:{value:"#8A96D5"},stroke:{value:"#3C4DB4"},strokeWidth:{value:.5},width:700,height:40},{data:{url:"https://resgen.io/api/v1/tileset_info/?d=dc_SOjdCRgq_8PYf6W--7w",type:"vector",column:"position",value:"peak",binSize:4},mark:"bar",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},y:{field:"peak",type:"quantitative"},color:{value:"#8A96D5"},stroke:{value:"#3C4DB4"},strokeWidth:{value:.5},width:700,height:40},{data:{url:"https://resgen.io/api/v1/tileset_info/?d=Nolbrk9kS3CE0jJL_7OW1g",type:"vector",column:"position",value:"peak",binSize:4},mark:"bar",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},y:{field:"peak",type:"quantitative"},color:{value:"#8A96D5"},stroke:{value:"#3C4DB4"},strokeWidth:{value:.5},width:700,height:40},{alignment:"overlay",data:{url:"https://raw.githubusercontent.com/sehilyi/gemini-datasets/master/data/UCSC.HG38.Human.CytoBandIdeogram.csv",type:"csv",chromosomeField:"Chromosome",genomicFields:["chromStart","chromEnd"]},tracks:[{mark:"rect",dataTransform:[{type:"filter",field:"Stain",oneOf:["acen"],not:!0}]},{mark:"triangleRight",dataTransform:[{type:"filter",field:"Stain",oneOf:["acen"]},{type:"filter",field:"Name",include:"q"}]},{mark:"triangleLeft",dataTransform:[{type:"filter",field:"Stain",oneOf:["acen"]},{type:"filter",field:"Name",include:"p"}]}],x:{field:"chromStart",type:"genomic",domain:{chromosome:"chr17",interval:[2e7,5e7]}},xe:{field:"chromEnd",type:"genomic"},color:{value:"white"},size:{value:14},stroke:{value:"black"},strokeWidth:{value:.5},width:700,height:40},{data:{url:"https://raw.githubusercontent.com/vigsterkr/circos/master/data/5/segdup.txt",type:"csv",headerNames:["id","chr","p1","p2"],chromosomePrefix:"hs",chromosomeField:"chr",genomicFields:["p1","p2"],separator:" ",longToWideId:"id"},dataTransform:[{type:"filter",field:"chr",oneOf:["hs17"]}],mark:"rect",x:{field:"p1",type:"genomic"},xe:{field:"p2",type:"genomic"},color:{field:"chr_2",type:"nominal",domain:["chr1","chr2","chr3","chr4","chr5","chr6","chr7","chr8","chr9","chr10","chr11","chr12","chr13","chr14","chr15","chr16","chr17","chr18","chr19","chr20","chr21","chr22","chrX","chrY"]},opacity:{value:.5},size:{value:14},overlayOnPreviousTrack:!0,width:700,height:40}]},{layout:"linear",tracks:[{alignment:"overlay",data:{url:"https://raw.githubusercontent.com/sehilyi/gemini-datasets/master/data/UCSC.HG38.Human.CytoBandIdeogram.csv",type:"csv",chromosomeField:"Chromosome",genomicFields:["chromStart","chromEnd"]},tracks:[{mark:"rect",dataTransform:[{type:"filter",field:"Stain",oneOf:["acen"],not:!0}]},{mark:"triangleRight",dataTransform:[{type:"filter",field:"Stain",oneOf:["acen"]},{type:"filter",field:"Name",include:"q"}]},{mark:"triangleLeft",dataTransform:[{type:"filter",field:"Stain",oneOf:["acen"]},{type:"filter",field:"Name",include:"p"}]}],x:{field:"chromStart",type:"genomic",axis:"none"},xe:{field:"chromEnd",type:"genomic"},color:{value:"white"},size:{value:14},stroke:{value:"black"},strokeWidth:{value:.5},width:700,height:40},{data:{url:"https://raw.githubusercontent.com/vigsterkr/circos/master/data/5/segdup.txt",type:"csv",headerNames:["id","chr","p1","p2"],chromosomePrefix:"hs",chromosomeField:"chr",genomicFields:["p1","p2"],separator:" ",longToWideId:"id"},dataTransform:[{type:"filter",field:"chr_2",oneOf:["hs1"]}],mark:"rect",x:{field:"p1_2",type:"genomic"},xe:{field:"p2_2",type:"genomic"},color:{field:"chr",type:"nominal",domain:["chr1","chr2","chr3","chr4","chr5","chr6","chr7","chr8","chr9","chr10","chr11","chr12","chr13","chr14","chr15","chr16","chr17","chr18","chr19","chr20","chr21","chr22","chrX","chrY"]},opacity:{value:.5},size:{value:14},overlayOnPreviousTrack:!0,width:700,height:40},{data:{url:"https://resgen.io/api/v1/tileset_info/?d=Zz3CBDSqQ3ySrOSe2yj1eg",type:"vector",column:"position",value:"peak",binSize:4},mark:"bar",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},y:{field:"peak",type:"quantitative"},color:{value:"#8A96D5"},stroke:{value:"#3C4DB4"},strokeWidth:{value:.5},width:700,height:40},{data:{url:"https://resgen.io/api/v1/tileset_info/?d=dc_SOjdCRgq_8PYf6W--7w",type:"vector",column:"position",value:"peak",binSize:4},mark:"bar",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},y:{field:"peak",type:"quantitative"},color:{value:"#8A96D5"},stroke:{value:"#3C4DB4"},strokeWidth:{value:.5},width:700,height:40},{data:{url:"https://resgen.io/api/v1/tileset_info/?d=Nolbrk9kS3CE0jJL_7OW1g",type:"vector",column:"position",value:"peak",binSize:4},mark:"bar",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},y:{field:"peak",type:"quantitative"},color:{value:"#8A96D5"},stroke:{value:"#3C4DB4"},strokeWidth:{value:.5},width:700,height:40},{alignment:"overlay",title:"Genes",data:{url:"https://resgen.io/api/v1/tileset_info/?d=M9A9klpwTci5Vf4bHZ864g",type:"beddb",genomicFields:[{index:1,name:"start"},{index:2,name:"end"}],valueFields:[{index:5,name:"strand",type:"nominal"},{index:3,name:"name",type:"nominal"}],exonIntervalFields:[{index:12,name:"start"},{index:13,name:"end"}]},tracks:[{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["+"]}],mark:"rect",x:{field:"end",type:"genomic",domain:{chromosome:"chr1",interval:[109e6,112e6]},axis:"bottom"},size:{value:7}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["-"]}],mark:"rect",x:{field:"start",type:"genomic"},size:{value:7}},{dataTransform:[{type:"filter",field:"type",oneOf:["exon"]}],mark:"rect",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},size:{value:14}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]}],mark:"rule",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},strokeWidth:{value:3}}],row:{field:"strand",type:"nominal",domain:["+","-"]},color:{value:"#4050B4"},width:700,height:50}]}],style:{outlineWidth:0}};function Gue(e){return e!=null&&!(Array.isArray(e)&&e.length===0)}function OH(e,g=!1){return e&&(Gue(e.value)&&e.value!==""||g&&Gue(e.defaultValue)&&e.defaultValue!=="")}function bdg(e){return e.startAdornment}const ydg=U.createContext(void 0),_8=ydg;function Zdg(e){return li("MuiFormControl",e)}HI("MuiFormControl",["root","marginNone","marginNormal","marginDense","fullWidth","disabled"]);const Gdg=["children","className","color","component","disabled","error","focused","fullWidth","hiddenLabel","margin","required","size","variant"],vdg=e=>{const{classes:g,margin:I,fullWidth:i}=e,n={root:["root",I!=="none"&&`margin${si(I)}`,i&&"fullWidth"]};return vi(n,Zdg,g)},Bdg=qt("div",{name:"MuiFormControl",slot:"Root",overridesResolver:({ownerState:e},g)=>Ke({},g.root,g[`margin${si(e.margin)}`],e.fullWidth&&g.fullWidth)})(({ownerState:e})=>Ke({display:"inline-flex",flexDirection:"column",position:"relative",minWidth:0,padding:0,margin:0,border:0,verticalAlign:"top"},e.margin==="normal"&&{marginTop:16,marginBottom:8},e.margin==="dense"&&{marginTop:8,marginBottom:4},e.fullWidth&&{width:"100%"})),Sdg=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiFormControl"}),{children:n,className:C,color:r="primary",component:o="div",disabled:a=!1,error:s=!1,focused:A,fullWidth:l=!1,hiddenLabel:c=!1,margin:u="none",required:d=!1,size:h="medium",variant:m="outlined"}=i,f=Qt(i,Gdg),b=Ke({},i,{color:r,component:o,disabled:a,error:s,fullWidth:l,hiddenLabel:c,margin:u,required:d,size:h,variant:m}),p=vdg(b),[y,Z]=U.useState(()=>{let W=!1;return n&&U.Children.forEach(n,R=>{if(!xW(R,["Input","Select"]))return;const H=xW(R,["Select"])?R.props.input:R;H&&bdg(H.props)&&(W=!0)}),W}),[B,G]=U.useState(()=>{let W=!1;return n&&U.Children.forEach(n,R=>{xW(R,["Input","Select"])&&(OH(R.props,!0)||OH(R.props.inputProps,!0))&&(W=!0)}),W}),[v,w]=U.useState(!1);a&&v&&w(!1);const V=A!==void 0&&!a?A:v;let S;const X=U.useMemo(()=>({adornedStart:y,setAdornedStart:Z,color:r,disabled:a,error:s,filled:B,focused:V,fullWidth:l,hiddenLabel:c,size:h,onBlur:()=>{w(!1)},onEmpty:()=>{G(!1)},onFilled:()=>{G(!0)},onFocus:()=>{w(!0)},registerEffect:S,required:d,variant:m}),[y,r,a,s,B,V,l,c,S,d,h,m]);return Oe.jsx(_8.Provider,{value:X,children:Oe.jsx(Bdg,Ke({as:o,ownerState:b,className:ug(p.root,C),ref:I},f,{children:n}))})}),wdg=Sdg;function Pw(){return U.useContext(_8)}function Jw({props:e,states:g,muiFormControl:I}){return g.reduce((i,n)=>(i[n]=e[n],I&&typeof e[n]>"u"&&(i[n]=I[n]),i),{})}function Vdg(e){return li("MuiFormLabel",e)}const Rdg=HI("MuiFormLabel",["root","colorSecondary","focused","disabled","error","filled","required","asterisk"]),Kv=Rdg,Wdg=["children","className","color","component","disabled","error","filled","focused","required"],Xdg=e=>{const{classes:g,color:I,focused:i,disabled:n,error:C,filled:r,required:o}=e,a={root:["root",`color${si(I)}`,n&&"disabled",C&&"error",r&&"filled",i&&"focused",o&&"required"],asterisk:["asterisk",C&&"error"]};return vi(a,Vdg,g)},Hdg=qt("label",{name:"MuiFormLabel",slot:"Root",overridesResolver:({ownerState:e},g)=>Ke({},g.root,e.color==="secondary"&&g.colorSecondary,e.filled&&g.filled)})(({theme:e,ownerState:g})=>Ke({color:(e.vars||e).palette.text.secondary},e.typography.body1,{lineHeight:"1.4375em",padding:0,position:"relative",[`&.${Kv.focused}`]:{color:(e.vars||e).palette[g.color].main},[`&.${Kv.disabled}`]:{color:(e.vars||e).palette.text.disabled},[`&.${Kv.error}`]:{color:(e.vars||e).palette.error.main}})),Tdg=qt("span",{name:"MuiFormLabel",slot:"Asterisk",overridesResolver:(e,g)=>g.asterisk})(({theme:e})=>({[`&.${Kv.error}`]:{color:(e.vars||e).palette.error.main}})),Ndg=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiFormLabel"}),{children:n,className:C,component:r="label"}=i,o=Qt(i,Wdg),a=Pw(),s=Jw({props:i,muiFormControl:a,states:["color","required","focused","disabled","error","filled"]}),A=Ke({},i,{color:s.color||"primary",component:r,disabled:s.disabled,error:s.error,filled:s.filled,focused:s.focused,required:s.required}),l=Xdg(A);return Oe.jsxs(Hdg,Ke({as:r,ownerState:A,className:ug(l.root,C),ref:I},o,{children:[n,s.required&&Oe.jsxs(Tdg,{ownerState:A,"aria-hidden":!0,className:l.asterisk,children:[" ","*"]})]}))}),kdg=Ndg;function Ydg(e){return li("MuiInputLabel",e)}HI("MuiInputLabel",["root","focused","disabled","error","required","asterisk","formControl","sizeSmall","shrink","animated","standard","filled","outlined"]);const Kdg=["disableAnimation","margin","shrink","variant","className"],xdg=e=>{const{classes:g,formControl:I,size:i,shrink:n,disableAnimation:C,variant:r,required:o}=e,a={root:["root",I&&"formControl",!C&&"animated",n&&"shrink",i&&i!=="normal"&&`size${si(i)}`,r],asterisk:[o&&"asterisk"]},s=vi(a,Ydg,g);return Ke({},g,s)},Ddg=qt(kdg,{shouldForwardProp:e=>va(e)||e==="classes",name:"MuiInputLabel",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[{[`& .${Kv.asterisk}`]:g.asterisk},g.root,I.formControl&&g.formControl,I.size==="small"&&g.sizeSmall,I.shrink&&g.shrink,!I.disableAnimation&&g.animated,I.focused&&g.focused,g[I.variant]]}})(({theme:e,ownerState:g})=>Ke({display:"block",transformOrigin:"top left",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%"},g.formControl&&{position:"absolute",left:0,top:0,transform:"translate(0, 20px) scale(1)"},g.size==="small"&&{transform:"translate(0, 17px) scale(1)"},g.shrink&&{transform:"translate(0, -1.5px) scale(0.75)",transformOrigin:"top left",maxWidth:"133%"},!g.disableAnimation&&{transition:e.transitions.create(["color","transform","max-width"],{duration:e.transitions.duration.shorter,easing:e.transitions.easing.easeOut})},g.variant==="filled"&&Ke({zIndex:1,pointerEvents:"none",transform:"translate(12px, 16px) scale(1)",maxWidth:"calc(100% - 24px)"},g.size==="small"&&{transform:"translate(12px, 13px) scale(1)"},g.shrink&&Ke({userSelect:"none",pointerEvents:"auto",transform:"translate(12px, 7px) scale(0.75)",maxWidth:"calc(133% - 24px)"},g.size==="small"&&{transform:"translate(12px, 4px) scale(0.75)"})),g.variant==="outlined"&&Ke({zIndex:1,pointerEvents:"none",transform:"translate(14px, 16px) scale(1)",maxWidth:"calc(100% - 24px)"},g.size==="small"&&{transform:"translate(14px, 9px) scale(1)"},g.shrink&&{userSelect:"none",pointerEvents:"auto",maxWidth:"calc(133% - 32px)",transform:"translate(14px, -9px) scale(0.75)"}))),Fdg=U.forwardRef(function(g,I){const i=gi({name:"MuiInputLabel",props:g}),{disableAnimation:n=!1,shrink:C,className:r}=i,o=Qt(i,Kdg),a=Pw();let s=C;typeof s>"u"&&a&&(s=a.filled||a.focused||a.adornedStart);const A=Jw({props:i,muiFormControl:a,states:["size","variant","required","focused"]}),l=Ke({},i,{disableAnimation:n,formControl:a,shrink:s,size:A.size,variant:A.variant,required:A.required,focused:A.focused}),c=xdg(l);return Oe.jsx(Ddg,Ke({"data-shrink":s,ownerState:l,ref:I,className:ug(c.root,r)},o,{classes:c}))}),Edg=Fdg;function _H(e){return typeof e=="string"}function Mdg(e,g,I){return e===void 0||_H(e)?g:Ke({},g,{ownerState:Ke({},g.ownerState,I)})}function rke(e,g=[]){if(e===void 0)return{};const I={};return Object.keys(e).filter(i=>i.match(/^on[A-Z]/)&&typeof e[i]=="function"&&!g.includes(i)).forEach(i=>{I[i]=e[i]}),I}function zdg(e,g,I){return typeof e=="function"?e(g,I):e}function vue(e){if(e===void 0)return{};const g={};return Object.keys(e).filter(I=>!(I.match(/^on[A-Z]/)&&typeof e[I]=="function")).forEach(I=>{g[I]=e[I]}),g}function Pdg(e){const{getSlotProps:g,additionalProps:I,externalSlotProps:i,externalForwardedProps:n,className:C}=e;if(!g){const u=ug(I==null?void 0:I.className,C,n==null?void 0:n.className,i==null?void 0:i.className),d=Ke({},I==null?void 0:I.style,n==null?void 0:n.style,i==null?void 0:i.style),h=Ke({},I,n,i);return u.length>0&&(h.className=u),Object.keys(d).length>0&&(h.style=d),{props:h,internalRef:void 0}}const r=rke(Ke({},n,i)),o=vue(i),a=vue(n),s=g(r),A=ug(s==null?void 0:s.className,I==null?void 0:I.className,C,n==null?void 0:n.className,i==null?void 0:i.className),l=Ke({},s==null?void 0:s.style,I==null?void 0:I.style,n==null?void 0:n.style,i==null?void 0:i.style),c=Ke({},s,I,a,o);return A.length>0&&(c.className=A),Object.keys(l).length>0&&(c.style=l),{props:c,internalRef:s.ref}}const Jdg=["elementType","externalSlotProps","ownerState","skipResolvingSlotProps"];function p0(e){var g;const{elementType:I,externalSlotProps:i,ownerState:n,skipResolvingSlotProps:C=!1}=e,r=Qt(e,Jdg),o=C?{}:zdg(i,n),{props:a,internalRef:s}=Pdg(Ke({},r,{externalSlotProps:o})),A=pn(s,o==null?void 0:o.ref,(g=e.additionalProps)==null?void 0:g.ref);return Mdg(I,Ke({},a,{ref:A}),n)}const Odg=U.createContext({}),E_=Odg;function _dg(e){return li("MuiList",e)}HI("MuiList",["root","padding","dense","subheader"]);const Ldg=["children","className","component","dense","disablePadding","subheader"],Udg=e=>{const{classes:g,disablePadding:I,dense:i,subheader:n}=e;return vi({root:["root",!I&&"padding",i&&"dense",n&&"subheader"]},_dg,g)},Qdg=qt("ul",{name:"MuiList",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[g.root,!I.disablePadding&&g.padding,I.dense&&g.dense,I.subheader&&g.subheader]}})(({ownerState:e})=>Ke({listStyle:"none",margin:0,padding:0,position:"relative"},!e.disablePadding&&{paddingTop:8,paddingBottom:8},e.subheader&&{paddingTop:0})),jdg=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiList"}),{children:n,className:C,component:r="ul",dense:o=!1,disablePadding:a=!1,subheader:s}=i,A=Qt(i,Ldg),l=U.useMemo(()=>({dense:o}),[o]),c=Ke({},i,{component:r,dense:o,disablePadding:a}),u=Udg(c);return Oe.jsx(E_.Provider,{value:l,children:Oe.jsxs(Qdg,Ke({as:r,className:ug(u.root,C),ref:I,ownerState:c},A,{children:[s,n]}))})}),$dg=jdg,qdg=["actions","autoFocus","autoFocusItem","children","className","disabledItemsFocusable","disableListWrap","onKeyDown","variant"];function qF(e,g,I){return e===g?e.firstChild:g&&g.nextElementSibling?g.nextElementSibling:I?null:e.firstChild}function Bue(e,g,I){return e===g?I?e.firstChild:e.lastChild:g&&g.previousElementSibling?g.previousElementSibling:I?null:e.lastChild}function oke(e,g){if(g===void 0)return!0;let I=e.innerText;return I===void 0&&(I=e.textContent),I=I.trim().toLowerCase(),I.length===0?!1:g.repeating?I[0]===g.keys[0]:I.indexOf(g.keys.join(""))===0}function wZ(e,g,I,i,n,C){let r=!1,o=n(e,g,g?I:!1);for(;o;){if(o===e.firstChild){if(r)return!1;r=!0}const a=i?!1:o.disabled||o.getAttribute("aria-disabled")==="true";if(!o.hasAttribute("tabindex")||!oke(o,C)||a)o=n(e,o,I);else return o.focus(),!0}return!1}const ehg=U.forwardRef(function(g,I){const{actions:i,autoFocus:n=!1,autoFocusItem:C=!1,children:r,className:o,disabledItemsFocusable:a=!1,disableListWrap:s=!1,onKeyDown:A,variant:l="selectedMenu"}=g,c=Qt(g,qdg),u=U.useRef(null),d=U.useRef({keys:[],repeating:!0,previousKeyMatched:!0,lastTime:null});Ls(()=>{n&&u.current.focus()},[n]),U.useImperativeHandle(i,()=>({adjustStyleForScrollbar:(p,y)=>{const Z=!u.current.style.width;if(p.clientHeight{const y=u.current,Z=p.key,B=zC(y).activeElement;if(Z==="ArrowDown")p.preventDefault(),wZ(y,B,s,a,qF);else if(Z==="ArrowUp")p.preventDefault(),wZ(y,B,s,a,Bue);else if(Z==="Home")p.preventDefault(),wZ(y,null,s,a,qF);else if(Z==="End")p.preventDefault(),wZ(y,null,s,a,Bue);else if(Z.length===1){const G=d.current,v=Z.toLowerCase(),w=performance.now();G.keys.length>0&&(w-G.lastTime>500?(G.keys=[],G.repeating=!0,G.previousKeyMatched=!0):G.repeating&&v!==G.keys[0]&&(G.repeating=!1)),G.lastTime=w,G.keys.push(v);const V=B&&!G.repeating&&oke(B,G);G.previousKeyMatched&&(V||wZ(y,B,!1,a,qF,G))?p.preventDefault():G.previousKeyMatched=!1}A&&A(p)},m=pn(u,I);let f=-1;U.Children.forEach(r,(p,y)=>{if(!U.isValidElement(p)){f===y&&(f+=1,f>=r.length&&(f=-1));return}p.props.disabled||(l==="selectedMenu"&&p.props.selected||f===-1)&&(f=y),f===y&&(p.props.disabled||p.props.muiSkipListHighlight||p.type.muiSkipListHighlight)&&(f+=1,f>=r.length&&(f=-1))});const b=U.Children.map(r,(p,y)=>{if(y===f){const Z={};return C&&(Z.autoFocus=!0),p.props.tabIndex===void 0&&l==="selectedMenu"&&(Z.tabIndex=0),U.cloneElement(p,Z)}return p});return Oe.jsx($dg,Ke({role:"menu",ref:m,className:o,onKeyDown:h,tabIndex:n?0:-1},c,{children:b}))}),thg=ehg,ghg=["input","select","textarea","a[href]","button","[tabindex]","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])'].join(",");function Ihg(e){const g=parseInt(e.getAttribute("tabindex")||"",10);return Number.isNaN(g)?e.contentEditable==="true"||(e.nodeName==="AUDIO"||e.nodeName==="VIDEO"||e.nodeName==="DETAILS")&&e.getAttribute("tabindex")===null?0:e.tabIndex:g}function ihg(e){if(e.tagName!=="INPUT"||e.type!=="radio"||!e.name)return!1;const g=i=>e.ownerDocument.querySelector(`input[type="radio"]${i}`);let I=g(`[name="${e.name}"]:checked`);return I||(I=g(`[name="${e.name}"]`)),I!==e}function nhg(e){return!(e.disabled||e.tagName==="INPUT"&&e.type==="hidden"||ihg(e))}function Chg(e){const g=[],I=[];return Array.from(e.querySelectorAll(ghg)).forEach((i,n)=>{const C=Ihg(i);C===-1||!nhg(i)||(C===0?g.push(i):I.push({documentOrder:n,tabIndex:C,node:i}))}),I.sort((i,n)=>i.tabIndex===n.tabIndex?i.documentOrder-n.documentOrder:i.tabIndex-n.tabIndex).map(i=>i.node).concat(g)}function rhg(){return!0}function ohg(e){const{children:g,disableAutoFocus:I=!1,disableEnforceFocus:i=!1,disableRestoreFocus:n=!1,getTabbable:C=Chg,isEnabled:r=rhg,open:o}=e,a=U.useRef(!1),s=U.useRef(null),A=U.useRef(null),l=U.useRef(null),c=U.useRef(null),u=U.useRef(!1),d=U.useRef(null),h=pn(g.ref,d),m=U.useRef(null);U.useEffect(()=>{!o||!d.current||(u.current=!I)},[I,o]),U.useEffect(()=>{if(!o||!d.current)return;const p=zC(d.current);return d.current.contains(p.activeElement)||(d.current.hasAttribute("tabIndex")||d.current.setAttribute("tabIndex","-1"),u.current&&d.current.focus()),()=>{n||(l.current&&l.current.focus&&(a.current=!0,l.current.focus()),l.current=null)}},[o]),U.useEffect(()=>{if(!o||!d.current)return;const p=zC(d.current),y=G=>{m.current=G,!(i||!r()||G.key!=="Tab")&&p.activeElement===d.current&&G.shiftKey&&(a.current=!0,A.current&&A.current.focus())},Z=()=>{const G=d.current;if(G===null)return;if(!p.hasFocus()||!r()||a.current){a.current=!1;return}if(G.contains(p.activeElement)||i&&p.activeElement!==s.current&&p.activeElement!==A.current)return;if(p.activeElement!==c.current)c.current=null;else if(c.current!==null)return;if(!u.current)return;let v=[];if((p.activeElement===s.current||p.activeElement===A.current)&&(v=C(d.current)),v.length>0){var w,V;const S=!!((w=m.current)!=null&&w.shiftKey&&((V=m.current)==null?void 0:V.key)==="Tab"),X=v[0],W=v[v.length-1];typeof X!="string"&&typeof W!="string"&&(S?W.focus():X.focus())}else G.focus()};p.addEventListener("focusin",Z),p.addEventListener("keydown",y,!0);const B=setInterval(()=>{p.activeElement&&p.activeElement.tagName==="BODY"&&Z()},50);return()=>{clearInterval(B),p.removeEventListener("focusin",Z),p.removeEventListener("keydown",y,!0)}},[I,i,n,r,o,C]);const f=p=>{l.current===null&&(l.current=p.relatedTarget),u.current=!0,c.current=p.target;const y=g.props.onFocus;y&&y(p)},b=p=>{l.current===null&&(l.current=p.relatedTarget),u.current=!0};return Oe.jsxs(U.Fragment,{children:[Oe.jsx("div",{tabIndex:o?0:-1,onFocus:b,ref:s,"data-testid":"sentinelStart"}),U.cloneElement(g,{ref:h,onFocus:f}),Oe.jsx("div",{tabIndex:o?0:-1,onFocus:b,ref:A,"data-testid":"sentinelEnd"})]})}function ahg(e){return typeof e=="function"?e():e}const Ahg=U.forwardRef(function(g,I){const{children:i,container:n,disablePortal:C=!1}=g,[r,o]=U.useState(null),a=pn(U.isValidElement(i)?i.ref:null,I);if(Ls(()=>{C||o(ahg(n)||document.body)},[n,C]),Ls(()=>{if(r&&!C)return FH(I,r),()=>{FH(I,null)}},[I,r,C]),C){if(U.isValidElement(i)){const s={ref:a};return U.cloneElement(i,s)}return Oe.jsx(U.Fragment,{children:i})}return Oe.jsx(U.Fragment,{children:r&&Aa.createPortal(i,r)})});function shg(e){const g=zC(e);return g.body===e?Qc(e).innerWidth>g.documentElement.clientWidth:e.scrollHeight>e.clientHeight}function xv(e,g){g?e.setAttribute("aria-hidden","true"):e.removeAttribute("aria-hidden")}function Sue(e){return parseInt(Qc(e).getComputedStyle(e).paddingRight,10)||0}function lhg(e){const I=["TEMPLATE","SCRIPT","STYLE","LINK","MAP","META","NOSCRIPT","PICTURE","COL","COLGROUP","PARAM","SLOT","SOURCE","TRACK"].indexOf(e.tagName)!==-1,i=e.tagName==="INPUT"&&e.getAttribute("type")==="hidden";return I||i}function wue(e,g,I,i,n){const C=[g,I,...i];[].forEach.call(e.children,r=>{const o=C.indexOf(r)===-1,a=!lhg(r);o&&a&&xv(r,n)})}function eE(e,g){let I=-1;return e.some((i,n)=>g(i)?(I=n,!0):!1),I}function chg(e,g){const I=[],i=e.container;if(!g.disableScrollLock){if(shg(i)){const r=aNe(zC(i));I.push({value:i.style.paddingRight,property:"padding-right",el:i}),i.style.paddingRight=`${Sue(i)+r}px`;const o=zC(i).querySelectorAll(".mui-fixed");[].forEach.call(o,a=>{I.push({value:a.style.paddingRight,property:"padding-right",el:a}),a.style.paddingRight=`${Sue(a)+r}px`})}let C;if(i.parentNode instanceof DocumentFragment)C=zC(i).body;else{const r=i.parentElement,o=Qc(i);C=(r==null?void 0:r.nodeName)==="HTML"&&o.getComputedStyle(r).overflowY==="scroll"?r:i}I.push({value:C.style.overflow,property:"overflow",el:C},{value:C.style.overflowX,property:"overflow-x",el:C},{value:C.style.overflowY,property:"overflow-y",el:C}),C.style.overflow="hidden"}return()=>{I.forEach(({value:C,el:r,property:o})=>{C?r.style.setProperty(o,C):r.style.removeProperty(o)})}}function uhg(e){const g=[];return[].forEach.call(e.children,I=>{I.getAttribute("aria-hidden")==="true"&&g.push(I)}),g}class dhg{constructor(){this.containers=void 0,this.modals=void 0,this.modals=[],this.containers=[]}add(g,I){let i=this.modals.indexOf(g);if(i!==-1)return i;i=this.modals.length,this.modals.push(g),g.modalRef&&xv(g.modalRef,!1);const n=uhg(I);wue(I,g.mount,g.modalRef,n,!0);const C=eE(this.containers,r=>r.container===I);return C!==-1?(this.containers[C].modals.push(g),i):(this.containers.push({modals:[g],container:I,restore:null,hiddenSiblings:n}),i)}mount(g,I){const i=eE(this.containers,C=>C.modals.indexOf(g)!==-1),n=this.containers[i];n.restore||(n.restore=chg(n,I))}remove(g,I=!0){const i=this.modals.indexOf(g);if(i===-1)return i;const n=eE(this.containers,r=>r.modals.indexOf(g)!==-1),C=this.containers[n];if(C.modals.splice(C.modals.indexOf(g),1),this.modals.splice(i,1),C.modals.length===0)C.restore&&C.restore(),g.modalRef&&xv(g.modalRef,I),wue(C.container,g.mount,g.modalRef,C.hiddenSiblings,!1),this.containers.splice(n,1);else{const r=C.modals[C.modals.length-1];r.modalRef&&xv(r.modalRef,!1)}return i}isTopModal(g){return this.modals.length>0&&this.modals[this.modals.length-1]===g}}function hhg(e){return typeof e=="function"?e():e}function mhg(e){return e?e.props.hasOwnProperty("in"):!1}const fhg=new dhg;function phg(e){const{container:g,disableEscapeKeyDown:I=!1,disableScrollLock:i=!1,manager:n=fhg,closeAfterTransition:C=!1,onTransitionEnter:r,onTransitionExited:o,children:a,onClose:s,open:A,rootRef:l}=e,c=U.useRef({}),u=U.useRef(null),d=U.useRef(null),h=pn(d,l),[m,f]=U.useState(!A),b=mhg(a);let p=!0;(e["aria-hidden"]==="false"||e["aria-hidden"]===!1)&&(p=!1);const y=()=>zC(u.current),Z=()=>(c.current.modalRef=d.current,c.current.mount=u.current,c.current),B=()=>{n.mount(Z(),{disableScrollLock:i}),d.current&&(d.current.scrollTop=0)},G=Zd(()=>{const Y=hhg(g)||y().body;n.add(Z(),Y),d.current&&B()}),v=U.useCallback(()=>n.isTopModal(Z()),[n]),w=Zd(Y=>{u.current=Y,Y&&(A&&v()?B():d.current&&xv(d.current,p))}),V=U.useCallback(()=>{n.remove(Z(),p)},[p,n]);U.useEffect(()=>()=>{V()},[V]),U.useEffect(()=>{A?G():(!b||!C)&&V()},[A,V,b,C,G]);const S=Y=>K=>{var F;(F=Y.onKeyDown)==null||F.call(Y,K),!(K.key!=="Escape"||K.which===229||!v())&&(I||(K.stopPropagation(),s&&s(K,"escapeKeyDown")))},X=Y=>K=>{var F;(F=Y.onClick)==null||F.call(Y,K),K.target===K.currentTarget&&s&&s(K,"backdropClick")};return{getRootProps:(Y={})=>{const K=rke(e);delete K.onTransitionEnter,delete K.onTransitionExited;const F=Ke({},K,Y);return Ke({role:"presentation"},F,{onKeyDown:S(F),ref:h})},getBackdropProps:(Y={})=>{const K=Y;return Ke({"aria-hidden":!0},K,{onClick:X(K),open:A})},getTransitionProps:()=>{const Y=()=>{f(!1),r&&r()},K=()=>{f(!0),o&&o(),C&&V()};return{onEnter:W_(Y,a==null?void 0:a.props.onEnter),onExited:W_(K,a==null?void 0:a.props.onExited)}},rootRef:h,portalRef:w,isTopModal:v,exited:m,hasTransition:b}}const bhg=["onChange","maxRows","minRows","style","value"];function l1(e){return parseInt(e,10)||0}const yhg={shadow:{visibility:"hidden",position:"absolute",overflow:"hidden",height:0,top:0,left:0,transform:"translateZ(0)"}};function Vue(e){return e==null||Object.keys(e).length===0||e.outerHeightStyle===0&&!e.overflow}const Zhg=U.forwardRef(function(g,I){const{onChange:i,maxRows:n,minRows:C=1,style:r,value:o}=g,a=Qt(g,bhg),{current:s}=U.useRef(o!=null),A=U.useRef(null),l=pn(I,A),c=U.useRef(null),u=U.useRef(0),[d,h]=U.useState({outerHeightStyle:0}),m=U.useCallback(()=>{const y=A.current,B=Qc(y).getComputedStyle(y);if(B.width==="0px")return{outerHeightStyle:0};const G=c.current;G.style.width=B.width,G.value=y.value||g.placeholder||"x",G.value.slice(-1)===` -`&&(G.value+=" ");const v=B.boxSizing,w=l1(B.paddingBottom)+l1(B.paddingTop),V=l1(B.borderBottomWidth)+l1(B.borderTopWidth),S=G.scrollHeight;G.value="x";const X=G.scrollHeight;let W=S;C&&(W=Math.max(Number(C)*X,W)),n&&(W=Math.min(Number(n)*X,W)),W=Math.max(W,X);const R=W+(v==="border-box"?w+V:0),H=Math.abs(W-S)<=1;return{outerHeightStyle:R,overflow:H}},[n,C,g.placeholder]),f=(y,Z)=>{const{outerHeightStyle:B,overflow:G}=Z;return u.current<20&&(B>0&&Math.abs((y.outerHeightStyle||0)-B)>1||y.overflow!==G)?(u.current+=1,{overflow:G,outerHeightStyle:B}):y},b=U.useCallback(()=>{const y=m();Vue(y)||h(Z=>f(Z,y))},[m]);Ls(()=>{const y=()=>{const S=m();Vue(S)||Aa.flushSync(()=>{h(X=>f(X,S))})},Z=()=>{u.current=0,y()};let B;const G=h8(Z),v=A.current,w=Qc(v);w.addEventListener("resize",G);let V;return typeof ResizeObserver<"u"&&(V=new ResizeObserver(Z),V.observe(v)),()=>{G.clear(),cancelAnimationFrame(B),w.removeEventListener("resize",G),V&&V.disconnect()}},[m]),Ls(()=>{b()}),U.useEffect(()=>{u.current=0},[o]);const p=y=>{u.current=0,s||b(),i&&i(y)};return Oe.jsxs(U.Fragment,{children:[Oe.jsx("textarea",Ke({value:o,onChange:p,ref:l,rows:C,style:Ke({height:d.outerHeightStyle,overflow:d.overflow?"hidden":void 0},r)},a)),Oe.jsx("textarea",{"aria-hidden":!0,className:g.className,readOnly:!0,ref:c,tabIndex:-1,style:Ke({},yhg.shadow,r,{paddingTop:0,paddingBottom:0})})]})}),Ghg=["addEndListener","appear","children","easing","in","onEnter","onEntered","onEntering","onExit","onExited","onExiting","style","timeout","TransitionComponent"];function M_(e){return`scale(${e}, ${e**2})`}const vhg={entering:{opacity:1,transform:M_(1)},entered:{opacity:1,transform:"none"}},tE=typeof navigator<"u"&&/^((?!chrome|android).)*(safari|mobile)/i.test(navigator.userAgent)&&/(os |version\/)15(.|_)4/i.test(navigator.userAgent),ake=U.forwardRef(function(g,I){const{addEndListener:i,appear:n=!0,children:C,easing:r,in:o,onEnter:a,onEntered:s,onEntering:A,onExit:l,onExited:c,onExiting:u,style:d,timeout:h="auto",TransitionComponent:m=D8}=g,f=Qt(g,Ghg),b=U.useRef(),p=U.useRef(),y=fy(),Z=U.useRef(null),B=pn(Z,C.ref,I),G=H=>Y=>{if(H){const K=Z.current;Y===void 0?H(K):H(K,Y)}},v=G(A),w=G((H,Y)=>{ONe(H);const{duration:K,delay:F,easing:J}=f0({style:d,timeout:h,easing:r},{mode:"enter"});let P;h==="auto"?(P=y.transitions.getAutoHeightDuration(H.clientHeight),p.current=P):P=K,H.style.transition=[y.transitions.create("opacity",{duration:P,delay:F}),y.transitions.create("transform",{duration:tE?P:P*.666,delay:F,easing:J})].join(","),a&&a(H,Y)}),V=G(s),S=G(u),X=G(H=>{const{duration:Y,delay:K,easing:F}=f0({style:d,timeout:h,easing:r},{mode:"exit"});let J;h==="auto"?(J=y.transitions.getAutoHeightDuration(H.clientHeight),p.current=J):J=Y,H.style.transition=[y.transitions.create("opacity",{duration:J,delay:K}),y.transitions.create("transform",{duration:tE?J:J*.666,delay:tE?K:K||J*.333,easing:F})].join(","),H.style.opacity=0,H.style.transform=M_(.75),l&&l(H)}),W=G(c),R=H=>{h==="auto"&&(b.current=setTimeout(H,p.current||0)),i&&i(Z.current,H)};return U.useEffect(()=>()=>{clearTimeout(b.current)},[]),Oe.jsx(m,Ke({appear:n,in:o,nodeRef:Z,onEnter:w,onEntered:V,onEntering:v,onExit:X,onExited:W,onExiting:S,addEndListener:R,timeout:h==="auto"?null:h},f,{children:(H,Y)=>U.cloneElement(C,Ke({style:Ke({opacity:0,transform:M_(.75),visibility:H==="exited"&&!o?"hidden":void 0},vhg[H],d,C.props.style),ref:B},Y))}))});ake.muiSupportAuto=!0;const Bhg=ake,Shg=["addEndListener","appear","children","easing","in","onEnter","onEntered","onEntering","onExit","onExited","onExiting","style","timeout","TransitionComponent"],whg={entering:{opacity:1},entered:{opacity:1}},Vhg=U.forwardRef(function(g,I){const i=fy(),n={enter:i.transitions.duration.enteringScreen,exit:i.transitions.duration.leavingScreen},{addEndListener:C,appear:r=!0,children:o,easing:a,in:s,onEnter:A,onEntered:l,onEntering:c,onExit:u,onExited:d,onExiting:h,style:m,timeout:f=n,TransitionComponent:b=D8}=g,p=Qt(g,Shg),y=U.useRef(null),Z=pn(y,o.ref,I),B=R=>H=>{if(R){const Y=y.current;H===void 0?R(Y):R(Y,H)}},G=B(c),v=B((R,H)=>{ONe(R);const Y=f0({style:m,timeout:f,easing:a},{mode:"enter"});R.style.webkitTransition=i.transitions.create("opacity",Y),R.style.transition=i.transitions.create("opacity",Y),A&&A(R,H)}),w=B(l),V=B(h),S=B(R=>{const H=f0({style:m,timeout:f,easing:a},{mode:"exit"});R.style.webkitTransition=i.transitions.create("opacity",H),R.style.transition=i.transitions.create("opacity",H),u&&u(R)}),X=B(d),W=R=>{C&&C(y.current,R)};return Oe.jsx(b,Ke({appear:r,in:s,nodeRef:y,onEnter:v,onEntered:w,onEntering:G,onExit:S,onExited:X,onExiting:V,addEndListener:W,timeout:f},p,{children:(R,H)=>U.cloneElement(o,Ke({style:Ke({opacity:0,visibility:R==="exited"&&!s?"hidden":void 0},whg[R],m,o.props.style),ref:Z},H))}))}),Rhg=Vhg;function Whg(e){return li("MuiBackdrop",e)}HI("MuiBackdrop",["root","invisible"]);const Xhg=["children","className","component","components","componentsProps","invisible","open","slotProps","slots","TransitionComponent","transitionDuration"],Hhg=e=>{const{classes:g,invisible:I}=e;return vi({root:["root",I&&"invisible"]},Whg,g)},Thg=qt("div",{name:"MuiBackdrop",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[g.root,I.invisible&&g.invisible]}})(({ownerState:e})=>Ke({position:"fixed",display:"flex",alignItems:"center",justifyContent:"center",right:0,bottom:0,top:0,left:0,backgroundColor:"rgba(0, 0, 0, 0.5)",WebkitTapHighlightColor:"transparent"},e.invisible&&{backgroundColor:"transparent"})),Nhg=U.forwardRef(function(g,I){var i,n,C;const r=gi({props:g,name:"MuiBackdrop"}),{children:o,className:a,component:s="div",components:A={},componentsProps:l={},invisible:c=!1,open:u,slotProps:d={},slots:h={},TransitionComponent:m=Rhg,transitionDuration:f}=r,b=Qt(r,Xhg),p=Ke({},r,{component:s,invisible:c}),y=Hhg(p),Z=(i=d.root)!=null?i:l.root;return Oe.jsx(m,Ke({in:u,timeout:f},b,{children:Oe.jsx(Thg,Ke({"aria-hidden":!0},Z,{as:(n=(C=h.root)!=null?C:A.Root)!=null?n:s,className:ug(y.root,a,Z==null?void 0:Z.className),ownerState:Ke({},p,Z==null?void 0:Z.ownerState),classes:y,ref:I,children:o}))}))}),khg=Nhg;function Yhg(e){return li("MuiModal",e)}HI("MuiModal",["root","hidden","backdrop"]);const Khg=["BackdropComponent","BackdropProps","classes","className","closeAfterTransition","children","container","component","components","componentsProps","disableAutoFocus","disableEnforceFocus","disableEscapeKeyDown","disablePortal","disableRestoreFocus","disableScrollLock","hideBackdrop","keepMounted","onBackdropClick","onClose","onTransitionEnter","onTransitionExited","open","slotProps","slots","theme"],xhg=e=>{const{open:g,exited:I,classes:i}=e;return vi({root:["root",!g&&I&&"hidden"],backdrop:["backdrop"]},Yhg,i)},Dhg=qt("div",{name:"MuiModal",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[g.root,!I.open&&I.exited&&g.hidden]}})(({theme:e,ownerState:g})=>Ke({position:"fixed",zIndex:(e.vars||e).zIndex.modal,right:0,bottom:0,top:0,left:0},!g.open&&g.exited&&{visibility:"hidden"})),Fhg=qt(khg,{name:"MuiModal",slot:"Backdrop",overridesResolver:(e,g)=>g.backdrop})({zIndex:-1}),Ehg=U.forwardRef(function(g,I){var i,n,C,r,o,a;const s=gi({name:"MuiModal",props:g}),{BackdropComponent:A=Fhg,BackdropProps:l,className:c,closeAfterTransition:u=!1,children:d,container:h,component:m,components:f={},componentsProps:b={},disableAutoFocus:p=!1,disableEnforceFocus:y=!1,disableEscapeKeyDown:Z=!1,disablePortal:B=!1,disableRestoreFocus:G=!1,disableScrollLock:v=!1,hideBackdrop:w=!1,keepMounted:V=!1,onBackdropClick:S,open:X,slotProps:W,slots:R}=s,H=Qt(s,Khg),Y=Ke({},s,{closeAfterTransition:u,disableAutoFocus:p,disableEnforceFocus:y,disableEscapeKeyDown:Z,disablePortal:B,disableRestoreFocus:G,disableScrollLock:v,hideBackdrop:w,keepMounted:V}),{getRootProps:K,getBackdropProps:F,getTransitionProps:J,portalRef:P,isTopModal:ge,exited:q,hasTransition:$}=phg(Ke({},Y,{rootRef:I})),j=Ke({},Y,{exited:q}),te=xhg(j),Q={};if(d.props.tabIndex===void 0&&(Q.tabIndex="-1"),$){const{onEnter:We,onExited:Be}=J();Q.onEnter=We,Q.onExited=Be}const ie=(i=(n=R==null?void 0:R.root)!=null?n:f.Root)!=null?i:Dhg,he=(C=(r=R==null?void 0:R.backdrop)!=null?r:f.Backdrop)!=null?C:A,ne=(o=W==null?void 0:W.root)!=null?o:b.root,be=(a=W==null?void 0:W.backdrop)!=null?a:b.backdrop,pe=p0({elementType:ie,externalSlotProps:ne,externalForwardedProps:H,getSlotProps:K,additionalProps:{ref:I,as:m},ownerState:j,className:ug(c,ne==null?void 0:ne.className,te==null?void 0:te.root,!j.open&&j.exited&&(te==null?void 0:te.hidden))}),ve=p0({elementType:he,externalSlotProps:be,additionalProps:l,getSlotProps:We=>F(Ke({},We,{onClick:Be=>{S&&S(Be),We!=null&&We.onClick&&We.onClick(Be)}})),className:ug(be==null?void 0:be.className,l==null?void 0:l.className,te==null?void 0:te.backdrop),ownerState:j});return!V&&!X&&(!$||q)?null:Oe.jsx(Ahg,{ref:P,container:h,disablePortal:B,children:Oe.jsxs(ie,Ke({},pe,{children:[!w&&A?Oe.jsx(he,Ke({},ve)):null,Oe.jsx(ohg,{disableEnforceFocus:y,disableAutoFocus:p,disableRestoreFocus:G,isEnabled:ge,open:X,children:U.cloneElement(d,Q)})]}))})}),Mhg=Ehg;function zhg(e){return li("MuiPaper",e)}HI("MuiPaper",["root","rounded","outlined","elevation","elevation0","elevation1","elevation2","elevation3","elevation4","elevation5","elevation6","elevation7","elevation8","elevation9","elevation10","elevation11","elevation12","elevation13","elevation14","elevation15","elevation16","elevation17","elevation18","elevation19","elevation20","elevation21","elevation22","elevation23","elevation24"]);const Phg=["className","component","elevation","square","variant"],Jhg=e=>{const{square:g,elevation:I,variant:i,classes:n}=e,C={root:["root",i,!g&&"rounded",i==="elevation"&&`elevation${I}`]};return vi(C,zhg,n)},Ohg=qt("div",{name:"MuiPaper",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[g.root,g[I.variant],!I.square&&g.rounded,I.variant==="elevation"&&g[`elevation${I.elevation}`]]}})(({theme:e,ownerState:g})=>{var I;return Ke({backgroundColor:(e.vars||e).palette.background.paper,color:(e.vars||e).palette.text.primary,transition:e.transitions.create("box-shadow")},!g.square&&{borderRadius:e.shape.borderRadius},g.variant==="outlined"&&{border:`1px solid ${(e.vars||e).palette.divider}`},g.variant==="elevation"&&Ke({boxShadow:(e.vars||e).shadows[g.elevation]},!e.vars&&e.palette.mode==="dark"&&{backgroundImage:`linear-gradient(${rA("#fff",oue(g.elevation))}, ${rA("#fff",oue(g.elevation))})`},e.vars&&{backgroundImage:(I=e.vars.overlays)==null?void 0:I[g.elevation]}))}),_hg=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiPaper"}),{className:n,component:C="div",elevation:r=1,square:o=!1,variant:a="elevation"}=i,s=Qt(i,Phg),A=Ke({},i,{component:C,elevation:r,square:o,variant:a}),l=Jhg(A);return Oe.jsx(Ohg,Ke({as:C,ownerState:A,className:ug(l.root,n),ref:I},s))}),Lhg=_hg;function Uhg(e){return li("MuiPopover",e)}HI("MuiPopover",["root","paper"]);const Qhg=["onEntering"],jhg=["action","anchorEl","anchorOrigin","anchorPosition","anchorReference","children","className","container","elevation","marginThreshold","open","PaperProps","slots","slotProps","transformOrigin","TransitionComponent","transitionDuration","TransitionProps","disableScrollLock"],$hg=["slotProps"];function Rue(e,g){let I=0;return typeof g=="number"?I=g:g==="center"?I=e.height/2:g==="bottom"&&(I=e.height),I}function Wue(e,g){let I=0;return typeof g=="number"?I=g:g==="center"?I=e.width/2:g==="right"&&(I=e.width),I}function Xue(e){return[e.horizontal,e.vertical].map(g=>typeof g=="number"?`${g}px`:g).join(" ")}function gE(e){return typeof e=="function"?e():e}const qhg=e=>{const{classes:g}=e;return vi({root:["root"],paper:["paper"]},Uhg,g)},emg=qt(Mhg,{name:"MuiPopover",slot:"Root",overridesResolver:(e,g)=>g.root})({}),Ake=qt(Lhg,{name:"MuiPopover",slot:"Paper",overridesResolver:(e,g)=>g.paper})({position:"absolute",overflowY:"auto",overflowX:"hidden",minWidth:16,minHeight:16,maxWidth:"calc(100% - 32px)",maxHeight:"calc(100% - 32px)",outline:0}),tmg=U.forwardRef(function(g,I){var i,n,C;const r=gi({props:g,name:"MuiPopover"}),{action:o,anchorEl:a,anchorOrigin:s={vertical:"top",horizontal:"left"},anchorPosition:A,anchorReference:l="anchorEl",children:c,className:u,container:d,elevation:h=8,marginThreshold:m=16,open:f,PaperProps:b={},slots:p,slotProps:y,transformOrigin:Z={vertical:"top",horizontal:"left"},TransitionComponent:B=Bhg,transitionDuration:G="auto",TransitionProps:{onEntering:v}={},disableScrollLock:w=!1}=r,V=Qt(r.TransitionProps,Qhg),S=Qt(r,jhg),X=(i=y==null?void 0:y.paper)!=null?i:b,W=U.useRef(),R=pn(W,X.ref),H=Ke({},r,{anchorOrigin:s,anchorReference:l,elevation:h,marginThreshold:m,externalPaperSlotProps:X,transformOrigin:Z,TransitionComponent:B,transitionDuration:G,TransitionProps:V}),Y=qhg(H),K=U.useCallback(()=>{if(l==="anchorPosition")return A;const We=gE(a),Je=(We&&We.nodeType===1?We:zC(W.current).body).getBoundingClientRect();return{top:Je.top+Rue(Je,s.vertical),left:Je.left+Wue(Je,s.horizontal)}},[a,s.horizontal,s.vertical,A,l]),F=U.useCallback(We=>({vertical:Rue(We,Z.vertical),horizontal:Wue(We,Z.horizontal)}),[Z.horizontal,Z.vertical]),J=U.useCallback(We=>{const Be={width:We.offsetWidth,height:We.offsetHeight},Je=F(Be);if(l==="none")return{top:null,left:null,transformOrigin:Xue(Je)};const Pe=K();let De=Pe.top-Je.vertical,Qe=Pe.left-Je.horizontal;const _e=De+Be.height,gt=Qe+Be.width,lt=Qc(gE(a)),tt=lt.innerHeight-m,Xe=lt.innerWidth-m;if(m!==null&&Dett){const ae=_e-tt;De-=ae,Je.vertical+=ae}if(m!==null&&QeXe){const ae=gt-Xe;Qe-=ae,Je.horizontal+=ae}return{top:`${Math.round(De)}px`,left:`${Math.round(Qe)}px`,transformOrigin:Xue(Je)}},[a,l,K,F,m]),[P,ge]=U.useState(f),q=U.useCallback(()=>{const We=W.current;if(!We)return;const Be=J(We);Be.top!==null&&(We.style.top=Be.top),Be.left!==null&&(We.style.left=Be.left),We.style.transformOrigin=Be.transformOrigin,ge(!0)},[J]);U.useEffect(()=>(w&&window.addEventListener("scroll",q),()=>window.removeEventListener("scroll",q)),[a,w,q]);const $=(We,Be)=>{v&&v(We,Be),q()},j=()=>{ge(!1)};U.useEffect(()=>{f&&q()}),U.useImperativeHandle(o,()=>f?{updatePosition:()=>{q()}}:null,[f,q]),U.useEffect(()=>{if(!f)return;const We=h8(()=>{q()}),Be=Qc(a);return Be.addEventListener("resize",We),()=>{We.clear(),Be.removeEventListener("resize",We)}},[a,f,q]);let te=G;G==="auto"&&!B.muiSupportAuto&&(te=void 0);const Q=d||(a?zC(gE(a)).body:void 0),ie=(n=p==null?void 0:p.root)!=null?n:emg,he=(C=p==null?void 0:p.paper)!=null?C:Ake,ne=p0({elementType:he,externalSlotProps:Ke({},X,{style:P?X.style:Ke({},X.style,{opacity:0})}),additionalProps:{elevation:h,ref:R},ownerState:H,className:ug(Y.paper,X==null?void 0:X.className)}),be=p0({elementType:ie,externalSlotProps:(y==null?void 0:y.root)||{},externalForwardedProps:S,additionalProps:{ref:I,slotProps:{backdrop:{invisible:!0}},container:Q,open:f},ownerState:H,className:ug(Y.root,u)}),{slotProps:pe}=be,ve=Qt(be,$hg);return Oe.jsx(ie,Ke({},ve,!_H(ie)&&{slotProps:pe,disableScrollLock:w},{children:Oe.jsx(B,Ke({appear:!0,in:f,onEntering:$,onExited:j,timeout:te},V,{children:Oe.jsx(he,Ke({},ne,{children:c}))}))}))}),gmg=tmg;function Img(e){return li("MuiMenu",e)}HI("MuiMenu",["root","paper","list"]);const img=["onEntering"],nmg=["autoFocus","children","className","disableAutoFocusItem","MenuListProps","onClose","open","PaperProps","PopoverClasses","transitionDuration","TransitionProps","variant","slots","slotProps"],Cmg={vertical:"top",horizontal:"right"},rmg={vertical:"top",horizontal:"left"},omg=e=>{const{classes:g}=e;return vi({root:["root"],paper:["paper"],list:["list"]},Img,g)},amg=qt(gmg,{shouldForwardProp:e=>va(e)||e==="classes",name:"MuiMenu",slot:"Root",overridesResolver:(e,g)=>g.root})({}),Amg=qt(Ake,{name:"MuiMenu",slot:"Paper",overridesResolver:(e,g)=>g.paper})({maxHeight:"calc(100% - 96px)",WebkitOverflowScrolling:"touch"}),smg=qt(thg,{name:"MuiMenu",slot:"List",overridesResolver:(e,g)=>g.list})({outline:0}),lmg=U.forwardRef(function(g,I){var i,n;const C=gi({props:g,name:"MuiMenu"}),{autoFocus:r=!0,children:o,className:a,disableAutoFocusItem:s=!1,MenuListProps:A={},onClose:l,open:c,PaperProps:u={},PopoverClasses:d,transitionDuration:h="auto",TransitionProps:{onEntering:m}={},variant:f="selectedMenu",slots:b={},slotProps:p={}}=C,y=Qt(C.TransitionProps,img),Z=Qt(C,nmg),B=fy(),G=B.direction==="rtl",v=Ke({},C,{autoFocus:r,disableAutoFocusItem:s,MenuListProps:A,onEntering:m,PaperProps:u,transitionDuration:h,TransitionProps:y,variant:f}),w=omg(v),V=r&&!s&&c,S=U.useRef(null),X=(J,P)=>{S.current&&S.current.adjustStyleForScrollbar(J,B),m&&m(J,P)},W=J=>{J.key==="Tab"&&(J.preventDefault(),l&&l(J,"tabKeyDown"))};let R=-1;U.Children.map(o,(J,P)=>{U.isValidElement(J)&&(J.props.disabled||(f==="selectedMenu"&&J.props.selected||R===-1)&&(R=P))});const H=(i=b.paper)!=null?i:Amg,Y=(n=p.paper)!=null?n:u,K=p0({elementType:b.root,externalSlotProps:p.root,ownerState:v,className:[w.root,a]}),F=p0({elementType:H,externalSlotProps:Y,ownerState:v,className:w.paper});return Oe.jsx(amg,Ke({onClose:l,anchorOrigin:{vertical:"bottom",horizontal:G?"right":"left"},transformOrigin:G?Cmg:rmg,slots:{paper:H,root:b.root},slotProps:{root:K,paper:F},open:c,ref:I,transitionDuration:h,TransitionProps:Ke({onEntering:X},y),ownerState:v},Z,{classes:d,children:Oe.jsx(smg,Ke({onKeyDown:W,actions:S,autoFocus:r&&(R===-1||s),autoFocusItem:V,variant:f},A,{className:ug(w.list,A.className),children:o}))}))}),cmg=lmg;function umg(e){return li("MuiNativeSelect",e)}const dmg=HI("MuiNativeSelect",["root","select","multiple","filled","outlined","standard","disabled","icon","iconOpen","iconFilled","iconOutlined","iconStandard","nativeInput","error"]),L8=dmg,hmg=["className","disabled","error","IconComponent","inputRef","variant"],mmg=e=>{const{classes:g,variant:I,disabled:i,multiple:n,open:C,error:r}=e,o={select:["select",I,i&&"disabled",n&&"multiple",r&&"error"],icon:["icon",`icon${si(I)}`,C&&"iconOpen",i&&"disabled"]};return vi(o,umg,g)},ske=({ownerState:e,theme:g})=>Ke({MozAppearance:"none",WebkitAppearance:"none",userSelect:"none",borderRadius:0,cursor:"pointer","&:focus":Ke({},g.vars?{backgroundColor:`rgba(${g.vars.palette.common.onBackgroundChannel} / 0.05)`}:{backgroundColor:g.palette.mode==="light"?"rgba(0, 0, 0, 0.05)":"rgba(255, 255, 255, 0.05)"},{borderRadius:0}),"&::-ms-expand":{display:"none"},[`&.${L8.disabled}`]:{cursor:"default"},"&[multiple]":{height:"auto"},"&:not([multiple]) option, &:not([multiple]) optgroup":{backgroundColor:(g.vars||g).palette.background.paper},"&&&":{paddingRight:24,minWidth:16}},e.variant==="filled"&&{"&&&":{paddingRight:32}},e.variant==="outlined"&&{borderRadius:(g.vars||g).shape.borderRadius,"&:focus":{borderRadius:(g.vars||g).shape.borderRadius},"&&&":{paddingRight:32}}),fmg=qt("select",{name:"MuiNativeSelect",slot:"Select",shouldForwardProp:va,overridesResolver:(e,g)=>{const{ownerState:I}=e;return[g.select,g[I.variant],I.error&&g.error,{[`&.${L8.multiple}`]:g.multiple}]}})(ske),lke=({ownerState:e,theme:g})=>Ke({position:"absolute",right:0,top:"calc(50% - .5em)",pointerEvents:"none",color:(g.vars||g).palette.action.active,[`&.${L8.disabled}`]:{color:(g.vars||g).palette.action.disabled}},e.open&&{transform:"rotate(180deg)"},e.variant==="filled"&&{right:7},e.variant==="outlined"&&{right:7}),pmg=qt("svg",{name:"MuiNativeSelect",slot:"Icon",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[g.icon,I.variant&&g[`icon${si(I.variant)}`],I.open&&g.iconOpen]}})(lke),bmg=U.forwardRef(function(g,I){const{className:i,disabled:n,error:C,IconComponent:r,inputRef:o,variant:a="standard"}=g,s=Qt(g,hmg),A=Ke({},g,{disabled:n,variant:a,error:C}),l=mmg(A);return Oe.jsxs(U.Fragment,{children:[Oe.jsx(fmg,Ke({ownerState:A,className:ug(l.select,i),disabled:n,ref:o||I},s)),g.multiple?null:Oe.jsx(pmg,{as:r,ownerState:A,className:l.icon})]})}),ymg=bmg;function Zmg(e){return li("MuiSelect",e)}const Gmg=HI("MuiSelect",["root","select","multiple","filled","outlined","standard","disabled","focused","icon","iconOpen","iconFilled","iconOutlined","iconStandard","nativeInput","error"]),VZ=Gmg;var Hue;const vmg=["aria-describedby","aria-label","autoFocus","autoWidth","children","className","defaultOpen","defaultValue","disabled","displayEmpty","error","IconComponent","inputRef","labelId","MenuProps","multiple","name","onBlur","onChange","onClose","onFocus","onOpen","open","readOnly","renderValue","SelectDisplayProps","tabIndex","type","value","variant"],Bmg=qt("div",{name:"MuiSelect",slot:"Select",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[{[`&.${VZ.select}`]:g.select},{[`&.${VZ.select}`]:g[I.variant]},{[`&.${VZ.error}`]:g.error},{[`&.${VZ.multiple}`]:g.multiple}]}})(ske,{[`&.${VZ.select}`]:{height:"auto",minHeight:"1.4375em",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}}),Smg=qt("svg",{name:"MuiSelect",slot:"Icon",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[g.icon,I.variant&&g[`icon${si(I.variant)}`],I.open&&g.iconOpen]}})(lke),wmg=qt("input",{shouldForwardProp:e=>Acg(e)&&e!=="classes",name:"MuiSelect",slot:"NativeInput",overridesResolver:(e,g)=>g.nativeInput})({bottom:0,left:0,position:"absolute",opacity:0,pointerEvents:"none",width:"100%",boxSizing:"border-box"});function Tue(e,g){return typeof g=="object"&&g!==null?e===g:String(e)===String(g)}function Vmg(e){return e==null||typeof e=="string"&&!e.trim()}const Rmg=e=>{const{classes:g,variant:I,disabled:i,multiple:n,open:C,error:r}=e,o={select:["select",I,i&&"disabled",n&&"multiple",r&&"error"],icon:["icon",`icon${si(I)}`,C&&"iconOpen",i&&"disabled"],nativeInput:["nativeInput"]};return vi(o,Zmg,g)},Wmg=U.forwardRef(function(g,I){var i;const{"aria-describedby":n,"aria-label":C,autoFocus:r,autoWidth:o,children:a,className:s,defaultOpen:A,defaultValue:l,disabled:c,displayEmpty:u,error:d=!1,IconComponent:h,inputRef:m,labelId:f,MenuProps:b={},multiple:p,name:y,onBlur:Z,onChange:B,onClose:G,onFocus:v,onOpen:w,open:V,readOnly:S,renderValue:X,SelectDisplayProps:W={},tabIndex:R,value:H,variant:Y="standard"}=g,K=Qt(g,vmg),[F,J]=X_({controlled:H,default:l,name:"Select"}),[P,ge]=X_({controlled:V,default:A,name:"Select"}),q=U.useRef(null),$=U.useRef(null),[j,te]=U.useState(null),{current:Q}=U.useRef(V!=null),[ie,he]=U.useState(),ne=pn(I,m),be=U.useCallback(we=>{$.current=we,we&&te(we)},[]),pe=j==null?void 0:j.parentNode;U.useImperativeHandle(ne,()=>({focus:()=>{$.current.focus()},node:q.current,value:F}),[F]),U.useEffect(()=>{A&&P&&j&&!Q&&(he(o?null:pe.clientWidth),$.current.focus())},[j,o]),U.useEffect(()=>{r&&$.current.focus()},[r]),U.useEffect(()=>{if(!f)return;const we=zC($.current).getElementById(f);if(we){const je=()=>{getSelection().isCollapsed&&$.current.focus()};return we.addEventListener("click",je),()=>{we.removeEventListener("click",je)}}},[f]);const ve=(we,je)=>{we?w&&w(je):G&&G(je),Q||(he(o?null:pe.clientWidth),ge(we))},We=we=>{we.button===0&&(we.preventDefault(),$.current.focus(),ve(!0,we))},Be=we=>{ve(!1,we)},Je=U.Children.toArray(a),Pe=we=>{const je=Je.find(at=>at.props.value===we.target.value);je!==void 0&&(J(je.props.value),B&&B(we,je))},De=we=>je=>{let at;if(je.currentTarget.hasAttribute("tabindex")){if(p){at=Array.isArray(F)?F.slice():[];const bt=F.indexOf(we.props.value);bt===-1?at.push(we.props.value):at.splice(bt,1)}else at=we.props.value;if(we.props.onClick&&we.props.onClick(je),F!==at&&(J(at),B)){const bt=je.nativeEvent||je,ct=new bt.constructor(bt.type,bt);Object.defineProperty(ct,"target",{writable:!0,value:{value:at,name:y}}),B(ct,we)}p||ve(!1,je)}},Qe=we=>{S||[" ","ArrowUp","ArrowDown","Enter"].indexOf(we.key)!==-1&&(we.preventDefault(),ve(!0,we))},_e=j!==null&&P,gt=we=>{!_e&&Z&&(Object.defineProperty(we,"target",{writable:!0,value:{value:F,name:y}}),Z(we))};delete K["aria-invalid"];let lt,tt;const Xe=[];let ae=!1;(OH({value:F})||u)&&(X?lt=X(F):ae=!0);const ye=Je.map(we=>{if(!U.isValidElement(we))return null;let je;if(p){if(!Array.isArray(F))throw new Error(Uc(2));je=F.some(at=>Tue(at,we.props.value)),je&&ae&&Xe.push(we.props.children)}else je=Tue(F,we.props.value),je&&ae&&(tt=we.props.children);return U.cloneElement(we,{"aria-selected":je?"true":"false",onClick:De(we),onKeyUp:at=>{at.key===" "&&at.preventDefault(),we.props.onKeyUp&&we.props.onKeyUp(at)},role:"option",selected:je,value:void 0,"data-value":we.props.value})});ae&&(p?Xe.length===0?lt=null:lt=Xe.reduce((we,je,at)=>(we.push(je),at{const{ownerState:I}=e;return[g.root,I.formControl&&g.formControl,I.startAdornment&&g.adornedStart,I.endAdornment&&g.adornedEnd,I.error&&g.error,I.size==="small"&&g.sizeSmall,I.multiline&&g.multiline,I.color&&g[`color${si(I.color)}`],I.fullWidth&&g.fullWidth,I.hiddenLabel&&g.hiddenLabel]},MY=(e,g)=>{const{ownerState:I}=e;return[g.input,I.size==="small"&&g.inputSizeSmall,I.multiline&&g.inputMultiline,I.type==="search"&&g.inputTypeSearch,I.startAdornment&&g.inputAdornedStart,I.endAdornment&&g.inputAdornedEnd,I.hiddenLabel&&g.inputHiddenLabel]},Kmg=e=>{const{classes:g,color:I,disabled:i,error:n,endAdornment:C,focused:r,formControl:o,fullWidth:a,hiddenLabel:s,multiline:A,readOnly:l,size:c,startAdornment:u,type:d}=e,h={root:["root",`color${si(I)}`,i&&"disabled",n&&"error",a&&"fullWidth",r&&"focused",o&&"formControl",c&&c!=="medium"&&`size${si(c)}`,A&&"multiline",u&&"adornedStart",C&&"adornedEnd",s&&"hiddenLabel",l&&"readOnly"],input:["input",i&&"disabled",d==="search"&&"inputTypeSearch",A&&"inputMultiline",c==="small"&&"inputSizeSmall",s&&"inputHiddenLabel",u&&"inputAdornedStart",C&&"inputAdornedEnd",l&&"readOnly"]};return vi(h,Nmg,g)},zY=qt("div",{name:"MuiInputBase",slot:"Root",overridesResolver:EY})(({theme:e,ownerState:g})=>Ke({},e.typography.body1,{color:(e.vars||e).palette.text.primary,lineHeight:"1.4375em",boxSizing:"border-box",position:"relative",cursor:"text",display:"inline-flex",alignItems:"center",[`&.${b0.disabled}`]:{color:(e.vars||e).palette.text.disabled,cursor:"default"}},g.multiline&&Ke({padding:"4px 0 5px"},g.size==="small"&&{paddingTop:1}),g.fullWidth&&{width:"100%"})),PY=qt("input",{name:"MuiInputBase",slot:"Input",overridesResolver:MY})(({theme:e,ownerState:g})=>{const I=e.palette.mode==="light",i=Ke({color:"currentColor"},e.vars?{opacity:e.vars.opacity.inputPlaceholder}:{opacity:I?.42:.5},{transition:e.transitions.create("opacity",{duration:e.transitions.duration.shorter})}),n={opacity:"0 !important"},C=e.vars?{opacity:e.vars.opacity.inputPlaceholder}:{opacity:I?.42:.5};return Ke({font:"inherit",letterSpacing:"inherit",color:"currentColor",padding:"4px 0 5px",border:0,boxSizing:"content-box",background:"none",height:"1.4375em",margin:0,WebkitTapHighlightColor:"transparent",display:"block",minWidth:0,width:"100%",animationName:"mui-auto-fill-cancel",animationDuration:"10ms","&::-webkit-input-placeholder":i,"&::-moz-placeholder":i,"&:-ms-input-placeholder":i,"&::-ms-input-placeholder":i,"&:focus":{outline:0},"&:invalid":{boxShadow:"none"},"&::-webkit-search-decoration":{WebkitAppearance:"none"},[`label[data-shrink=false] + .${b0.formControl} &`]:{"&::-webkit-input-placeholder":n,"&::-moz-placeholder":n,"&:-ms-input-placeholder":n,"&::-ms-input-placeholder":n,"&:focus::-webkit-input-placeholder":C,"&:focus::-moz-placeholder":C,"&:focus:-ms-input-placeholder":C,"&:focus::-ms-input-placeholder":C},[`&.${b0.disabled}`]:{opacity:1,WebkitTextFillColor:(e.vars||e).palette.text.disabled},"&:-webkit-autofill":{animationDuration:"5000s",animationName:"mui-auto-fill"}},g.size==="small"&&{paddingTop:1},g.multiline&&{height:"auto",resize:"none",padding:0,paddingTop:0},g.type==="search"&&{MozAppearance:"textfield"})}),xmg=Oe.jsx(Tmg,{styles:{"@keyframes mui-auto-fill":{from:{display:"block"}},"@keyframes mui-auto-fill-cancel":{from:{display:"block"}}}}),Dmg=U.forwardRef(function(g,I){var i;const n=gi({props:g,name:"MuiInputBase"}),{"aria-describedby":C,autoComplete:r,autoFocus:o,className:a,components:s={},componentsProps:A={},defaultValue:l,disabled:c,disableInjectingGlobalStyles:u,endAdornment:d,fullWidth:h=!1,id:m,inputComponent:f="input",inputProps:b={},inputRef:p,maxRows:y,minRows:Z,multiline:B=!1,name:G,onBlur:v,onChange:w,onClick:V,onFocus:S,onKeyDown:X,onKeyUp:W,placeholder:R,readOnly:H,renderSuffix:Y,rows:K,slotProps:F={},slots:J={},startAdornment:P,type:ge="text",value:q}=n,$=Qt(n,Ymg),j=b.value!=null?b.value:q,{current:te}=U.useRef(j!=null),Q=U.useRef(),ie=U.useCallback(T=>{},[]),he=pn(Q,p,b.ref,ie),[ne,be]=U.useState(!1),pe=Pw(),ve=Jw({props:n,muiFormControl:pe,states:["color","disabled","error","hiddenLabel","size","required","filled"]});ve.focused=pe?pe.focused:ne,U.useEffect(()=>{!pe&&c&&ne&&(be(!1),v&&v())},[pe,c,ne,v]);const We=pe&&pe.onFilled,Be=pe&&pe.onEmpty,Je=U.useCallback(T=>{OH(T)?We&&We():Be&&Be()},[We,Be]);Ls(()=>{te&&Je({value:j})},[j,Je,te]);const Pe=T=>{if(ve.disabled){T.stopPropagation();return}S&&S(T),b.onFocus&&b.onFocus(T),pe&&pe.onFocus?pe.onFocus(T):be(!0)},De=T=>{v&&v(T),b.onBlur&&b.onBlur(T),pe&&pe.onBlur?pe.onBlur(T):be(!1)},Qe=(T,...k)=>{if(!te){const Ie=T.target||Q.current;if(Ie==null)throw new Error(Uc(1));Je({value:Ie.value})}b.onChange&&b.onChange(T,...k),w&&w(T,...k)};U.useEffect(()=>{Je(Q.current)},[]);const _e=T=>{Q.current&&T.currentTarget===T.target&&Q.current.focus(),V&&V(T)};let gt=f,lt=b;B&>==="input"&&(K?lt=Ke({type:void 0,minRows:K,maxRows:K},lt):lt=Ke({type:void 0,maxRows:y,minRows:Z},lt),gt=Zhg);const tt=T=>{Je(T.animationName==="mui-auto-fill-cancel"?Q.current:{value:"x"})};U.useEffect(()=>{pe&&pe.setAdornedStart(!!P)},[pe,P]);const Xe=Ke({},n,{color:ve.color||"primary",disabled:ve.disabled,endAdornment:d,error:ve.error,focused:ve.focused,formControl:pe,fullWidth:h,hiddenLabel:ve.hiddenLabel,multiline:B,size:ve.size,startAdornment:P,type:ge}),ae=Kmg(Xe),ye=J.root||s.Root||zY,He=F.root||A.root||{},x=J.input||s.Input||PY;return lt=Ke({},lt,(i=F.input)!=null?i:A.input),Oe.jsxs(U.Fragment,{children:[!u&&xmg,Oe.jsxs(ye,Ke({},He,!_H(ye)&&{ownerState:Ke({},Xe,He.ownerState)},{ref:I,onClick:_e},$,{className:ug(ae.root,He.className,a,H&&"MuiInputBase-readOnly"),children:[P,Oe.jsx(_8.Provider,{value:null,children:Oe.jsx(x,Ke({ownerState:Xe,"aria-invalid":ve.error,"aria-describedby":C,autoComplete:r,autoFocus:o,defaultValue:l,disabled:ve.disabled,id:m,onAnimationStart:tt,name:G,placeholder:R,readOnly:H,required:ve.required,rows:K,value:j,onKeyDown:X,onKeyUp:W,type:ge},lt,!_H(x)&&{as:gt,ownerState:Ke({},Xe,lt.ownerState)},{ref:he,className:ug(ae.input,lt.className,H&&"MuiInputBase-readOnly"),onBlur:De,onChange:Qe,onFocus:Pe}))}),d,Y?Y(Ke({},ve,{startAdornment:P})):null]}))]})}),U8=Dmg;function Fmg(e){return li("MuiInput",e)}const Emg=Ke({},b0,HI("MuiInput",["root","underline","input"])),RZ=Emg,Mmg=["disableUnderline","components","componentsProps","fullWidth","inputComponent","multiline","slotProps","slots","type"],zmg=e=>{const{classes:g,disableUnderline:I}=e,n=vi({root:["root",!I&&"underline"],input:["input"]},Fmg,g);return Ke({},g,n)},Pmg=qt(zY,{shouldForwardProp:e=>va(e)||e==="classes",name:"MuiInput",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[...EY(e,g),!I.disableUnderline&&g.underline]}})(({theme:e,ownerState:g})=>{let i=e.palette.mode==="light"?"rgba(0, 0, 0, 0.42)":"rgba(255, 255, 255, 0.7)";return e.vars&&(i=`rgba(${e.vars.palette.common.onBackgroundChannel} / ${e.vars.opacity.inputUnderline})`),Ke({position:"relative"},g.formControl&&{"label + &":{marginTop:16}},!g.disableUnderline&&{"&:after":{borderBottom:`2px solid ${(e.vars||e).palette[g.color].main}`,left:0,bottom:0,content:'""',position:"absolute",right:0,transform:"scaleX(0)",transition:e.transitions.create("transform",{duration:e.transitions.duration.shorter,easing:e.transitions.easing.easeOut}),pointerEvents:"none"},[`&.${RZ.focused}:after`]:{transform:"scaleX(1) translateX(0)"},[`&.${RZ.error}`]:{"&:before, &:after":{borderBottomColor:(e.vars||e).palette.error.main}},"&:before":{borderBottom:`1px solid ${i}`,left:0,bottom:0,content:'"\\00a0"',position:"absolute",right:0,transition:e.transitions.create("border-bottom-color",{duration:e.transitions.duration.shorter}),pointerEvents:"none"},[`&:hover:not(.${RZ.disabled}, .${RZ.error}):before`]:{borderBottom:`2px solid ${(e.vars||e).palette.text.primary}`,"@media (hover: none)":{borderBottom:`1px solid ${i}`}},[`&.${RZ.disabled}:before`]:{borderBottomStyle:"dotted"}})}),Jmg=qt(PY,{name:"MuiInput",slot:"Input",overridesResolver:MY})({}),cke=U.forwardRef(function(g,I){var i,n,C,r;const o=gi({props:g,name:"MuiInput"}),{disableUnderline:a,components:s={},componentsProps:A,fullWidth:l=!1,inputComponent:c="input",multiline:u=!1,slotProps:d,slots:h={},type:m="text"}=o,f=Qt(o,Mmg),b=zmg(o),y={root:{ownerState:{disableUnderline:a}}},Z=d??A?MC(d??A,y):y,B=(i=(n=h.root)!=null?n:s.Root)!=null?i:Pmg,G=(C=(r=h.input)!=null?r:s.Input)!=null?C:Jmg;return Oe.jsx(U8,Ke({slots:{root:B,input:G},slotProps:Z,fullWidth:l,inputComponent:c,multiline:u,ref:I,type:m},f,{classes:b}))});cke.muiName="Input";const Omg=cke;function _mg(e){return li("MuiFilledInput",e)}const Lmg=Ke({},b0,HI("MuiFilledInput",["root","underline","input"])),Eu=Lmg,Umg=["disableUnderline","components","componentsProps","fullWidth","hiddenLabel","inputComponent","multiline","slotProps","slots","type"],Qmg=e=>{const{classes:g,disableUnderline:I}=e,n=vi({root:["root",!I&&"underline"],input:["input"]},_mg,g);return Ke({},g,n)},jmg=qt(zY,{shouldForwardProp:e=>va(e)||e==="classes",name:"MuiFilledInput",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[...EY(e,g),!I.disableUnderline&&g.underline]}})(({theme:e,ownerState:g})=>{var I;const i=e.palette.mode==="light",n=i?"rgba(0, 0, 0, 0.42)":"rgba(255, 255, 255, 0.7)",C=i?"rgba(0, 0, 0, 0.06)":"rgba(255, 255, 255, 0.09)",r=i?"rgba(0, 0, 0, 0.09)":"rgba(255, 255, 255, 0.13)",o=i?"rgba(0, 0, 0, 0.12)":"rgba(255, 255, 255, 0.12)";return Ke({position:"relative",backgroundColor:e.vars?e.vars.palette.FilledInput.bg:C,borderTopLeftRadius:(e.vars||e).shape.borderRadius,borderTopRightRadius:(e.vars||e).shape.borderRadius,transition:e.transitions.create("background-color",{duration:e.transitions.duration.shorter,easing:e.transitions.easing.easeOut}),"&:hover":{backgroundColor:e.vars?e.vars.palette.FilledInput.hoverBg:r,"@media (hover: none)":{backgroundColor:e.vars?e.vars.palette.FilledInput.bg:C}},[`&.${Eu.focused}`]:{backgroundColor:e.vars?e.vars.palette.FilledInput.bg:C},[`&.${Eu.disabled}`]:{backgroundColor:e.vars?e.vars.palette.FilledInput.disabledBg:o}},!g.disableUnderline&&{"&:after":{borderBottom:`2px solid ${(I=(e.vars||e).palette[g.color||"primary"])==null?void 0:I.main}`,left:0,bottom:0,content:'""',position:"absolute",right:0,transform:"scaleX(0)",transition:e.transitions.create("transform",{duration:e.transitions.duration.shorter,easing:e.transitions.easing.easeOut}),pointerEvents:"none"},[`&.${Eu.focused}:after`]:{transform:"scaleX(1) translateX(0)"},[`&.${Eu.error}`]:{"&:before, &:after":{borderBottomColor:(e.vars||e).palette.error.main}},"&:before":{borderBottom:`1px solid ${e.vars?`rgba(${e.vars.palette.common.onBackgroundChannel} / ${e.vars.opacity.inputUnderline})`:n}`,left:0,bottom:0,content:'"\\00a0"',position:"absolute",right:0,transition:e.transitions.create("border-bottom-color",{duration:e.transitions.duration.shorter}),pointerEvents:"none"},[`&:hover:not(.${Eu.disabled}, .${Eu.error}):before`]:{borderBottom:`1px solid ${(e.vars||e).palette.text.primary}`},[`&.${Eu.disabled}:before`]:{borderBottomStyle:"dotted"}},g.startAdornment&&{paddingLeft:12},g.endAdornment&&{paddingRight:12},g.multiline&&Ke({padding:"25px 12px 8px"},g.size==="small"&&{paddingTop:21,paddingBottom:4},g.hiddenLabel&&{paddingTop:16,paddingBottom:17},g.hiddenLabel&&g.size==="small"&&{paddingTop:8,paddingBottom:9}))}),$mg=qt(PY,{name:"MuiFilledInput",slot:"Input",overridesResolver:MY})(({theme:e,ownerState:g})=>Ke({paddingTop:25,paddingRight:12,paddingBottom:8,paddingLeft:12},!e.vars&&{"&:-webkit-autofill":{WebkitBoxShadow:e.palette.mode==="light"?null:"0 0 0 100px #266798 inset",WebkitTextFillColor:e.palette.mode==="light"?null:"#fff",caretColor:e.palette.mode==="light"?null:"#fff",borderTopLeftRadius:"inherit",borderTopRightRadius:"inherit"}},e.vars&&{"&:-webkit-autofill":{borderTopLeftRadius:"inherit",borderTopRightRadius:"inherit"},[e.getColorSchemeSelector("dark")]:{"&:-webkit-autofill":{WebkitBoxShadow:"0 0 0 100px #266798 inset",WebkitTextFillColor:"#fff",caretColor:"#fff"}}},g.size==="small"&&{paddingTop:21,paddingBottom:4},g.hiddenLabel&&{paddingTop:16,paddingBottom:17},g.startAdornment&&{paddingLeft:0},g.endAdornment&&{paddingRight:0},g.hiddenLabel&&g.size==="small"&&{paddingTop:8,paddingBottom:9},g.multiline&&{paddingTop:0,paddingBottom:0,paddingLeft:0,paddingRight:0})),uke=U.forwardRef(function(g,I){var i,n,C,r;const o=gi({props:g,name:"MuiFilledInput"}),{components:a={},componentsProps:s,fullWidth:A=!1,inputComponent:l="input",multiline:c=!1,slotProps:u,slots:d={},type:h="text"}=o,m=Qt(o,Umg),f=Ke({},o,{fullWidth:A,inputComponent:l,multiline:c,type:h}),b=Qmg(o),p={root:{ownerState:f},input:{ownerState:f}},y=u??s?MC(p,u??s):p,Z=(i=(n=d.root)!=null?n:a.Root)!=null?i:jmg,B=(C=(r=d.input)!=null?r:a.Input)!=null?C:$mg;return Oe.jsx(U8,Ke({slots:{root:Z,input:B},componentsProps:y,fullWidth:A,inputComponent:l,multiline:c,ref:I,type:h},m,{classes:b}))});uke.muiName="Input";const qmg=uke;var Nue;const efg=["children","classes","className","label","notched"],tfg=qt("fieldset",{shouldForwardProp:va})({textAlign:"left",position:"absolute",bottom:0,right:0,top:-5,left:0,margin:0,padding:"0 8px",pointerEvents:"none",borderRadius:"inherit",borderStyle:"solid",borderWidth:1,overflow:"hidden",minWidth:"0%"}),gfg=qt("legend",{shouldForwardProp:va})(({ownerState:e,theme:g})=>Ke({float:"unset",width:"auto",overflow:"hidden"},!e.withLabel&&{padding:0,lineHeight:"11px",transition:g.transitions.create("width",{duration:150,easing:g.transitions.easing.easeOut})},e.withLabel&&Ke({display:"block",padding:0,height:11,fontSize:"0.75em",visibility:"hidden",maxWidth:.01,transition:g.transitions.create("max-width",{duration:50,easing:g.transitions.easing.easeOut}),whiteSpace:"nowrap","& > span":{paddingLeft:5,paddingRight:5,display:"inline-block",opacity:0,visibility:"visible"}},e.notched&&{maxWidth:"100%",transition:g.transitions.create("max-width",{duration:100,easing:g.transitions.easing.easeOut,delay:50})})));function Ifg(e){const{className:g,label:I,notched:i}=e,n=Qt(e,efg),C=I!=null&&I!=="",r=Ke({},e,{notched:i,withLabel:C});return Oe.jsx(tfg,Ke({"aria-hidden":!0,className:g,ownerState:r},n,{children:Oe.jsx(gfg,{ownerState:r,children:C?Oe.jsx("span",{children:I}):Nue||(Nue=Oe.jsx("span",{className:"notranslate",children:"​"}))})}))}function ifg(e){return li("MuiOutlinedInput",e)}const nfg=Ke({},b0,HI("MuiOutlinedInput",["root","notchedOutline","input"])),Rl=nfg,Cfg=["components","fullWidth","inputComponent","label","multiline","notched","slots","type"],rfg=e=>{const{classes:g}=e,i=vi({root:["root"],notchedOutline:["notchedOutline"],input:["input"]},ifg,g);return Ke({},g,i)},ofg=qt(zY,{shouldForwardProp:e=>va(e)||e==="classes",name:"MuiOutlinedInput",slot:"Root",overridesResolver:EY})(({theme:e,ownerState:g})=>{const I=e.palette.mode==="light"?"rgba(0, 0, 0, 0.23)":"rgba(255, 255, 255, 0.23)";return Ke({position:"relative",borderRadius:(e.vars||e).shape.borderRadius,[`&:hover .${Rl.notchedOutline}`]:{borderColor:(e.vars||e).palette.text.primary},"@media (hover: none)":{[`&:hover .${Rl.notchedOutline}`]:{borderColor:e.vars?`rgba(${e.vars.palette.common.onBackgroundChannel} / 0.23)`:I}},[`&.${Rl.focused} .${Rl.notchedOutline}`]:{borderColor:(e.vars||e).palette[g.color].main,borderWidth:2},[`&.${Rl.error} .${Rl.notchedOutline}`]:{borderColor:(e.vars||e).palette.error.main},[`&.${Rl.disabled} .${Rl.notchedOutline}`]:{borderColor:(e.vars||e).palette.action.disabled}},g.startAdornment&&{paddingLeft:14},g.endAdornment&&{paddingRight:14},g.multiline&&Ke({padding:"16.5px 14px"},g.size==="small"&&{padding:"8.5px 14px"}))}),afg=qt(Ifg,{name:"MuiOutlinedInput",slot:"NotchedOutline",overridesResolver:(e,g)=>g.notchedOutline})(({theme:e})=>{const g=e.palette.mode==="light"?"rgba(0, 0, 0, 0.23)":"rgba(255, 255, 255, 0.23)";return{borderColor:e.vars?`rgba(${e.vars.palette.common.onBackgroundChannel} / 0.23)`:g}}),Afg=qt(PY,{name:"MuiOutlinedInput",slot:"Input",overridesResolver:MY})(({theme:e,ownerState:g})=>Ke({padding:"16.5px 14px"},!e.vars&&{"&:-webkit-autofill":{WebkitBoxShadow:e.palette.mode==="light"?null:"0 0 0 100px #266798 inset",WebkitTextFillColor:e.palette.mode==="light"?null:"#fff",caretColor:e.palette.mode==="light"?null:"#fff",borderRadius:"inherit"}},e.vars&&{"&:-webkit-autofill":{borderRadius:"inherit"},[e.getColorSchemeSelector("dark")]:{"&:-webkit-autofill":{WebkitBoxShadow:"0 0 0 100px #266798 inset",WebkitTextFillColor:"#fff",caretColor:"#fff"}}},g.size==="small"&&{padding:"8.5px 14px"},g.multiline&&{padding:0},g.startAdornment&&{paddingLeft:0},g.endAdornment&&{paddingRight:0})),dke=U.forwardRef(function(g,I){var i,n,C,r,o;const a=gi({props:g,name:"MuiOutlinedInput"}),{components:s={},fullWidth:A=!1,inputComponent:l="input",label:c,multiline:u=!1,notched:d,slots:h={},type:m="text"}=a,f=Qt(a,Cfg),b=rfg(a),p=Pw(),y=Jw({props:a,muiFormControl:p,states:["color","disabled","error","focused","hiddenLabel","size","required"]}),Z=Ke({},a,{color:y.color||"primary",disabled:y.disabled,error:y.error,focused:y.focused,formControl:p,fullWidth:A,hiddenLabel:y.hiddenLabel,multiline:u,size:y.size,type:m}),B=(i=(n=h.root)!=null?n:s.Root)!=null?i:ofg,G=(C=(r=h.input)!=null?r:s.Input)!=null?C:Afg;return Oe.jsx(U8,Ke({slots:{root:B,input:G},renderSuffix:v=>Oe.jsx(afg,{ownerState:Z,className:b.notchedOutline,label:c!=null&&c!==""&&y.required?o||(o=Oe.jsxs(U.Fragment,{children:[c," ","*"]})):c,notched:typeof d<"u"?d:!!(v.startAdornment||v.filled||v.focused)}),fullWidth:A,inputComponent:l,multiline:u,ref:I,type:m},f,{classes:Ke({},b,{notchedOutline:null})}))});dke.muiName="Input";const sfg=dke,lfg=["autoWidth","children","classes","className","defaultOpen","displayEmpty","IconComponent","id","input","inputProps","label","labelId","MenuProps","multiple","native","onClose","onOpen","open","renderValue","SelectDisplayProps","variant"],cfg=["root"],ufg=e=>{const{classes:g}=e;return g},Q8={name:"MuiSelect",overridesResolver:(e,g)=>g.root,shouldForwardProp:e=>va(e)&&e!=="variant",slot:"Root"},dfg=qt(Omg,Q8)(""),hfg=qt(sfg,Q8)(""),mfg=qt(qmg,Q8)(""),hke=U.forwardRef(function(g,I){const i=gi({name:"MuiSelect",props:g}),{autoWidth:n=!1,children:C,classes:r={},className:o,defaultOpen:a=!1,displayEmpty:s=!1,IconComponent:A=Hmg,id:l,input:c,inputProps:u,label:d,labelId:h,MenuProps:m,multiple:f=!1,native:b=!1,onClose:p,onOpen:y,open:Z,renderValue:B,SelectDisplayProps:G,variant:v="outlined"}=i,w=Qt(i,lfg),V=b?ymg:Xmg,S=Pw(),X=Jw({props:i,muiFormControl:S,states:["variant","error"]}),W=X.variant||v,R=Ke({},i,{variant:W,classes:r}),H=ufg(R),Y=Qt(H,cfg),K=c||{standard:Oe.jsx(dfg,{ownerState:R}),outlined:Oe.jsx(hfg,{label:d,ownerState:R}),filled:Oe.jsx(mfg,{ownerState:R})}[W],F=pn(I,K.ref);return Oe.jsx(U.Fragment,{children:U.cloneElement(K,Ke({inputComponent:V,inputProps:Ke({children:C,error:X.error,IconComponent:A,variant:W,type:void 0,multiple:f},b?{id:l}:{autoWidth:n,defaultOpen:a,displayEmpty:s,labelId:h,MenuProps:m,onClose:p,onOpen:y,open:Z,renderValue:B,SelectDisplayProps:Ke({id:l},G)},u,{classes:u?MC(Y,u.classes):Y},c?c.props.inputProps:{})},f&&b&&W==="outlined"?{notched:!0}:{},{ref:F,className:ug(K.props.className,o,H.root)},!c&&{variant:W},w))})});hke.muiName="Select";const ffg=hke;function pfg(e){const{className:g,classes:I,pulsate:i=!1,rippleX:n,rippleY:C,rippleSize:r,in:o,onExited:a,timeout:s}=e,[A,l]=U.useState(!1),c=ug(g,I.ripple,I.rippleVisible,i&&I.ripplePulsate),u={width:r,height:r,top:-(r/2)+C,left:-(r/2)+n},d=ug(I.child,A&&I.childLeaving,i&&I.childPulsate);return!o&&!A&&l(!0),U.useEffect(()=>{if(!o&&a!=null){const h=setTimeout(a,s);return()=>{clearTimeout(h)}}},[a,o,s]),Oe.jsx("span",{className:c,style:u,children:Oe.jsx("span",{className:d})})}const bfg=HI("MuiTouchRipple",["root","ripple","rippleVisible","ripplePulsate","child","childLeaving","childPulsate"]),Yr=bfg,yfg=["center","classes","className"];let JY=e=>e,kue,Yue,Kue,xue;const z_=550,Zfg=80,Gfg=B8(kue||(kue=JY` + */function Csg(e,g){return Y_(e,g)}const rsg=(e,g)=>{Array.isArray(e.__emotion_styles)&&(e.__emotion_styles=g(e.__emotion_styles))},osg=["values","unit","step"],asg=e=>{const g=Object.keys(e).map(I=>({key:I,val:e[I]}))||[];return g.sort((I,i)=>I.val-i.val),g.reduce((I,i)=>Ke({},I,{[i.key]:i.val}),{})};function Asg(e){const{values:g={xs:0,sm:600,md:900,lg:1200,xl:1536},unit:I="px",step:i=5}=e,n=Qt(e,osg),C=asg(g),r=Object.keys(C);function o(c){return`@media (min-width:${typeof g[c]=="number"?g[c]:c}${I})`}function a(c){return`@media (max-width:${(typeof g[c]=="number"?g[c]:c)-i/100}${I})`}function s(c,u){const d=r.indexOf(u);return`@media (min-width:${typeof g[c]=="number"?g[c]:c}${I}) and (max-width:${(d!==-1&&typeof g[r[d]]=="number"?g[r[d]]:u)-i/100}${I})`}function A(c){return r.indexOf(c)+1`@media (min-width:${S8[e]}px)`};function ao(e,g,I){const i=e.theme||{};if(Array.isArray(g)){const C=i.breakpoints||$ce;return g.reduce((r,o,a)=>(r[C.up(C.keys[a])]=I(g[a]),r),{})}if(typeof g=="object"){const C=i.breakpoints||$ce;return Object.keys(g).reduce((r,o)=>{if(Object.keys(C.values||S8).indexOf(o)!==-1){const a=C.up(o);r[a]=I(g[o],o)}else{const a=o;r[a]=g[a]}return r},{})}return I(g)}function csg(e={}){var g;return((g=e.keys)==null?void 0:g.reduce((i,n)=>{const C=e.up(n);return i[C]={},i},{}))||{}}function usg(e,g){return e.reduce((I,i)=>{const n=I[i];return(!n||Object.keys(n).length===0)&&delete I[i],I},g)}function dsg(e,g){if(typeof e!="object")return{};const I={},i=Object.keys(g);return Array.isArray(e)?i.forEach((n,C)=>{C{e[n]!=null&&(I[n]=!0)}),I}function WY({values:e,breakpoints:g,base:I}){const i=I||dsg(e,g),n=Object.keys(i);if(n.length===0)return e;let C;return n.reduce((r,o,a)=>(Array.isArray(e)?(r[o]=e[a]!=null?e[a]:e[C],C=a):typeof e=="object"?(r[o]=e[o]!=null?e[o]:e[C],C=o):r[o]=e,r),{})}function XY(e,g,I=!0){if(!g||typeof g!="string")return null;if(e&&e.vars&&I){const i=`vars.${g}`.split(".").reduce((n,C)=>n&&n[C]?n[C]:null,e);if(i!=null)return i}return g.split(".").reduce((i,n)=>i&&i[n]!=null?i[n]:null,e)}function MH(e,g,I,i=I){let n;return typeof e=="function"?n=e(I):Array.isArray(e)?n=e[I]||i:n=XY(e,I)||i,g&&(n=g(n,i,e)),n}function ci(e){const{prop:g,cssProperty:I=e.prop,themeKey:i,transform:n}=e,C=r=>{if(r[g]==null)return null;const o=r[g],a=r.theme,s=XY(a,i)||{};return ao(r,o,l=>{let c=MH(s,n,l);return l===c&&typeof l=="string"&&(c=MH(s,n,`${g}${l==="default"?"":si(l)}`,l)),I===!1?c:{[I]:c}})};return C.propTypes={},C.filterProps=[g],C}function hsg(e){const g={};return I=>(g[I]===void 0&&(g[I]=e(I)),g[I])}const msg={m:"margin",p:"padding"},fsg={t:"Top",r:"Right",b:"Bottom",l:"Left",x:["Left","Right"],y:["Top","Bottom"]},qce={marginX:"mx",marginY:"my",paddingX:"px",paddingY:"py"},psg=hsg(e=>{if(e.length>2)if(qce[e])e=qce[e];else return[e];const[g,I]=e.split(""),i=msg[g],n=fsg[I]||"";return Array.isArray(n)?n.map(C=>i+C):[i+n]}),w8=["m","mt","mr","mb","ml","mx","my","margin","marginTop","marginRight","marginBottom","marginLeft","marginX","marginY","marginInline","marginInlineStart","marginInlineEnd","marginBlock","marginBlockStart","marginBlockEnd"],V8=["p","pt","pr","pb","pl","px","py","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingX","paddingY","paddingInline","paddingInlineStart","paddingInlineEnd","paddingBlock","paddingBlockStart","paddingBlockEnd"];[...w8,...V8];function Mw(e,g,I,i){var n;const C=(n=XY(e,g,!1))!=null?n:I;return typeof C=="number"?r=>typeof r=="string"?r:C*r:Array.isArray(C)?r=>typeof r=="string"?r:C[r]:typeof C=="function"?C:()=>{}}function WNe(e){return Mw(e,"spacing",8)}function zw(e,g){if(typeof g=="string"||g==null)return g;const I=Math.abs(g),i=e(I);return g>=0?i:typeof i=="number"?-i:`-${i}`}function bsg(e,g){return I=>e.reduce((i,n)=>(i[n]=zw(g,I),i),{})}function ysg(e,g,I,i){if(g.indexOf(I)===-1)return null;const n=psg(I),C=bsg(n,i),r=e[I];return ao(e,r,C)}function XNe(e,g){const I=WNe(e.theme);return Object.keys(e).map(i=>ysg(e,g,i,I)).reduce(kv,{})}function OI(e){return XNe(e,w8)}OI.propTypes={};OI.filterProps=w8;function _I(e){return XNe(e,V8)}_I.propTypes={};_I.filterProps=V8;function Zsg(e=8){if(e.mui)return e;const g=WNe({spacing:e}),I=(...i)=>(i.length===0?[1]:i).map(C=>{const r=g(C);return typeof r=="number"?`${r}px`:r}).join(" ");return I.mui=!0,I}function HY(...e){const g=e.reduce((i,n)=>(n.filterProps.forEach(C=>{i[C]=n}),i),{}),I=i=>Object.keys(i).reduce((n,C)=>g[C]?kv(n,g[C](i)):n,{});return I.propTypes={},I.filterProps=e.reduce((i,n)=>i.concat(n.filterProps),[]),I}function zr(e){return typeof e!="number"?e:`${e}px solid`}function lo(e,g){return ci({prop:e,themeKey:"borders",transform:g})}const Gsg=lo("border",zr),vsg=lo("borderTop",zr),Bsg=lo("borderRight",zr),Ssg=lo("borderBottom",zr),wsg=lo("borderLeft",zr),Vsg=lo("borderColor"),Rsg=lo("borderTopColor"),Wsg=lo("borderRightColor"),Xsg=lo("borderBottomColor"),Hsg=lo("borderLeftColor"),Tsg=lo("outline",zr),Nsg=lo("outlineColor"),TY=e=>{if(e.borderRadius!==void 0&&e.borderRadius!==null){const g=Mw(e.theme,"shape.borderRadius",4),I=i=>({borderRadius:zw(g,i)});return ao(e,e.borderRadius,I)}return null};TY.propTypes={};TY.filterProps=["borderRadius"];HY(Gsg,vsg,Bsg,Ssg,wsg,Vsg,Rsg,Wsg,Xsg,Hsg,TY,Tsg,Nsg);const NY=e=>{if(e.gap!==void 0&&e.gap!==null){const g=Mw(e.theme,"spacing",8),I=i=>({gap:zw(g,i)});return ao(e,e.gap,I)}return null};NY.propTypes={};NY.filterProps=["gap"];const kY=e=>{if(e.columnGap!==void 0&&e.columnGap!==null){const g=Mw(e.theme,"spacing",8),I=i=>({columnGap:zw(g,i)});return ao(e,e.columnGap,I)}return null};kY.propTypes={};kY.filterProps=["columnGap"];const YY=e=>{if(e.rowGap!==void 0&&e.rowGap!==null){const g=Mw(e.theme,"spacing",8),I=i=>({rowGap:zw(g,i)});return ao(e,e.rowGap,I)}return null};YY.propTypes={};YY.filterProps=["rowGap"];const ksg=ci({prop:"gridColumn"}),Ysg=ci({prop:"gridRow"}),Ksg=ci({prop:"gridAutoFlow"}),xsg=ci({prop:"gridAutoColumns"}),Dsg=ci({prop:"gridAutoRows"}),Fsg=ci({prop:"gridTemplateColumns"}),Esg=ci({prop:"gridTemplateRows"}),Msg=ci({prop:"gridTemplateAreas"}),zsg=ci({prop:"gridArea"});HY(NY,kY,YY,ksg,Ysg,Ksg,xsg,Dsg,Fsg,Esg,Msg,zsg);function qp(e,g){return g==="grey"?g:e}const Psg=ci({prop:"color",themeKey:"palette",transform:qp}),Jsg=ci({prop:"bgcolor",cssProperty:"backgroundColor",themeKey:"palette",transform:qp}),Osg=ci({prop:"backgroundColor",themeKey:"palette",transform:qp});HY(Psg,Jsg,Osg);function Ar(e){return e<=1&&e!==0?`${e*100}%`:e}const _sg=ci({prop:"width",transform:Ar}),R8=e=>{if(e.maxWidth!==void 0&&e.maxWidth!==null){const g=I=>{var i,n;const C=((i=e.theme)==null||(i=i.breakpoints)==null||(i=i.values)==null?void 0:i[I])||S8[I];return C?((n=e.theme)==null||(n=n.breakpoints)==null?void 0:n.unit)!=="px"?{maxWidth:`${C}${e.theme.breakpoints.unit}`}:{maxWidth:C}:{maxWidth:Ar(I)}};return ao(e,e.maxWidth,g)}return null};R8.filterProps=["maxWidth"];const Lsg=ci({prop:"minWidth",transform:Ar}),Usg=ci({prop:"height",transform:Ar}),Qsg=ci({prop:"maxHeight",transform:Ar}),jsg=ci({prop:"minHeight",transform:Ar});ci({prop:"size",cssProperty:"width",transform:Ar});ci({prop:"size",cssProperty:"height",transform:Ar});const $sg=ci({prop:"boxSizing"});HY(_sg,R8,Lsg,Usg,Qsg,jsg,$sg);const qsg={border:{themeKey:"borders",transform:zr},borderTop:{themeKey:"borders",transform:zr},borderRight:{themeKey:"borders",transform:zr},borderBottom:{themeKey:"borders",transform:zr},borderLeft:{themeKey:"borders",transform:zr},borderColor:{themeKey:"palette"},borderTopColor:{themeKey:"palette"},borderRightColor:{themeKey:"palette"},borderBottomColor:{themeKey:"palette"},borderLeftColor:{themeKey:"palette"},outline:{themeKey:"borders",transform:zr},outlineColor:{themeKey:"palette"},borderRadius:{themeKey:"shape.borderRadius",style:TY},color:{themeKey:"palette",transform:qp},bgcolor:{themeKey:"palette",cssProperty:"backgroundColor",transform:qp},backgroundColor:{themeKey:"palette",transform:qp},p:{style:_I},pt:{style:_I},pr:{style:_I},pb:{style:_I},pl:{style:_I},px:{style:_I},py:{style:_I},padding:{style:_I},paddingTop:{style:_I},paddingRight:{style:_I},paddingBottom:{style:_I},paddingLeft:{style:_I},paddingX:{style:_I},paddingY:{style:_I},paddingInline:{style:_I},paddingInlineStart:{style:_I},paddingInlineEnd:{style:_I},paddingBlock:{style:_I},paddingBlockStart:{style:_I},paddingBlockEnd:{style:_I},m:{style:OI},mt:{style:OI},mr:{style:OI},mb:{style:OI},ml:{style:OI},mx:{style:OI},my:{style:OI},margin:{style:OI},marginTop:{style:OI},marginRight:{style:OI},marginBottom:{style:OI},marginLeft:{style:OI},marginX:{style:OI},marginY:{style:OI},marginInline:{style:OI},marginInlineStart:{style:OI},marginInlineEnd:{style:OI},marginBlock:{style:OI},marginBlockStart:{style:OI},marginBlockEnd:{style:OI},displayPrint:{cssProperty:!1,transform:e=>({"@media print":{display:e}})},display:{},overflow:{},textOverflow:{},visibility:{},whiteSpace:{},flexBasis:{},flexDirection:{},flexWrap:{},justifyContent:{},alignItems:{},alignContent:{},order:{},flex:{},flexGrow:{},flexShrink:{},alignSelf:{},justifyItems:{},justifySelf:{},gap:{style:NY},rowGap:{style:YY},columnGap:{style:kY},gridColumn:{},gridRow:{},gridAutoFlow:{},gridAutoColumns:{},gridAutoRows:{},gridTemplateColumns:{},gridTemplateRows:{},gridTemplateAreas:{},gridArea:{},position:{},zIndex:{themeKey:"zIndex"},top:{},right:{},bottom:{},left:{},boxShadow:{themeKey:"shadows"},width:{transform:Ar},maxWidth:{style:R8},minWidth:{transform:Ar},height:{transform:Ar},maxHeight:{transform:Ar},minHeight:{transform:Ar},boxSizing:{},fontFamily:{themeKey:"typography"},fontSize:{themeKey:"typography"},fontStyle:{themeKey:"typography"},fontWeight:{themeKey:"typography"},letterSpacing:{},textTransform:{},lineHeight:{},textAlign:{},typography:{cssProperty:!1,themeKey:"typography"}},KY=qsg;function elg(...e){const g=e.reduce((i,n)=>i.concat(Object.keys(n)),[]),I=new Set(g);return e.every(i=>I.size===Object.keys(i).length)}function tlg(e,g){return typeof e=="function"?e(g):e}function glg(){function e(I,i,n,C){const r={[I]:i,theme:n},o=C[I];if(!o)return{[I]:i};const{cssProperty:a=I,themeKey:s,transform:A,style:l}=o;if(i==null)return null;if(s==="typography"&&i==="inherit")return{[I]:i};const c=XY(n,s)||{};return l?l(r):ao(r,i,d=>{let h=MH(c,A,d);return d===h&&typeof d=="string"&&(h=MH(c,A,`${I}${d==="default"?"":si(d)}`,d)),a===!1?h:{[a]:h}})}function g(I){var i;const{sx:n,theme:C={}}=I||{};if(!n)return null;const r=(i=C.unstable_sxConfig)!=null?i:KY;function o(a){let s=a;if(typeof a=="function")s=a(C);else if(typeof a!="object")return a;if(!s)return null;const A=csg(C.breakpoints),l=Object.keys(A);let c=A;return Object.keys(s).forEach(u=>{const d=tlg(s[u],C);if(d!=null)if(typeof d=="object")if(r[u])c=kv(c,e(u,d,C,r));else{const h=ao({theme:C},d,m=>({[u]:m}));elg(h,d)?c[u]=g({sx:d,theme:C}):c=kv(c,h)}else c=kv(c,e(u,d,C,r))}),usg(l,c)}return Array.isArray(n)?n.map(o):o(n)}return g}const HNe=glg();HNe.filterProps=["sx"];const W8=HNe,Ilg=["breakpoints","palette","spacing","shape"];function X8(e={},...g){const{breakpoints:I={},palette:i={},spacing:n,shape:C={}}=e,r=Qt(e,Ilg),o=Asg(I),a=Zsg(n);let s=MC({breakpoints:o,direction:"ltr",components:{},palette:Ke({mode:"light"},i),spacing:a,shape:Ke({},lsg,C)},r);return s=g.reduce((A,l)=>MC(A,l),s),s.unstable_sxConfig=Ke({},KY,r==null?void 0:r.unstable_sxConfig),s.unstable_sx=function(l){return W8({sx:l,theme:this})},s}function ilg(e){return Object.keys(e).length===0}function nlg(e=null){const g=U.useContext(v8);return!g||ilg(g)?e:g}const Clg=X8();function H8(e=Clg){return nlg(e)}function rlg({styles:e,themeId:g,defaultTheme:I={}}){const i=H8(I),n=typeof e=="function"?e(g&&i[g]||i):e;return Oe.jsx(nsg,{styles:n})}const olg=["sx"],alg=e=>{var g,I;const i={systemProps:{},otherProps:{}},n=(g=e==null||(I=e.theme)==null?void 0:I.unstable_sxConfig)!=null?g:KY;return Object.keys(e).forEach(C=>{n[C]?i.systemProps[C]=e[C]:i.otherProps[C]=e[C]}),i};function Alg(e){const{sx:g}=e,I=Qt(e,olg),{systemProps:i,otherProps:n}=alg(I);let C;return Array.isArray(g)?C=[i,...g]:typeof g=="function"?C=(...r)=>{const o=g(...r);return ss(o)?Ke({},i,o):i}:C=Ke({},i,g),Ke({},n,{sx:C})}function TNe(e){var g,I,i="";if(typeof e=="string"||typeof e=="number")i+=e;else if(typeof e=="object")if(Array.isArray(e))for(g=0;g{n==="color"?i+=eue(i)?e[n]:si(e[n]):i+=`${eue(i)?n:si(n)}${si(e[n].toString())}`}),i}const llg=["name","slot","skipVariantsResolver","skipSx","overridesResolver"];function clg(e){return Object.keys(e).length===0}function ulg(e){return typeof e=="string"&&e.charCodeAt(0)>96}const dlg=(e,g)=>g.components&&g.components[e]&&g.components[e].styleOverrides?g.components[e].styleOverrides:null,zH=e=>{const g={};return e&&e.forEach(I=>{const i=NNe(I.props);g[i]=I.style}),g},hlg=(e,g)=>{let I=[];return g&&g.components&&g.components[e]&&g.components[e].variants&&(I=g.components[e].variants),zH(I)},PH=(e,g,I)=>{const{ownerState:i={}}=e,n=[];return I&&I.forEach(C=>{let r=!0;Object.keys(C.props).forEach(o=>{i[o]!==C.props[o]&&e[o]!==C.props[o]&&(r=!1)}),r&&n.push(g[NNe(C.props)])}),n},mlg=(e,g,I,i)=>{var n;const C=I==null||(n=I.components)==null||(n=n[i])==null?void 0:n.variants;return PH(e,g,C)};function Yv(e){return e!=="ownerState"&&e!=="theme"&&e!=="sx"&&e!=="as"}const flg=X8(),plg=e=>e&&e.charAt(0).toLowerCase()+e.slice(1);function MW({defaultTheme:e,theme:g,themeId:I}){return clg(g)?e:g[I]||g}function blg(e){return e?(g,I)=>I[e]:null}const tue=({styledArg:e,props:g,defaultTheme:I,themeId:i})=>{const n=e(Ke({},g,{theme:MW(Ke({},g,{defaultTheme:I,themeId:i}))}));let C;if(n&&n.variants&&(C=n.variants,delete n.variants),C){const r=PH(g,zH(C),C);return[n,...r]}return n};function ylg(e={}){const{themeId:g,defaultTheme:I=flg,rootShouldForwardProp:i=Yv,slotShouldForwardProp:n=Yv}=e,C=r=>W8(Ke({},r,{theme:MW(Ke({},r,{defaultTheme:I,themeId:g}))}));return C.__mui_systemSx=!0,(r,o={})=>{rsg(r,y=>y.filter(Z=>!(Z!=null&&Z.__mui_systemSx)));const{name:a,slot:s,skipVariantsResolver:A,skipSx:l,overridesResolver:c=blg(plg(s))}=o,u=Qt(o,llg),d=A!==void 0?A:s&&s!=="Root"&&s!=="root"||!1,h=l||!1;let m,f=Yv;s==="Root"||s==="root"?f=i:s?f=n:ulg(r)&&(f=void 0);const b=Csg(r,Ke({shouldForwardProp:f,label:m},u)),p=(y,...Z)=>{const B=Z?Z.map(V=>{if(typeof V=="function"&&V.__emotion_real!==V)return S=>tue({styledArg:V,props:S,defaultTheme:I,themeId:g});if(ss(V)){let S=V,X;return V&&V.variants&&(X=V.variants,delete S.variants,S=W=>{let R=V;return PH(W,zH(X),X).forEach(Y=>{R=MC(R,Y)}),R}),S}return V}):[];let G=y;if(ss(y)){let V;y&&y.variants&&(V=y.variants,delete G.variants,G=S=>{let X=y;return PH(S,zH(V),V).forEach(R=>{X=MC(X,R)}),X})}else typeof y=="function"&&y.__emotion_real!==y&&(G=V=>tue({styledArg:y,props:V,defaultTheme:I,themeId:g}));a&&c&&B.push(V=>{const S=MW(Ke({},V,{defaultTheme:I,themeId:g})),X=dlg(a,S);if(X){const W={};return Object.entries(X).forEach(([R,H])=>{W[R]=typeof H=="function"?H(Ke({},V,{theme:S})):H}),c(V,W)}return null}),a&&!d&&B.push(V=>{const S=MW(Ke({},V,{defaultTheme:I,themeId:g}));return mlg(V,hlg(a,S),S,a)}),h||B.push(C);const v=B.length-Z.length;if(Array.isArray(y)&&v>0){const V=new Array(v).fill("");G=[...y,...V],G.raw=[...y.raw,...V]}const w=b(G,...B);return r.muiName&&(w.muiName=r.muiName),w};return b.withConfig&&(p.withConfig=b.withConfig),p}}function Zlg(e){const{theme:g,name:I,props:i}=e;return!g||!g.components||!g.components[I]||!g.components[I].defaultProps?i:ANe(g.components[I].defaultProps,i)}function Glg({props:e,name:g,defaultTheme:I,themeId:i}){let n=H8(I);return i&&(n=n[i]||n),Zlg({theme:n,name:g,props:e})}function T8(e,g=0,I=1){return Math.min(Math.max(g,e),I)}function vlg(e){e=e.slice(1);const g=new RegExp(`.{1,${e.length>=6?2:1}}`,"g");let I=e.match(g);return I&&I[0].length===1&&(I=I.map(i=>i+i)),I?`rgb${I.length===4?"a":""}(${I.map((i,n)=>n<3?parseInt(i,16):Math.round(parseInt(i,16)/255*1e3)/1e3).join(", ")})`:""}function Ph(e){if(e.type)return e;if(e.charAt(0)==="#")return Ph(vlg(e));const g=e.indexOf("("),I=e.substring(0,g);if(["rgb","rgba","hsl","hsla","color"].indexOf(I)===-1)throw new Error(Uc(9,e));let i=e.substring(g+1,e.length-1),n;if(I==="color"){if(i=i.split(" "),n=i.shift(),i.length===4&&i[3].charAt(0)==="/"&&(i[3]=i[3].slice(1)),["srgb","display-p3","a98-rgb","prophoto-rgb","rec-2020"].indexOf(n)===-1)throw new Error(Uc(10,n))}else i=i.split(",");return i=i.map(C=>parseFloat(C)),{type:I,values:i,colorSpace:n}}function xY(e){const{type:g,colorSpace:I}=e;let{values:i}=e;return g.indexOf("rgb")!==-1?i=i.map((n,C)=>C<3?parseInt(n,10):n):g.indexOf("hsl")!==-1&&(i[1]=`${i[1]}%`,i[2]=`${i[2]}%`),g.indexOf("color")!==-1?i=`${I} ${i.join(" ")}`:i=`${i.join(", ")}`,`${g}(${i})`}function Blg(e){e=Ph(e);const{values:g}=e,I=g[0],i=g[1]/100,n=g[2]/100,C=i*Math.min(n,1-n),r=(s,A=(s+I/30)%12)=>n-C*Math.max(Math.min(A-3,9-A,1),-1);let o="rgb";const a=[Math.round(r(0)*255),Math.round(r(8)*255),Math.round(r(4)*255)];return e.type==="hsla"&&(o+="a",a.push(g[3])),xY({type:o,values:a})}function gue(e){e=Ph(e);let g=e.type==="hsl"||e.type==="hsla"?Ph(Blg(e)).values:e.values;return g=g.map(I=>(e.type!=="color"&&(I/=255),I<=.03928?I/12.92:((I+.055)/1.055)**2.4)),Number((.2126*g[0]+.7152*g[1]+.0722*g[2]).toFixed(3))}function Slg(e,g){const I=gue(e),i=gue(g);return(Math.max(I,i)+.05)/(Math.min(I,i)+.05)}function rA(e,g){return e=Ph(e),g=T8(g),(e.type==="rgb"||e.type==="hsl")&&(e.type+="a"),e.type==="color"?e.values[3]=`/${g}`:e.values[3]=g,xY(e)}function wlg(e,g){if(e=Ph(e),g=T8(g),e.type.indexOf("hsl")!==-1)e.values[2]*=1-g;else if(e.type.indexOf("rgb")!==-1||e.type.indexOf("color")!==-1)for(let I=0;I<3;I+=1)e.values[I]*=1-g;return xY(e)}function Vlg(e,g){if(e=Ph(e),g=T8(g),e.type.indexOf("hsl")!==-1)e.values[2]+=(100-e.values[2])*g;else if(e.type.indexOf("rgb")!==-1)for(let I=0;I<3;I+=1)e.values[I]+=(255-e.values[I])*g;else if(e.type.indexOf("color")!==-1)for(let I=0;I<3;I+=1)e.values[I]+=(1-e.values[I])*g;return xY(e)}function Rlg(e,g){return Ke({toolbar:{minHeight:56,[e.up("xs")]:{"@media (orientation: landscape)":{minHeight:48}},[e.up("sm")]:{minHeight:64}}},g)}const Wlg={black:"#000",white:"#fff"},hS=Wlg,Xlg={50:"#fafafa",100:"#f5f5f5",200:"#eeeeee",300:"#e0e0e0",400:"#bdbdbd",500:"#9e9e9e",600:"#757575",700:"#616161",800:"#424242",900:"#212121",A100:"#f5f5f5",A200:"#eeeeee",A400:"#bdbdbd",A700:"#616161"},Hlg=Xlg,Tlg={50:"#f3e5f5",100:"#e1bee7",200:"#ce93d8",300:"#ba68c8",400:"#ab47bc",500:"#9c27b0",600:"#8e24aa",700:"#7b1fa2",800:"#6a1b9a",900:"#4a148c",A100:"#ea80fc",A200:"#e040fb",A400:"#d500f9",A700:"#aa00ff"},sf=Tlg,Nlg={50:"#ffebee",100:"#ffcdd2",200:"#ef9a9a",300:"#e57373",400:"#ef5350",500:"#f44336",600:"#e53935",700:"#d32f2f",800:"#c62828",900:"#b71c1c",A100:"#ff8a80",A200:"#ff5252",A400:"#ff1744",A700:"#d50000"},lf=Nlg,klg={50:"#fff3e0",100:"#ffe0b2",200:"#ffcc80",300:"#ffb74d",400:"#ffa726",500:"#ff9800",600:"#fb8c00",700:"#f57c00",800:"#ef6c00",900:"#e65100",A100:"#ffd180",A200:"#ffab40",A400:"#ff9100",A700:"#ff6d00"},BZ=klg,Ylg={50:"#e3f2fd",100:"#bbdefb",200:"#90caf9",300:"#64b5f6",400:"#42a5f5",500:"#2196f3",600:"#1e88e5",700:"#1976d2",800:"#1565c0",900:"#0d47a1",A100:"#82b1ff",A200:"#448aff",A400:"#2979ff",A700:"#2962ff"},cf=Ylg,Klg={50:"#e1f5fe",100:"#b3e5fc",200:"#81d4fa",300:"#4fc3f7",400:"#29b6f6",500:"#03a9f4",600:"#039be5",700:"#0288d1",800:"#0277bd",900:"#01579b",A100:"#80d8ff",A200:"#40c4ff",A400:"#00b0ff",A700:"#0091ea"},uf=Klg,xlg={50:"#e8f5e9",100:"#c8e6c9",200:"#a5d6a7",300:"#81c784",400:"#66bb6a",500:"#4caf50",600:"#43a047",700:"#388e3c",800:"#2e7d32",900:"#1b5e20",A100:"#b9f6ca",A200:"#69f0ae",A400:"#00e676",A700:"#00c853"},df=xlg,Dlg=["mode","contrastThreshold","tonalOffset"],Iue={text:{primary:"rgba(0, 0, 0, 0.87)",secondary:"rgba(0, 0, 0, 0.6)",disabled:"rgba(0, 0, 0, 0.38)"},divider:"rgba(0, 0, 0, 0.12)",background:{paper:hS.white,default:hS.white},action:{active:"rgba(0, 0, 0, 0.54)",hover:"rgba(0, 0, 0, 0.04)",hoverOpacity:.04,selected:"rgba(0, 0, 0, 0.08)",selectedOpacity:.08,disabled:"rgba(0, 0, 0, 0.26)",disabledBackground:"rgba(0, 0, 0, 0.12)",disabledOpacity:.38,focus:"rgba(0, 0, 0, 0.12)",focusOpacity:.12,activatedOpacity:.12}},QF={text:{primary:hS.white,secondary:"rgba(255, 255, 255, 0.7)",disabled:"rgba(255, 255, 255, 0.5)",icon:"rgba(255, 255, 255, 0.5)"},divider:"rgba(255, 255, 255, 0.12)",background:{paper:"#121212",default:"#121212"},action:{active:hS.white,hover:"rgba(255, 255, 255, 0.08)",hoverOpacity:.08,selected:"rgba(255, 255, 255, 0.16)",selectedOpacity:.16,disabled:"rgba(255, 255, 255, 0.3)",disabledBackground:"rgba(255, 255, 255, 0.12)",disabledOpacity:.38,focus:"rgba(255, 255, 255, 0.12)",focusOpacity:.12,activatedOpacity:.24}};function iue(e,g,I,i){const n=i.light||i,C=i.dark||i*1.5;e[g]||(e.hasOwnProperty(I)?e[g]=e[I]:g==="light"?e.light=Vlg(e.main,n):g==="dark"&&(e.dark=wlg(e.main,C)))}function Flg(e="light"){return e==="dark"?{main:cf[200],light:cf[50],dark:cf[400]}:{main:cf[700],light:cf[400],dark:cf[800]}}function Elg(e="light"){return e==="dark"?{main:sf[200],light:sf[50],dark:sf[400]}:{main:sf[500],light:sf[300],dark:sf[700]}}function Mlg(e="light"){return e==="dark"?{main:lf[500],light:lf[300],dark:lf[700]}:{main:lf[700],light:lf[400],dark:lf[800]}}function zlg(e="light"){return e==="dark"?{main:uf[400],light:uf[300],dark:uf[700]}:{main:uf[700],light:uf[500],dark:uf[900]}}function Plg(e="light"){return e==="dark"?{main:df[400],light:df[300],dark:df[700]}:{main:df[800],light:df[500],dark:df[900]}}function Jlg(e="light"){return e==="dark"?{main:BZ[400],light:BZ[300],dark:BZ[700]}:{main:"#ed6c02",light:BZ[500],dark:BZ[900]}}function Olg(e){const{mode:g="light",contrastThreshold:I=3,tonalOffset:i=.2}=e,n=Qt(e,Dlg),C=e.primary||Flg(g),r=e.secondary||Elg(g),o=e.error||Mlg(g),a=e.info||zlg(g),s=e.success||Plg(g),A=e.warning||Jlg(g);function l(h){return Slg(h,QF.text.primary)>=I?QF.text.primary:Iue.text.primary}const c=({color:h,name:m,mainShade:f=500,lightShade:b=300,darkShade:p=700})=>{if(h=Ke({},h),!h.main&&h[f]&&(h.main=h[f]),!h.hasOwnProperty("main"))throw new Error(Uc(11,m?` (${m})`:"",f));if(typeof h.main!="string")throw new Error(Uc(12,m?` (${m})`:"",JSON.stringify(h.main)));return iue(h,"light",b,i),iue(h,"dark",p,i),h.contrastText||(h.contrastText=l(h.main)),h},u={dark:QF,light:Iue};return MC(Ke({common:Ke({},hS),mode:g,primary:c({color:C,name:"primary"}),secondary:c({color:r,name:"secondary",mainShade:"A400",lightShade:"A200",darkShade:"A700"}),error:c({color:o,name:"error"}),warning:c({color:A,name:"warning"}),info:c({color:a,name:"info"}),success:c({color:s,name:"success"}),grey:Hlg,contrastThreshold:I,getContrastText:l,augmentColor:c,tonalOffset:i},u[g]),n)}const _lg=["fontFamily","fontSize","fontWeightLight","fontWeightRegular","fontWeightMedium","fontWeightBold","htmlFontSize","allVariants","pxToRem"];function Llg(e){return Math.round(e*1e5)/1e5}const nue={textTransform:"uppercase"},Cue='"Roboto", "Helvetica", "Arial", sans-serif';function Ulg(e,g){const I=typeof g=="function"?g(e):g,{fontFamily:i=Cue,fontSize:n=14,fontWeightLight:C=300,fontWeightRegular:r=400,fontWeightMedium:o=500,fontWeightBold:a=700,htmlFontSize:s=16,allVariants:A,pxToRem:l}=I,c=Qt(I,_lg),u=n/14,d=l||(f=>`${f/s*u}rem`),h=(f,b,p,y,Z)=>Ke({fontFamily:i,fontWeight:f,fontSize:d(b),lineHeight:p},i===Cue?{letterSpacing:`${Llg(y/b)}em`}:{},Z,A),m={h1:h(C,96,1.167,-1.5),h2:h(C,60,1.2,-.5),h3:h(r,48,1.167,0),h4:h(r,34,1.235,.25),h5:h(r,24,1.334,0),h6:h(o,20,1.6,.15),subtitle1:h(r,16,1.75,.15),subtitle2:h(o,14,1.57,.1),body1:h(r,16,1.5,.15),body2:h(r,14,1.43,.15),button:h(o,14,1.75,.4,nue),caption:h(r,12,1.66,.4),overline:h(r,12,2.66,1,nue),inherit:{fontFamily:"inherit",fontWeight:"inherit",fontSize:"inherit",lineHeight:"inherit",letterSpacing:"inherit"}};return MC(Ke({htmlFontSize:s,pxToRem:d,fontFamily:i,fontSize:n,fontWeightLight:C,fontWeightRegular:r,fontWeightMedium:o,fontWeightBold:a},m),c,{clone:!1})}const Qlg=.2,jlg=.14,$lg=.12;function BI(...e){return[`${e[0]}px ${e[1]}px ${e[2]}px ${e[3]}px rgba(0,0,0,${Qlg})`,`${e[4]}px ${e[5]}px ${e[6]}px ${e[7]}px rgba(0,0,0,${jlg})`,`${e[8]}px ${e[9]}px ${e[10]}px ${e[11]}px rgba(0,0,0,${$lg})`].join(",")}const qlg=["none",BI(0,2,1,-1,0,1,1,0,0,1,3,0),BI(0,3,1,-2,0,2,2,0,0,1,5,0),BI(0,3,3,-2,0,3,4,0,0,1,8,0),BI(0,2,4,-1,0,4,5,0,0,1,10,0),BI(0,3,5,-1,0,5,8,0,0,1,14,0),BI(0,3,5,-1,0,6,10,0,0,1,18,0),BI(0,4,5,-2,0,7,10,1,0,2,16,1),BI(0,5,5,-3,0,8,10,1,0,3,14,2),BI(0,5,6,-3,0,9,12,1,0,3,16,2),BI(0,6,6,-3,0,10,14,1,0,4,18,3),BI(0,6,7,-4,0,11,15,1,0,4,20,3),BI(0,7,8,-4,0,12,17,2,0,5,22,4),BI(0,7,8,-4,0,13,19,2,0,5,24,4),BI(0,7,9,-4,0,14,21,2,0,5,26,4),BI(0,8,9,-5,0,15,22,2,0,6,28,5),BI(0,8,10,-5,0,16,24,2,0,6,30,5),BI(0,8,11,-5,0,17,26,2,0,6,32,5),BI(0,9,11,-5,0,18,28,2,0,7,34,6),BI(0,9,12,-6,0,19,29,2,0,7,36,6),BI(0,10,13,-6,0,20,31,3,0,8,38,7),BI(0,10,13,-6,0,21,33,3,0,8,40,7),BI(0,10,14,-6,0,22,35,3,0,8,42,7),BI(0,11,14,-7,0,23,36,3,0,9,44,8),BI(0,11,15,-7,0,24,38,3,0,9,46,8)],ecg=qlg,tcg=["duration","easing","delay"],gcg={easeInOut:"cubic-bezier(0.4, 0, 0.2, 1)",easeOut:"cubic-bezier(0.0, 0, 0.2, 1)",easeIn:"cubic-bezier(0.4, 0, 1, 1)",sharp:"cubic-bezier(0.4, 0, 0.6, 1)"},kNe={shortest:150,shorter:200,short:250,standard:300,complex:375,enteringScreen:225,leavingScreen:195};function rue(e){return`${Math.round(e)}ms`}function Icg(e){if(!e)return 0;const g=e/36;return Math.round((4+15*g**.25+g/5)*10)}function icg(e){const g=Ke({},gcg,e.easing),I=Ke({},kNe,e.duration);return Ke({getAutoHeightDuration:Icg,create:(n=["all"],C={})=>{const{duration:r=I.standard,easing:o=g.easeInOut,delay:a=0}=C;return Qt(C,tcg),(Array.isArray(n)?n:[n]).map(s=>`${s} ${typeof r=="string"?r:rue(r)} ${o} ${typeof a=="string"?a:rue(a)}`).join(",")}},e,{easing:g,duration:I})}const ncg={mobileStepper:1e3,fab:1050,speedDial:1050,appBar:1100,drawer:1200,modal:1300,snackbar:1400,tooltip:1500},Ccg=ncg,rcg=["breakpoints","mixins","spacing","palette","transitions","typography","shape"];function ocg(e={},...g){const{mixins:I={},palette:i={},transitions:n={},typography:C={}}=e,r=Qt(e,rcg);if(e.vars)throw new Error(Uc(18));const o=Olg(i),a=X8(e);let s=MC(a,{mixins:Rlg(a.breakpoints,I),palette:o,shadows:ecg.slice(),typography:Ulg(o,C),transitions:icg(n),zIndex:Ke({},Ccg)});return s=MC(s,r),s=g.reduce((A,l)=>MC(A,l),s),s.unstable_sxConfig=Ke({},KY,r==null?void 0:r.unstable_sxConfig),s.unstable_sx=function(l){return W8({sx:l,theme:this})},s}const acg=ocg(),DY=acg;function fy(){const e=H8(DY);return e[hY]||e}function gi({props:e,name:g}){return Glg({props:e,name:g,defaultTheme:DY,themeId:hY})}const va=e=>Yv(e)&&e!=="classes",Acg=Yv,scg=ylg({themeId:hY,defaultTheme:DY,rootShouldForwardProp:va}),qt=scg,lcg=e=>{let g;return e<1?g=5.11916*e**2:g=4.5*Math.log(e+1)+2,(g/100).toFixed(2)},oue=lcg;function YNe(e,g,I=void 0){const i={};return Object.keys(e).forEach(n=>{i[n]=e[n].reduce((C,r)=>{if(r){const o=g(r);o!==""&&C.push(o),I&&I[r]&&C.push(I[r])}return C},[]).join(" ")}),i}function ccg(e){return typeof e=="string"}function ucg(e,g,I){return e===void 0||ccg(e)?g:Ke({},g,{ownerState:Ke({},g.ownerState,I)})}function dcg(e,g=[]){if(e===void 0)return{};const I={};return Object.keys(e).filter(i=>i.match(/^on[A-Z]/)&&typeof e[i]=="function"&&!g.includes(i)).forEach(i=>{I[i]=e[i]}),I}function hcg(e,g,I){return typeof e=="function"?e(g,I):e}function KNe(e){return e&&e.ownerDocument||document}function mcg(e,g){typeof e=="function"?e(g):e&&(e.current=g)}const fcg=typeof window<"u"?U.useLayoutEffect:U.useEffect,xNe=fcg;let aue=0;function pcg(e){const[g,I]=U.useState(e),i=e||g;return U.useEffect(()=>{g==null&&(aue+=1,I(`mui-${aue}`))},[g]),i}const Aue=zW["useId".toString()];function bcg(e){if(Aue!==void 0){const g=Aue();return e??g}return pcg(e)}function mS(e){const g=U.useRef(e);return xNe(()=>{g.current=e}),U.useRef((...I)=>(0,g.current)(...I)).current}function N8(...e){return U.useMemo(()=>e.every(g=>g==null)?null:g=>{e.forEach(I=>{mcg(I,g)})},e)}const sue=e=>e,ycg=()=>{let e=sue;return{configure(g){e=g},generate(g){return e(g)},reset(){e=sue}}},Zcg=ycg(),Gcg=Zcg,vcg={active:"active",checked:"checked",completed:"completed",disabled:"disabled",error:"error",expanded:"expanded",focused:"focused",focusVisible:"focusVisible",open:"open",readOnly:"readOnly",required:"required",selected:"selected"};function k8(e,g,I="Mui"){const i=vcg[g];return i?`${I}-${i}`:`${Gcg.generate(e)}-${g}`}function DNe(e,g,I="Mui"){const i={};return g.forEach(n=>{i[n]=k8(e,n,I)}),i}function lue(e){if(e===void 0)return{};const g={};return Object.keys(e).filter(I=>!(I.match(/^on[A-Z]/)&&typeof e[I]=="function")).forEach(I=>{g[I]=e[I]}),g}function Bcg(e){const{getSlotProps:g,additionalProps:I,externalSlotProps:i,externalForwardedProps:n,className:C}=e;if(!g){const u=ug(I==null?void 0:I.className,C,n==null?void 0:n.className,i==null?void 0:i.className),d=Ke({},I==null?void 0:I.style,n==null?void 0:n.style,i==null?void 0:i.style),h=Ke({},I,n,i);return u.length>0&&(h.className=u),Object.keys(d).length>0&&(h.style=d),{props:h,internalRef:void 0}}const r=dcg(Ke({},n,i)),o=lue(i),a=lue(n),s=g(r),A=ug(s==null?void 0:s.className,I==null?void 0:I.className,C,n==null?void 0:n.className,i==null?void 0:i.className),l=Ke({},s==null?void 0:s.style,I==null?void 0:I.style,n==null?void 0:n.style,i==null?void 0:i.style),c=Ke({},s,I,a,o);return A.length>0&&(c.className=A),Object.keys(l).length>0&&(c.style=l),{props:c,internalRef:s.ref}}const Scg=["elementType","externalSlotProps","ownerState","skipResolvingSlotProps"];function wcg(e){var g;const{elementType:I,externalSlotProps:i,ownerState:n,skipResolvingSlotProps:C=!1}=e,r=Qt(e,Scg),o=C?{}:hcg(i,n),{props:a,internalRef:s}=Bcg(Ke({},r,{externalSlotProps:o})),A=N8(s,o==null?void 0:o.ref,(g=e.additionalProps)==null?void 0:g.ref);return ucg(I,Ke({},a,{ref:A}),n)}function Vcg(e){return k8("MuiTreeView",e)}DNe("MuiTreeView",["root"]);const FNe={instance:null,multiSelect:!1,disabledItemsFocusable:!1,treeId:void 0,icons:{defaultCollapseIcon:null,defaultExpandIcon:null,defaultParentIcon:null,defaultEndIcon:null}},ENe=U.createContext(FNe),Rcg=(e,g)=>{const I=U.useRef({}),[i,n]=U.useState(()=>{const r={};return e.forEach(o=>{o.models&&Object.entries(o.models).forEach(([a,s])=>{I.current[a]={controlledProp:s.controlledProp,defaultProp:s.defaultProp,isControlled:g[s.controlledProp]!==void 0},r[a]=g[s.defaultProp]})}),r});return Object.fromEntries(Object.entries(I.current).map(([r,o])=>{const a=o.isControlled?g[o.controlledProp]:i[r];return[r,{value:a,setValue:s=>{o.isControlled||n(A=>Ke({},A,{[r]:s}))}}]}))};class Wcg{constructor(){this.maxListeners=20,this.warnOnce=!1,this.events={}}on(g,I,i={}){let n=this.events[g];n||(n={highPriority:new Map,regular:new Map},this.events[g]=n),i.isFirst?n.highPriority.set(I,!0):n.regular.set(I,!0)}removeListener(g,I){this.events[g]&&(this.events[g].regular.delete(I),this.events[g].highPriority.delete(I))}removeAllListeners(){this.events={}}emit(g,...I){const i=this.events[g];if(!i)return;const n=Array.from(i.highPriority.keys()),C=Array.from(i.regular.keys());for(let r=n.length-1;r>=0;r-=1){const o=n[r];i.highPriority.has(o)&&o.apply(this,I)}for(let r=0;r{const I=e.getNode(g),i=e.getNavigableChildrenIds(I.parentId),n=i.indexOf(g);if(n===0)return I.parentId;let C=i[n-1];for(;e.isNodeExpanded(C)&&e.getNavigableChildrenIds(C).length>0;)C=e.getNavigableChildrenIds(C).pop();return C},GG=(e,g)=>{if(e.isNodeExpanded(g)&&e.getNavigableChildrenIds(g).length>0)return e.getNavigableChildrenIds(g)[0];let I=e.getNode(g);for(;I!=null;){const i=e.getNavigableChildrenIds(I.parentId),n=i[i.indexOf(I.id)+1];if(n)return n;I=e.getNode(I.parentId)}return null},K_=e=>{let g=e.getNavigableChildrenIds(null).pop();for(;e.isNodeExpanded(g);)g=e.getNavigableChildrenIds(g).pop();return g},x_=e=>e.getNavigableChildrenIds(null)[0],py=(e,g)=>{Object.assign(e,g)},Xcg=e=>e.isPropagationStopped!==void 0,Hcg=({instance:e})=>{const[g]=U.useState(()=>new Wcg),I=U.useCallback((...n)=>{const[C,r,o={}]=n;o.defaultMuiPrevented=!1,!(Xcg(o)&&o.isPropagationStopped())&&g.emit(C,r,o)},[g]),i=U.useCallback((n,C)=>(g.on(n,C),()=>{g.removeListener(n,C)}),[g]);py(e,{$$publishEvent:I,$$subscribeEvent:i})},Tcg=[Hcg],Ncg=e=>{const g=[...Tcg,...e.plugins],I=g.reduce((d,h)=>h.getDefaultizedParams?h.getDefaultizedParams(d):d,e),i=Rcg(g,I),C=U.useRef({}).current,r=U.useRef(null),o=N8(r,e.rootRef),[a,s]=U.useState(()=>{const d={};return g.forEach(h=>{h.getInitialState&&Object.assign(d,h.getInitialState(I))}),d}),A=[];let l=FNe;const c=d=>{const h=d({instance:C,params:I,state:a,setState:s,rootRef:r,models:i})||{};h.getRootProps&&A.push(h.getRootProps),h.contextValue&&(l=h.contextValue)};return g.forEach(c),{getRootProps:(d={})=>{const h=Ke({role:"tree",tabIndex:0},d,{ref:o});return A.forEach(m=>{Object.assign(h,m(d))}),h},rootRef:o,contextValue:l}},kcg=["element"];function Ycg(e,g){for(let I=0;I{g.current=e},[e]),g.current}const cue=()=>{};function Dcg(e){const[,g]=U.useState(),{registerDescendant:I=cue,unregisterDescendant:i=cue,descendants:n=[],parentId:C=null}=U.useContext(MNe),r=Ycg(n,s=>s.element===e.element),o=xcg(n),a=n.some((s,A)=>o&&o[A]&&o[A].element!==s.element);return xNe(()=>{if(e.element)return I(Ke({},e,{index:r})),()=>{i(e.element)};g({})},[I,i,r,a,e]),{parentId:C,index:r}}function zNe(e){const{children:g,id:I}=e,[i,n]=U.useState([]),C=U.useCallback(a=>{let{element:s}=a,A=Qt(a,kcg);n(l=>{if(l.length===0)return[Ke({},A,{element:s,index:0})];const c=Kcg(l,s);let u;if(l[c]&&l[c].element===s)u=l;else{const d=Ke({},A,{element:s,index:c});u=l.slice(),u.splice(c,0,d)}return u.forEach((d,h)=>{d.index=h}),u})},[]),r=U.useCallback(a=>{n(s=>s.filter(A=>a!==A.element))},[]),o=U.useMemo(()=>({descendants:i,registerDescendant:C,unregisterDescendant:r,parentId:I}),[i,C,r,I]);return Oe.jsx(MNe.Provider,{value:o,children:g})}function Fcg(e){const{value:g,children:I}=e;return Oe.jsx(ENe.Provider,{value:g,children:Oe.jsx(zNe,{children:I})})}const Ecg=(e,g,I)=>{e.$$publishEvent(g,I)},Mcg=({instance:e,params:g})=>{const I=U.useRef({}),i=U.useCallback(s=>I.current[s],[]),n=U.useCallback(s=>{I.current[s.id]=s},[]),C=U.useCallback(s=>{const A=Ke({},I.current);delete A[s],I.current=A,Ecg(e,"removeNode",{id:s})},[e]),r=U.useCallback(s=>{if(s==null)return!1;let A=e.getNode(s);if(!A)return!1;if(A.disabled)return!0;for(;A.parentId!=null;)if(A=e.getNode(A.parentId),A.disabled)return!0;return!1},[e]),o=mS(s=>Object.values(I.current).filter(A=>A.parentId===s).sort((A,l)=>A.index-l.index).map(A=>A.id));py(e,{getNode:i,updateNode:n,removeNode:C,getChildrenIds:o,getNavigableChildrenIds:s=>{let A=e.getChildrenIds(s);return g.disabledItemsFocusable||(A=A.filter(l=>!e.isNodeDisabled(l))),A},isNodeDisabled:r})},Y8=({instance:e,params:g,models:I})=>{const i=U.useCallback(o=>Array.isArray(I.expanded.value)?I.expanded.value.indexOf(o)!==-1:!1,[I.expanded.value]),n=U.useCallback(o=>{var a;return!!((a=e.getNode(o))!=null&&a.expandable)},[e]),C=mS((o,a)=>{if(a==null)return;let s;I.expanded.value.indexOf(a)!==-1?s=I.expanded.value.filter(A=>A!==a):s=[a].concat(I.expanded.value),g.onNodeToggle&&g.onNodeToggle(o,s),I.expanded.setValue(s)});py(e,{isNodeExpanded:i,isNodeExpandable:n,toggleNodeExpansion:C,expandAllSiblings:(o,a)=>{const s=e.getNode(a),l=e.getChildrenIds(s.parentId).filter(u=>e.isNodeExpandable(u)&&!e.isNodeExpanded(u)),c=I.expanded.value.concat(l);l.length>0&&(I.expanded.setValue(c),g.onNodeToggle&&g.onNodeToggle(o,c))}})};Y8.models={expanded:{controlledProp:"expanded",defaultProp:"defaultExpanded"}};const zcg=[];Y8.getDefaultizedParams=e=>{var g;return Ke({},e,{defaultExpanded:(g=e.defaultExpanded)!=null?g:zcg})};const Pcg=(e,g,I)=>{if(g===I)return[g,I];const i=e.getNode(g),n=e.getNode(I);if(i.parentId===n.id||n.parentId===i.id)return n.parentId===i.id?[i.id,n.id]:[n.id,i.id];const C=[i.id],r=[n.id];let o=i.parentId,a=n.parentId,s=r.indexOf(o)!==-1,A=C.indexOf(a)!==-1,l=!0,c=!0;for(;!A&&!s;)l&&(C.push(o),s=r.indexOf(o)!==-1,l=o!==null,!s&&l&&(o=e.getNode(o).parentId)),c&&!s&&(r.push(a),A=C.indexOf(a)!==-1,c=a!==null,!A&&c&&(a=e.getNode(a).parentId));const u=s?o:a,d=e.getChildrenIds(u),h=C[C.indexOf(u)-1],m=r[r.indexOf(u)-1];return d.indexOf(h){const i=U.useRef(null),n=U.useRef(!1),C=U.useRef([]),r=d=>Array.isArray(I.selected.value)?I.selected.value.indexOf(d)!==-1:I.selected.value===d,o=(d,h,m=!1)=>{if(!g.disableSelection){if(m){if(Array.isArray(I.selected.value)){let f;I.selected.value.indexOf(h)!==-1?f=I.selected.value.filter(b=>b!==h):f=[h].concat(I.selected.value),g.onNodeSelect&&g.onNodeSelect(d,f),I.selected.setValue(f)}}else{const f=g.multiSelect?[h]:h;g.onNodeSelect&&g.onNodeSelect(d,f),I.selected.setValue(f)}i.current=h,n.current=!1,C.current=[]}},a=(d,h)=>{const[m,f]=Pcg(e,d,h),b=[m];let p=m;for(;p!==f;)p=GG(e,p),b.push(p);return b},s=(d,h)=>{let m=I.selected.value.slice();const{start:f,next:b,current:p}=h;!b||!p||(C.current.indexOf(p)===-1&&(C.current=[]),n.current?C.current.indexOf(b)!==-1?(m=m.filter(y=>y===f||y!==p),C.current=C.current.filter(y=>y===f||y!==p)):(m.push(b),C.current.push(b)):(m.push(b),C.current.push(p,b)),g.onNodeSelect&&g.onNodeSelect(d,m),I.selected.setValue(m))},A=(d,h)=>{let m=I.selected.value.slice();const{start:f,end:b}=h;n.current&&(m=m.filter(Z=>C.current.indexOf(Z)===-1));let p=a(f,b);p=p.filter(Z=>!e.isNodeDisabled(Z)),C.current=p;let y=m.concat(p);y=y.filter((Z,B)=>y.indexOf(Z)===B),g.onNodeSelect&&g.onNodeSelect(d,y),I.selected.setValue(y)};return py(e,{isNodeSelected:r,selectNode:o,selectRange:(d,h,m=!1)=>{if(g.disableSelection)return;const{start:f=i.current,end:b,current:p}=h;m?s(d,{start:f,next:b,current:p}):f!=null&&b!=null&&A(d,{start:f,end:b}),n.current=!0},rangeSelectToLast:(d,h)=>{i.current||(i.current=h);const m=n.current?i.current:h;e.selectRange(d,{start:m,end:K_(e)})},rangeSelectToFirst:(d,h)=>{i.current||(i.current=h);const m=n.current?i.current:h;e.selectRange(d,{start:m,end:x_(e)})}}),{getRootProps:()=>({"aria-multiselectable":g.multiSelect})}};K8.models={selected:{controlledProp:"selected",defaultProp:"defaultSelected"}};const Jcg=[];K8.getDefaultizedParams=e=>{var g,I,i;return Ke({},e,{disableSelection:(g=e.disableSelection)!=null?g:!1,multiSelect:(I=e.multiSelect)!=null?I:!1,defaultSelected:(i=e.defaultSelected)!=null?i:e.multiSelect?Jcg:null})};const uue=1e3;class Ocg{constructor(g=uue){this.timeouts=new Map,this.cleanupTimeout=uue,this.cleanupTimeout=g}register(g,I,i){this.timeouts||(this.timeouts=new Map);const n=setTimeout(()=>{typeof I=="function"&&I(),this.timeouts.delete(i.cleanupToken)},this.cleanupTimeout);this.timeouts.set(i.cleanupToken,n)}unregister(g){const I=this.timeouts.get(g.cleanupToken);I&&(this.timeouts.delete(g.cleanupToken),clearTimeout(I))}reset(){this.timeouts&&(this.timeouts.forEach((g,I)=>{this.unregister({cleanupToken:I})}),this.timeouts=void 0)}}class _cg{constructor(){this.registry=new FinalizationRegistry(g=>{typeof g=="function"&&g()})}register(g,I,i){this.registry.register(g,I,i)}unregister(g){this.registry.unregister(g)}reset(){}}class Lcg{}function Ucg(e){let g=0;return function(i,n,C){e.registry===null&&(e.registry=typeof FinalizationRegistry<"u"?new _cg:new Ocg);const[r]=U.useState(new Lcg),o=U.useRef(null),a=U.useRef();a.current=C;const s=U.useRef(null);if(!o.current&&a.current){const A=(l,c)=>{if(!c.defaultMuiPrevented){var u;(u=a.current)==null||u.call(a,l,c)}};o.current=i.$$subscribeEvent(n,A),g+=1,s.current={cleanupToken:g},e.registry.register(r,()=>{var l;(l=o.current)==null||l.call(o),o.current=null,s.current=null},s.current)}else!a.current&&o.current&&(o.current(),o.current=null,s.current&&(e.registry.unregister(s.current),s.current=null));U.useEffect(()=>{if(!o.current&&a.current){const A=(l,c)=>{if(!c.defaultMuiPrevented){var u;(u=a.current)==null||u.call(a,l,c)}};o.current=i.$$subscribeEvent(n,A)}return s.current&&e.registry&&(e.registry.unregister(s.current),s.current=null),()=>{var A;(A=o.current)==null||A.call(o),o.current=null}},[i,n])}}const Qcg={registry:null},jcg=Ucg(Qcg),x8=({instance:e,params:g,state:I,setState:i,models:n,rootRef:C})=>{const r=mS(u=>{const d=typeof u=="function"?u(I.focusedNodeId):u;i(h=>Ke({},h,{focusedNodeId:d}))}),o=U.useCallback(u=>I.focusedNodeId===u,[I.focusedNodeId]),a=mS((u,d)=>{d&&(r(d),g.onNodeFocus&&g.onNodeFocus(u,d))});py(e,{isNodeFocused:o,focusNode:a}),jcg(e,"removeNode",({id:u})=>{r(d=>d===u&&C.current===KNe(C.current).activeElement?e.getChildrenIds(null)[0]:d)});const s=u=>d=>{var h;if((h=u.onFocus)==null||h.call(u,d),d.target===d.currentTarget){const m=b=>{const p=e.getNode(b);return p&&(p.parentId==null||e.isNodeExpanded(p.parentId))};let f;Array.isArray(n.selected.value)?f=n.selected.value.find(m):n.selected.value!=null&&m(n.selected.value)&&(f=n.selected.value),f==null&&(f=e.getNavigableChildrenIds(null)[0]),e.focusNode(d,f)}},A=u=>d=>{var h;(h=u.onBlur)==null||h.call(u,d),r(null)},l=e.getNode(I.focusedNodeId),c=l?l.idAttribute:null;return{getRootProps:u=>({onFocus:s(u),onBlur:A(u),"aria-activedescendant":c??void 0})}};x8.getInitialState=()=>({focusedNodeId:null});x8.getDefaultizedParams=e=>{var g;return Ke({},e,{disabledItemsFocusable:(g=e.disabledItemsFocusable)!=null?g:!1})};function $cg(e){return e&&e.length===1&&e.match(/\S/)}function due(e,g,I){for(let i=g;i{const n=fy().direction==="rtl",C=U.useRef({}),r=mS((u,d)=>(C.current[u]=d,()=>{const h=Ke({},C.current);delete h[u],C.current=h}));py(e,{mapFirstChar:r});const o=u=>(I.focusedNodeId!=null&&e.isNodeExpandable(I.focusedNodeId)&&(e.isNodeExpanded(I.focusedNodeId)?e.focusNode(u,GG(e,I.focusedNodeId)):e.isNodeDisabled(I.focusedNodeId)||e.toggleNodeExpansion(u,I.focusedNodeId)),!0),a=u=>{if(I.focusedNodeId==null)return!1;if(e.isNodeExpanded(I.focusedNodeId)&&!e.isNodeDisabled(I.focusedNodeId))return e.toggleNodeExpansion(u,I.focusedNodeId),!0;const d=e.getNode(I.focusedNodeId).parentId;return d?(e.focusNode(u,d),!0):!1},s=(u,d,h)=>{let m,f;const b=h.toLowerCase(),p=[],y=[];Object.keys(C.current).forEach(Z=>{const B=e.getNode(Z),G=B.parentId?e.isNodeExpanded(B.parentId):!0,v=g.disabledItemsFocusable?!1:e.isNodeDisabled(Z);G&&!v&&(p.push(Z),y.push(C.current[Z]))}),m=p.indexOf(d)+1,m>=p.length&&(m=0),f=due(y,m,b),f===-1&&(f=due(y,0,b)),f>-1&&e.focusNode(u,p[f])},A=(u,d)=>{e.isNodeDisabled(GG(e,d))||e.selectRange(u,{end:GG(e,d),current:d},!0)},l=(u,d)=>{e.isNodeDisabled(jF(e,d))||e.selectRange(u,{end:jF(e,d),current:d},!0)},c=u=>d=>{var h;(h=u.onKeyDown)==null||h.call(u,d);let m=!1;const f=d.key;if(d.altKey||d.currentTarget!==d.target||I.focusedNodeId==null)return;const b=d.ctrlKey||d.metaKey;switch(f){case" ":!g.disableSelection&&!e.isNodeDisabled(I.focusedNodeId)&&(m=!0,g.multiSelect&&d.shiftKey?e.selectRange(d,{end:I.focusedNodeId}):g.multiSelect?e.selectNode(d,I.focusedNodeId,!0):e.selectNode(d,I.focusedNodeId)),d.stopPropagation();break;case"Enter":e.isNodeDisabled(I.focusedNodeId)||(e.isNodeExpandable(I.focusedNodeId)?(e.toggleNodeExpansion(d,I.focusedNodeId),m=!0):g.disableSelection||(m=!0,g.multiSelect?e.selectNode(d,I.focusedNodeId,!0):e.selectNode(d,I.focusedNodeId))),d.stopPropagation();break;case"ArrowDown":g.multiSelect&&d.shiftKey&&!g.disableSelection&&A(d,I.focusedNodeId),e.focusNode(d,GG(e,I.focusedNodeId)),m=!0;break;case"ArrowUp":g.multiSelect&&d.shiftKey&&!g.disableSelection&&l(d,I.focusedNodeId),e.focusNode(d,jF(e,I.focusedNodeId)),m=!0;break;case"ArrowRight":n?m=a(d):m=o(d);break;case"ArrowLeft":n?m=o(d):m=a(d);break;case"Home":g.multiSelect&&b&&d.shiftKey&&!g.disableSelection&&!e.isNodeDisabled(I.focusedNodeId)&&e.rangeSelectToFirst(d,I.focusedNodeId),e.focusNode(d,x_(e)),m=!0;break;case"End":g.multiSelect&&b&&d.shiftKey&&!g.disableSelection&&!e.isNodeDisabled(I.focusedNodeId)&&e.rangeSelectToLast(d,I.focusedNodeId),e.focusNode(d,K_(e)),m=!0;break;default:f==="*"?(e.expandAllSiblings(d,I.focusedNodeId),m=!0):g.multiSelect&&b&&f.toLowerCase()==="a"&&!g.disableSelection?(e.selectRange(d,{start:x_(e),end:K_(e)}),m=!0):!b&&!d.shiftKey&&$cg(f)&&(s(d,I.focusedNodeId,f),m=!0)}m&&(d.preventDefault(),d.stopPropagation())};return{getRootProps:u=>({onKeyDown:c(u)})}},eug=({instance:e,params:g})=>{const I=bcg(g.id);return{getRootProps:()=>({id:I}),contextValue:{treeId:I,instance:e,multiSelect:g.multiSelect,disabledItemsFocusable:g.disabledItemsFocusable,icons:{defaultCollapseIcon:g.defaultCollapseIcon,defaultEndIcon:g.defaultEndIcon,defaultExpandIcon:g.defaultExpandIcon,defaultParentIcon:g.defaultParentIcon}}}},tug=[Mcg,Y8,K8,x8,qcg,eug],gug=["disabledItemsFocusable","expanded","defaultExpanded","onNodeToggle","onNodeFocus","disableSelection","defaultSelected","selected","multiSelect","onNodeSelect","id","defaultCollapseIcon","defaultEndIcon","defaultExpandIcon","defaultParentIcon","children"],Iug=e=>{const{classes:g}=e;return YNe({root:["root"]},Vcg,g)},hue=qt("ul",{name:"MuiTreeView",slot:"Root",overridesResolver:(e,g)=>g.root})({padding:0,margin:0,listStyle:"none",outline:0}),PNe=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiTreeView"}),n=i,C=i,{disabledItemsFocusable:r,expanded:o,defaultExpanded:a,onNodeToggle:s,onNodeFocus:A,disableSelection:l,defaultSelected:c,selected:u,multiSelect:d,onNodeSelect:h,id:m,defaultCollapseIcon:f,defaultEndIcon:b,defaultExpandIcon:p,defaultParentIcon:y,children:Z}=C,B=Qt(C,gug),{getRootProps:G,contextValue:v}=Ncg({disabledItemsFocusable:r,expanded:o,defaultExpanded:a,onNodeToggle:s,onNodeFocus:A,disableSelection:l,defaultSelected:c,selected:u,multiSelect:d,onNodeSelect:h,id:m,defaultCollapseIcon:f,defaultEndIcon:b,defaultExpandIcon:p,defaultParentIcon:y,plugins:tug,rootRef:I}),w=Iug(i),V=wcg({elementType:hue,externalSlotProps:{},externalForwardedProps:B,className:w.root,getSlotProps:G,ownerState:n});return Oe.jsx(Fcg,{value:v,children:Oe.jsx(hue,Ke({},V,{children:Z}))})});function D_(e,g){return D_=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(i,n){return i.__proto__=n,i},D_(e,g)}function JNe(e,g){e.prototype=Object.create(g.prototype),e.prototype.constructor=e,D_(e,g)}const mue={disabled:!1},JH=N.createContext(null);var iug=function(g){return g.scrollTop},vG="unmounted",td="exited",gd="entering",zf="entered",F_="exiting",sl=function(e){JNe(g,e);function g(i,n){var C;C=e.call(this,i,n)||this;var r=n,o=r&&!r.isMounting?i.enter:i.appear,a;return C.appearStatus=null,i.in?o?(a=td,C.appearStatus=gd):a=zf:i.unmountOnExit||i.mountOnEnter?a=vG:a=td,C.state={status:a},C.nextCallback=null,C}g.getDerivedStateFromProps=function(n,C){var r=n.in;return r&&C.status===vG?{status:td}:null};var I=g.prototype;return I.componentDidMount=function(){this.updateStatus(!0,this.appearStatus)},I.componentDidUpdate=function(n){var C=null;if(n!==this.props){var r=this.state.status;this.props.in?r!==gd&&r!==zf&&(C=gd):(r===gd||r===zf)&&(C=F_)}this.updateStatus(!1,C)},I.componentWillUnmount=function(){this.cancelNextCallback()},I.getTimeouts=function(){var n=this.props.timeout,C,r,o;return C=r=o=n,n!=null&&typeof n!="number"&&(C=n.exit,r=n.enter,o=n.appear!==void 0?n.appear:r),{exit:C,enter:r,appear:o}},I.updateStatus=function(n,C){if(n===void 0&&(n=!1),C!==null)if(this.cancelNextCallback(),C===gd){if(this.props.unmountOnExit||this.props.mountOnEnter){var r=this.props.nodeRef?this.props.nodeRef.current:jI.findDOMNode(this);r&&iug(r)}this.performEnter(n)}else this.performExit();else this.props.unmountOnExit&&this.state.status===td&&this.setState({status:vG})},I.performEnter=function(n){var C=this,r=this.props.enter,o=this.context?this.context.isMounting:n,a=this.props.nodeRef?[o]:[jI.findDOMNode(this),o],s=a[0],A=a[1],l=this.getTimeouts(),c=o?l.appear:l.enter;if(!n&&!r||mue.disabled){this.safeSetState({status:zf},function(){C.props.onEntered(s)});return}this.props.onEnter(s,A),this.safeSetState({status:gd},function(){C.props.onEntering(s,A),C.onTransitionEnd(c,function(){C.safeSetState({status:zf},function(){C.props.onEntered(s,A)})})})},I.performExit=function(){var n=this,C=this.props.exit,r=this.getTimeouts(),o=this.props.nodeRef?void 0:jI.findDOMNode(this);if(!C||mue.disabled){this.safeSetState({status:td},function(){n.props.onExited(o)});return}this.props.onExit(o),this.safeSetState({status:F_},function(){n.props.onExiting(o),n.onTransitionEnd(r.exit,function(){n.safeSetState({status:td},function(){n.props.onExited(o)})})})},I.cancelNextCallback=function(){this.nextCallback!==null&&(this.nextCallback.cancel(),this.nextCallback=null)},I.safeSetState=function(n,C){C=this.setNextCallback(C),this.setState(n,C)},I.setNextCallback=function(n){var C=this,r=!0;return this.nextCallback=function(o){r&&(r=!1,C.nextCallback=null,n(o))},this.nextCallback.cancel=function(){r=!1},this.nextCallback},I.onTransitionEnd=function(n,C){this.setNextCallback(C);var r=this.props.nodeRef?this.props.nodeRef.current:jI.findDOMNode(this),o=n==null&&!this.props.addEndListener;if(!r||o){setTimeout(this.nextCallback,0);return}if(this.props.addEndListener){var a=this.props.nodeRef?[this.nextCallback]:[r,this.nextCallback],s=a[0],A=a[1];this.props.addEndListener(s,A)}n!=null&&setTimeout(this.nextCallback,n)},I.render=function(){var n=this.state.status;if(n===vG)return null;var C=this.props,r=C.children;C.in,C.mountOnEnter,C.unmountOnExit,C.appear,C.enter,C.exit,C.timeout,C.addEndListener,C.onEnter,C.onEntering,C.onEntered,C.onExit,C.onExiting,C.onExited,C.nodeRef;var o=Qt(C,["children","in","mountOnEnter","unmountOnExit","appear","enter","exit","timeout","addEndListener","onEnter","onEntering","onEntered","onExit","onExiting","onExited","nodeRef"]);return N.createElement(JH.Provider,{value:null},typeof r=="function"?r(n,o):N.cloneElement(N.Children.only(r),o))},g}(N.Component);sl.contextType=JH;sl.propTypes={};function hf(){}sl.defaultProps={in:!1,mountOnEnter:!1,unmountOnExit:!1,appear:!1,enter:!0,exit:!0,onEnter:hf,onEntering:hf,onEntered:hf,onExit:hf,onExiting:hf,onExited:hf};sl.UNMOUNTED=vG;sl.EXITED=td;sl.ENTERING=gd;sl.ENTERED=zf;sl.EXITING=F_;const D8=sl;function nug(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function F8(e,g){var I=function(C){return g&&U.isValidElement(C)?g(C):C},i=Object.create(null);return e&&U.Children.map(e,function(n){return n}).forEach(function(n){i[n.key]=I(n)}),i}function Cug(e,g){e=e||{},g=g||{};function I(A){return A in g?g[A]:e[A]}var i=Object.create(null),n=[];for(var C in e)C in g?n.length&&(i[C]=n,n=[]):n.push(C);var r,o={};for(var a in g){if(i[a])for(r=0;re.scrollTop;function f0(e,g){var I,i;const{timeout:n,easing:C,style:r={}}=e;return{duration:(I=r.transitionDuration)!=null?I:typeof n=="number"?n:n[g.mode]||0,easing:(i=r.transitionTimingFunction)!=null?i:typeof C=="object"?C[g.mode]:C,delay:r.transitionDelay}}function lug(e){return li("MuiSvgIcon",e)}HI("MuiSvgIcon",["root","colorPrimary","colorSecondary","colorAction","colorError","colorDisabled","fontSizeInherit","fontSizeSmall","fontSizeMedium","fontSizeLarge"]);const cug=["children","className","color","component","fontSize","htmlColor","inheritViewBox","titleAccess","viewBox"],uug=e=>{const{color:g,fontSize:I,classes:i}=e,n={root:["root",g!=="inherit"&&`color${si(g)}`,`fontSize${si(I)}`]};return vi(n,lug,i)},dug=qt("svg",{name:"MuiSvgIcon",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[g.root,I.color!=="inherit"&&g[`color${si(I.color)}`],g[`fontSize${si(I.fontSize)}`]]}})(({theme:e,ownerState:g})=>{var I,i,n,C,r,o,a,s,A,l,c,u,d;return{userSelect:"none",width:"1em",height:"1em",display:"inline-block",fill:g.hasSvgAsChild?void 0:"currentColor",flexShrink:0,transition:(I=e.transitions)==null||(i=I.create)==null?void 0:i.call(I,"fill",{duration:(n=e.transitions)==null||(n=n.duration)==null?void 0:n.shorter}),fontSize:{inherit:"inherit",small:((C=e.typography)==null||(r=C.pxToRem)==null?void 0:r.call(C,20))||"1.25rem",medium:((o=e.typography)==null||(a=o.pxToRem)==null?void 0:a.call(o,24))||"1.5rem",large:((s=e.typography)==null||(A=s.pxToRem)==null?void 0:A.call(s,35))||"2.1875rem"}[g.fontSize],color:(l=(c=(e.vars||e).palette)==null||(c=c[g.color])==null?void 0:c.main)!=null?l:{action:(u=(e.vars||e).palette)==null||(u=u.action)==null?void 0:u.active,disabled:(d=(e.vars||e).palette)==null||(d=d.action)==null?void 0:d.disabled,inherit:void 0}[g.color]}}),_Ne=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiSvgIcon"}),{children:n,className:C,color:r="inherit",component:o="svg",fontSize:a="medium",htmlColor:s,inheritViewBox:A=!1,titleAccess:l,viewBox:c="0 0 24 24"}=i,u=Qt(i,cug),d=U.isValidElement(n)&&n.type==="svg",h=Ke({},i,{color:r,component:o,fontSize:a,instanceFontSize:g.fontSize,inheritViewBox:A,viewBox:c,hasSvgAsChild:d}),m={};A||(m.viewBox=c);const f=uug(h);return Oe.jsxs(dug,Ke({as:o,className:ug(f.root,C),focusable:"false",color:s,"aria-hidden":l?void 0:!0,role:l?"img":void 0,ref:I},m,u,d&&n.props,{ownerState:h,children:[d?n.props.children:n,l?Oe.jsx("title",{children:l}):null]}))});_Ne.muiName="SvgIcon";const fue=_Ne;function LNe(e,g){function I(i,n){return Oe.jsx(fue,Ke({"data-testid":`${g}Icon`,ref:n},i,{children:e}))}return I.muiName=fue.muiName,U.memo(U.forwardRef(I))}const hug={configure:e=>{sNe.configure(e)}},mug=Object.freeze(Object.defineProperty({__proto__:null,capitalize:si,createChainedFunction:W_,createSvgIcon:LNe,debounce:h8,deprecatedPropType:zag,isMuiElement:xW,ownerDocument:zC,ownerWindow:Qc,requirePropFactory:Pag,setRef:FH,unstable_ClassNameGenerator:hug,unstable_useEnhancedEffect:Ls,unstable_useId:rNe,unsupportedProp:_ag,useControlled:X_,useEventCallback:Zd,useForkRef:pn,useIsFocusVisible:oNe},Symbol.toStringTag,{value:"Module"}));function fug(e){return li("MuiCollapse",e)}HI("MuiCollapse",["root","horizontal","vertical","entered","hidden","wrapper","wrapperInner"]);const pug=["addEndListener","children","className","collapsedSize","component","easing","in","onEnter","onEntered","onEntering","onExit","onExited","onExiting","orientation","style","timeout","TransitionComponent"],bug=e=>{const{orientation:g,classes:I}=e,i={root:["root",`${g}`],entered:["entered"],hidden:["hidden"],wrapper:["wrapper",`${g}`],wrapperInner:["wrapperInner",`${g}`]};return vi(i,fug,I)},yug=qt("div",{name:"MuiCollapse",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[g.root,g[I.orientation],I.state==="entered"&&g.entered,I.state==="exited"&&!I.in&&I.collapsedSize==="0px"&&g.hidden]}})(({theme:e,ownerState:g})=>Ke({height:0,overflow:"hidden",transition:e.transitions.create("height")},g.orientation==="horizontal"&&{height:"auto",width:0,transition:e.transitions.create("width")},g.state==="entered"&&Ke({height:"auto",overflow:"visible"},g.orientation==="horizontal"&&{width:"auto"}),g.state==="exited"&&!g.in&&g.collapsedSize==="0px"&&{visibility:"hidden"})),Zug=qt("div",{name:"MuiCollapse",slot:"Wrapper",overridesResolver:(e,g)=>g.wrapper})(({ownerState:e})=>Ke({display:"flex",width:"100%"},e.orientation==="horizontal"&&{width:"auto",height:"100%"})),Gug=qt("div",{name:"MuiCollapse",slot:"WrapperInner",overridesResolver:(e,g)=>g.wrapperInner})(({ownerState:e})=>Ke({width:"100%"},e.orientation==="horizontal"&&{width:"auto",height:"100%"})),UNe=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiCollapse"}),{addEndListener:n,children:C,className:r,collapsedSize:o="0px",component:a,easing:s,in:A,onEnter:l,onEntered:c,onEntering:u,onExit:d,onExited:h,onExiting:m,orientation:f="vertical",style:b,timeout:p=kNe.standard,TransitionComponent:y=D8}=i,Z=Qt(i,pug),B=Ke({},i,{orientation:f,collapsedSize:o}),G=bug(B),v=fy(),w=U.useRef(),V=U.useRef(null),S=U.useRef(),X=typeof o=="number"?`${o}px`:o,W=f==="horizontal",R=W?"width":"height";U.useEffect(()=>()=>{clearTimeout(w.current)},[]);const H=U.useRef(null),Y=pn(I,H),K=Q=>ie=>{if(Q){const he=H.current;ie===void 0?Q(he):Q(he,ie)}},F=()=>V.current?V.current[W?"clientWidth":"clientHeight"]:0,J=K((Q,ie)=>{V.current&&W&&(V.current.style.position="absolute"),Q.style[R]=X,l&&l(Q,ie)}),P=K((Q,ie)=>{const he=F();V.current&&W&&(V.current.style.position="");const{duration:ne,easing:be}=f0({style:b,timeout:p,easing:s},{mode:"enter"});if(p==="auto"){const pe=v.transitions.getAutoHeightDuration(he);Q.style.transitionDuration=`${pe}ms`,S.current=pe}else Q.style.transitionDuration=typeof ne=="string"?ne:`${ne}ms`;Q.style[R]=`${he}px`,Q.style.transitionTimingFunction=be,u&&u(Q,ie)}),ge=K((Q,ie)=>{Q.style[R]="auto",c&&c(Q,ie)}),q=K(Q=>{Q.style[R]=`${F()}px`,d&&d(Q)}),$=K(h),j=K(Q=>{const ie=F(),{duration:he,easing:ne}=f0({style:b,timeout:p,easing:s},{mode:"exit"});if(p==="auto"){const be=v.transitions.getAutoHeightDuration(ie);Q.style.transitionDuration=`${be}ms`,S.current=be}else Q.style.transitionDuration=typeof he=="string"?he:`${he}ms`;Q.style[R]=X,Q.style.transitionTimingFunction=ne,m&&m(Q)}),te=Q=>{p==="auto"&&(w.current=setTimeout(Q,S.current||0)),n&&n(H.current,Q)};return Oe.jsx(y,Ke({in:A,onEnter:J,onEntered:ge,onEntering:P,onExit:q,onExited:$,onExiting:j,addEndListener:te,nodeRef:H,timeout:p==="auto"?null:p},Z,{children:(Q,ie)=>Oe.jsx(yug,Ke({as:a,className:ug(G.root,r,{entered:G.entered,exited:!A&&X==="0px"&&G.hidden}[Q]),style:Ke({[W?"minWidth":"minHeight"]:X},b),ownerState:Ke({},B,{state:Q}),ref:Y},ie,{children:Oe.jsx(Zug,{ownerState:Ke({},B,{state:Q}),className:G.wrapper,ref:V,children:Oe.jsx(Gug,{ownerState:Ke({},B,{state:Q}),className:G.wrapperInner,children:C})})}))}))});UNe.muiSupportAuto=!0;const QNe=UNe;var jNe={exports:{}};(function(e){function g(I){return I&&I.__esModule?I:{default:I}}e.exports=g,e.exports.__esModule=!0,e.exports.default=e.exports})(jNe);var $Ne=jNe.exports;const qNe=()=>U.useContext(ENe);function vug(e){const{instance:g,multiSelect:I}=qNe(),i=g?g.isNodeExpandable(e):!1,n=g?g.isNodeExpanded(e):!1,C=g?g.isNodeFocused(e):!1,r=g?g.isNodeSelected(e):!1,o=g?g.isNodeDisabled(e):!1;return{disabled:o,expanded:n,selected:r,focused:C,handleExpansion:l=>{if(g&&!o){C||g.focusNode(l,e);const c=I&&(l.shiftKey||l.ctrlKey||l.metaKey);i&&!(c&&g.isNodeExpanded(e))&&g.toggleNodeExpansion(l,e)}},handleSelection:l=>{g&&!o&&(C||g.focusNode(l,e),I&&(l.shiftKey||l.ctrlKey||l.metaKey)?l.shiftKey?g.selectRange(l,{end:e}):g.selectNode(l,e,!0):g.selectNode(l,e))},preventSelection:l=>{(l.shiftKey||l.ctrlKey||l.metaKey||o)&&l.preventDefault()}}}const Bug=["classes","className","displayIcon","expansionIcon","icon","label","nodeId","onClick","onMouseDown"],eke=U.forwardRef(function(g,I){const{classes:i,className:n,displayIcon:C,expansionIcon:r,icon:o,label:a,nodeId:s,onClick:A,onMouseDown:l}=g,c=Qt(g,Bug),{disabled:u,expanded:d,selected:h,focused:m,handleExpansion:f,handleSelection:b,preventSelection:p}=vug(s),y=o||r||C,Z=G=>{p(G),l&&l(G)},B=G=>{f(G),b(G),A&&A(G)};return Oe.jsxs("div",Ke({},c,{className:ug(n,i.root,d&&i.expanded,h&&i.selected,m&&i.focused,u&&i.disabled),onClick:B,onMouseDown:Z,ref:I,children:[Oe.jsx("div",{className:i.iconContainer,children:y}),Oe.jsx("div",{className:i.label,children:a})]}))});function Sug(e){return k8("MuiTreeItem",e)}const Vl=DNe("MuiTreeItem",["root","group","content","expanded","selected","focused","disabled","iconContainer","label"]),wug=["children","className","collapseIcon","ContentComponent","ContentProps","endIcon","expandIcon","disabled","icon","id","label","nodeId","onClick","onMouseDown","TransitionComponent","TransitionProps"],Vug=e=>{const{classes:g}=e;return YNe({root:["root"],content:["content"],expanded:["expanded"],selected:["selected"],focused:["focused"],disabled:["disabled"],iconContainer:["iconContainer"],label:["label"],group:["group"]},Sug,g)},Rug=qt("li",{name:"MuiTreeItem",slot:"Root",overridesResolver:(e,g)=>g.root})({listStyle:"none",margin:0,padding:0,outline:0}),Wug=qt(eke,{name:"MuiTreeItem",slot:"Content",overridesResolver:(e,g)=>[g.content,g.iconContainer&&{[`& .${Vl.iconContainer}`]:g.iconContainer},g.label&&{[`& .${Vl.label}`]:g.label}]})(({theme:e})=>({padding:"0 8px",width:"100%",boxSizing:"border-box",display:"flex",alignItems:"center",cursor:"pointer",WebkitTapHighlightColor:"transparent","&:hover":{backgroundColor:(e.vars||e).palette.action.hover,"@media (hover: none)":{backgroundColor:"transparent"}},[`&.${Vl.disabled}`]:{opacity:(e.vars||e).palette.action.disabledOpacity,backgroundColor:"transparent"},[`&.${Vl.focused}`]:{backgroundColor:(e.vars||e).palette.action.focus},[`&.${Vl.selected}`]:{backgroundColor:e.vars?`rgba(${e.vars.palette.primary.mainChannel} / ${e.vars.palette.action.selectedOpacity})`:rA(e.palette.primary.main,e.palette.action.selectedOpacity),"&:hover":{backgroundColor:e.vars?`rgba(${e.vars.palette.primary.mainChannel} / calc(${e.vars.palette.action.selectedOpacity} + ${e.vars.palette.action.hoverOpacity}))`:rA(e.palette.primary.main,e.palette.action.selectedOpacity+e.palette.action.hoverOpacity),"@media (hover: none)":{backgroundColor:e.vars?`rgba(${e.vars.palette.primary.mainChannel} / ${e.vars.palette.action.selectedOpacity})`:rA(e.palette.primary.main,e.palette.action.selectedOpacity)}},[`&.${Vl.focused}`]:{backgroundColor:e.vars?`rgba(${e.vars.palette.primary.mainChannel} / calc(${e.vars.palette.action.selectedOpacity} + ${e.vars.palette.action.focusOpacity}))`:rA(e.palette.primary.main,e.palette.action.selectedOpacity+e.palette.action.focusOpacity)}},[`& .${Vl.iconContainer}`]:{marginRight:4,width:15,display:"flex",flexShrink:0,justifyContent:"center","& svg":{fontSize:18}},[`& .${Vl.label}`]:Ke({paddingLeft:4,width:"100%",boxSizing:"border-box",minWidth:0,position:"relative"},e.typography.body1)})),Xug=qt(QNe,{name:"MuiTreeItem",slot:"Group",overridesResolver:(e,g)=>g.group})({margin:0,padding:0,marginLeft:17}),rc=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiTreeItem"}),{children:n,className:C,collapseIcon:r,ContentComponent:o=eke,ContentProps:a,endIcon:s,expandIcon:A,disabled:l,icon:c,id:u,label:d,nodeId:h,onClick:m,onMouseDown:f,TransitionComponent:b=QNe,TransitionProps:p}=i,y=Qt(i,wug),{icons:Z,multiSelect:B,disabledItemsFocusable:G,treeId:v,instance:w}=qNe();let V;u!=null?V=u:v&&h&&(V=`${v}-${h}`);const[S,X]=U.useState(null),W=U.useRef(null),R=N8(X,I),H=U.useMemo(()=>({element:S,id:h}),[h,S]),{index:Y,parentId:K}=Dcg(H),F=!!(Array.isArray(n)?n.length:n),J=w?w.isNodeExpanded(h):!1,P=w?w.isNodeFocused(h):!1,ge=w?w.isNodeSelected(h):!1,q=w?w.isNodeDisabled(h):!1,$=Ke({},i,{expanded:J,focused:P,selected:ge,disabled:q}),j=Vug($);let te,Q;F&&(J?Q=r||Z.defaultCollapseIcon:Q=A||Z.defaultExpandIcon),F?te=Z.defaultParentIcon:te=s||Z.defaultEndIcon,U.useEffect(()=>{if(w&&Y!==-1)return w.updateNode({id:h,idAttribute:V,index:Y,parentId:K,expandable:F,disabled:l}),()=>w.removeNode(h)},[w,K,Y,h,F,l,V]),U.useEffect(()=>{if(w&&d){var ne,be;return w.mapFirstChar(h,((ne=(be=W.current)==null?void 0:be.textContent)!=null?ne:"").substring(0,1).toLowerCase())}},[w,h,d]);let ie;B?ie=ge:ge&&(ie=!0);function he(ne){if(ne.target===ne.currentTarget){let pe;typeof ne.target.getRootNode=="function"?pe=ne.target.getRootNode():pe=KNe(ne.target),pe.getElementById(v).focus({preventScroll:!0})}const be=!G&&q;w&&!P&&ne.currentTarget===ne.target&&!be&&w.focusNode(ne,h)}return Oe.jsxs(Rug,Ke({className:ug(j.root,C),role:"treeitem","aria-expanded":F?J:void 0,"aria-selected":ie,"aria-disabled":q||void 0,id:V,tabIndex:-1},y,{ownerState:$,onFocus:he,ref:R,children:[Oe.jsx(Wug,Ke({as:o,ref:W,classes:{root:j.content,expanded:j.expanded,selected:j.selected,focused:j.focused,disabled:j.disabled,iconContainer:j.iconContainer,label:j.label},label:d,nodeId:h,onClick:m,onMouseDown:f,icon:c,expansionIcon:Q,displayIcon:te,ownerState:$},a)),n&&Oe.jsx(zNe,{id:h,children:Oe.jsx(Xug,Ke({as:b,unmountOnExit:!0,className:j.group,in:J,component:"ul",role:"group"},p,{children:n}))})]}))});var M8={},$F={};const Hug=P_(mug);var pue;function tke(){return pue||(pue=1,function(e){"use client";Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"default",{enumerable:!0,get:function(){return g.createSvgIcon}});var g=Hug}($F)),$F}var Tug=$Ne;Object.defineProperty(M8,"__esModule",{value:!0});var z8=M8.default=void 0,Nug=Tug(tke()),kug=Oe,Yug=(0,Nug.default)((0,kug.jsx)("path",{d:"M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z"}),"ExpandMore");z8=M8.default=Yug;var P8={},Kug=$Ne;Object.defineProperty(P8,"__esModule",{value:!0});var J8=P8.default=void 0,xug=Kug(tke()),Dug=Oe,Fug=(0,xug.default)((0,Dug.jsx)("path",{d:"M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}),"ChevronRight");J8=P8.default=Fug;class Sg{constructor(g,I,i,n,C,r){Gu(this,"name");Gu(this,"key");Gu(this,"always_show");Gu(this,"collapsing");Gu(this,"children_type");Gu(this,"children");this.name=g,this.key=I,this.always_show=i,this.collapsing=n,this.children_type=C,this.children=r}}const Eug=(e,g,I,i,n)=>{const C=zug(e);return Mug(C,g,I,i,n)},Mug=(e,g,I,i,n)=>{const[C,r]=U.useState(g),[o,a]=U.useState(i);U.useEffect(()=>{I(C)},[C]),U.useEffect(()=>{n(o)},[o]);const s=O8(e);return Oe.jsx(PNe,{className:"tree-view","aria-label":"Hierarchical tree describing displayed Gosling visualization.",defaultCollapseIcon:Oe.jsx(z8,{}),defaultExpanded:g,onNodeToggle:(A,l)=>{r(l)},defaultSelected:i,onNodeFocus:(A,l)=>{a(l)},defaultExpandIcon:Oe.jsx(J8,{}),children:s})};function O8(e){if(!e.children)if(e.always_show)e.children="This information cannot be displayed.";else return Oe.jsx(Oe.Fragment,{});if(typeof e.children=="string")return e.collapsing?Oe.jsx(rc,{nodeId:e.key,label:e.name,children:Oe.jsx(rc,{nodeId:e.key+"-item",label:e.children})}):Oe.jsx(rc,{nodeId:e.key,label:e.name+": "+e.children});if(e.children_type==="altnodelist"){const g=e.children,I=Object.keys(e.children).map((i,n)=>O8(g[n]));return Oe.jsxs(rc,{nodeId:e.key,label:e.name,children:[...I]})}else{const g=e.children;return Oe.jsx(rc,{nodeId:e.key,label:e.name,children:iNe(g)})}}function zug(e){return new Sg("Automatic description","tree",!0,!0,"altnodelist",[new Sg("Alt-text","alt",!0,!0,"value",e.alt),new Sg("Description","long",!0,!0,"value",e.longDescription),new Sg("Details","details",!0,!0,"altnodelist",[new Sg("Title","title",!1,!0,"value",e.title),new Sg("Subtitle","subtitle",!1,!0,"value",e.subtitle),...Pug(e)])])}function Pug(e){if(e.composition.nTracks===1)return Jug(e.tracks[0]);{const g=Object.keys(e.tracks).map((I,i)=>Oug(e.tracks[i]));return[new Sg("Composition","composition",!0,!0,"value",e.composition.description),new Sg("Tracks","tracks",!0,!0,"altnodelist",g)]}}function Jug(e){return[new Sg("Description","T-1-desc",!0,!0,"value",e.description),new Sg("Details","T-1-det",!0,!0,"altnodelist",[new Sg("Title","T-1-det-title",!1,!0,"value",e.title),gke(e,"1"),Ike(e,"1"),ike(e,"1")])]}function Oug(e){const g=e.position.details.trackNumber;return new Sg("Track "+e.position.description,"T-"+g,!0,!0,"altnodelist",[new Sg("Description","T-"+g+"-desc",!0,!0,"value",e.description),new Sg("Details","T-"+g+"-det",!0,!0,"altnodelist",[new Sg("Title","T-"+g+"-det-title",!1,!0,"value",e.title),new Sg("Position","T-"+g+"-det-pos",!0,!0,"altnodelist",[new Sg("Description","T-"+g+"-det-pos-desc",!0,!1,"value",e.position.description),new Sg("Track number","T-"+g+"-det-pos-trackN",!0,!1,"value",(e.position.details.trackNumber+1).toString())]),gke(e,g),Ike(e,g),ike(e,g)])])}function gke(e,g){let I;return e.alttype==="single"?I=e.charttype:e.alttype==="ov-mark"&&e.charttype&&(I=e8(e.charttype)),new Sg("Type","T-"+g+"-det-type",!1,!1,"value",I)}function Ike(e,g){return e.alttype==="single"||e.alttype==="ov-mark"?new Sg("Appearance","T-"+g+"-det-app",!1,!0,"altnodelist",[new Sg("Description","T-"+g+"-det-app-desc",!1,!0,"value",e.appearance.description),new Sg("Details","T-"+g+"-det-app-det",!1,!0,"altnodelist",[_ug(e,g),new Sg("Layout (linear or circular)","T-"+g+"-det-app-lay",!1,!1,"value",e.appearance.details.layout),new Sg("overlaid","T-"+g+"-det-app-overlaid",!1,!1,"value",cCg(e.appearance.details.overlaid)),...Lug(e,g)])]):FY()}function _ug(e,g){let I;return e.alttype==="ov-mark"?I=e8(e.appearance.details.mark):I=e.appearance.details.mark,new Sg("Mark","T-"+g+"-det-pos-app-mark",!1,!1,"value",I)}function Lug(e,g){return e.appearance.details.encodingsDescList.map((i,n)=>new Sg(i[0],"T-"+g+"-det-pos-enc"+i[0]+n,!1,!0,"value",i[1]))}function ike(e,g){var I;return(e.alttype==="single"||e.alttype==="ov-mark")&&e.data.details.dataStatistics?new Sg("Data","T-"+g+"-det-data",!0,!0,"altnodelist",[new Sg("Description","T-"+g+"-det-data-desc",!0,!0,"value",e.data.description),nke(e.data.details.dataStatistics,g),new Sg("Raw data","T-"+g+"-det-data-raw-data",!0,!0,"rawData",(I=e.data.details.dataStatistics)==null?void 0:I.flatTileData)]):FY()}function bue(e,g){return g?g.map((i,n)=>new Sg(i[0],"T-"+e+"-det-pos-enc"+i[0]+n,!1,!1,"value",i[1])):[FY()]}function nke(e,g){return new Sg("Data statistics","T-"+g+"-det-data-stats",!1,!0,"altnodelist",[new Sg("Genomic range","T-"+g+"-det-data-stats-genomic",!1,!0,"altnodelist",[...bue("T-"+g+"-det-data-stats-genomic",e.genomicDescList)]),new Sg("Value range","T-"+g+"-det-data-stats-value",!1,!0,"altnodelist",[...bue("T-"+g+"-det-data-stats-value",e.valueDescList)]),Uug(e,g)])}function Uug(e,g){return e.categories?new Sg("Categories","T-"+g+"-det-data-stats-categories",!1,!1,"value",e8(e.categories)):FY()}function FY(){return new Sg("","",!1,!1,"value",void 0)}function yue(e,g,I,i,n,C,r){const[o,a]=U.useState(e),[s,A]=U.useState(I);if(U.useEffect(()=>{g(o)},[o]),U.useEffect(()=>{i(s)},[s]),n.alttype=="ov-data")return console.log("overlaid with data not yet supported"),Oe.jsx(Oe.Fragment,{});let l;r?r.id==C.id?C.genomicMin&&C.genomicMax&&(l=`Genomic range has been changed, now showing ${eHe(C.genomicMin,C.genomicMax)}.`):l=`Showing track ${C.id}`:l=`Showing track ${C.id}`;const c=nke(C,n.uid),u=iNe(C.flatTileData);return Oe.jsx(PNe,{className:"data-panel-tree","aria-label":"Hierarchical tree describing updated data.",defaultCollapseIcon:Oe.jsx(z8,{}),defaultExpanded:e,onNodeToggle:(d,h)=>{a(h)},defaultSelected:I,onNodeFocus:(d,h)=>{A(h)},defaultExpandIcon:Oe.jsx(J8,{}),children:Oe.jsxs(rc,{nodeId:"tree",label:"Data panel",children:[Oe.jsx(rc,{nodeId:"desc",label:l}),O8(c),Oe.jsx(rc,{nodeId:"rawData",label:"Raw Data",children:u})]})})}const Qug=U.createContext(),Zue=Qug;function jug(e){return li("MuiGrid",e)}const $ug=[0,1,2,3,4,5,6,7,8,9,10],qug=["column-reverse","column","row-reverse","row"],edg=["nowrap","wrap-reverse","wrap"],SZ=["auto",!0,1,2,3,4,5,6,7,8,9,10,11,12],fS=HI("MuiGrid",["root","container","item","zeroMinWidth",...$ug.map(e=>`spacing-xs-${e}`),...qug.map(e=>`direction-xs-${e}`),...edg.map(e=>`wrap-xs-${e}`),...SZ.map(e=>`grid-xs-${e}`),...SZ.map(e=>`grid-sm-${e}`),...SZ.map(e=>`grid-md-${e}`),...SZ.map(e=>`grid-lg-${e}`),...SZ.map(e=>`grid-xl-${e}`)]),tdg=["className","columns","columnSpacing","component","container","direction","item","rowSpacing","spacing","wrap","zeroMinWidth"];function eb(e){const g=parseFloat(e);return`${g}${String(e).replace(String(g),"")||"px"}`}function gdg({theme:e,ownerState:g}){let I;return e.breakpoints.keys.reduce((i,n)=>{let C={};if(g[n]&&(I=g[n]),!I)return i;if(I===!0)C={flexBasis:0,flexGrow:1,maxWidth:"100%"};else if(I==="auto")C={flexBasis:"auto",flexGrow:0,flexShrink:0,maxWidth:"none",width:"auto"};else{const r=WY({values:g.columns,breakpoints:e.breakpoints.values}),o=typeof r=="object"?r[n]:r;if(o==null)return i;const a=`${Math.round(I/o*1e8)/1e6}%`;let s={};if(g.container&&g.item&&g.columnSpacing!==0){const A=e.spacing(g.columnSpacing);if(A!=="0px"){const l=`calc(${a} + ${eb(A)})`;s={flexBasis:l,maxWidth:l}}}C=Ke({flexBasis:a,flexGrow:0,maxWidth:a},s)}return e.breakpoints.values[n]===0?Object.assign(i,C):i[e.breakpoints.up(n)]=C,i},{})}function Idg({theme:e,ownerState:g}){const I=WY({values:g.direction,breakpoints:e.breakpoints.values});return ao({theme:e},I,i=>{const n={flexDirection:i};return i.indexOf("column")===0&&(n[`& > .${fS.item}`]={maxWidth:"none"}),n})}function Cke({breakpoints:e,values:g}){let I="";Object.keys(g).forEach(n=>{I===""&&g[n]!==0&&(I=n)});const i=Object.keys(e).sort((n,C)=>e[n]-e[C]);return i.slice(0,i.indexOf(I))}function idg({theme:e,ownerState:g}){const{container:I,rowSpacing:i}=g;let n={};if(I&&i!==0){const C=WY({values:i,breakpoints:e.breakpoints.values});let r;typeof C=="object"&&(r=Cke({breakpoints:e.breakpoints.values,values:C})),n=ao({theme:e},C,(o,a)=>{var s;const A=e.spacing(o);return A!=="0px"?{marginTop:`-${eb(A)}`,[`& > .${fS.item}`]:{paddingTop:eb(A)}}:(s=r)!=null&&s.includes(a)?{}:{marginTop:0,[`& > .${fS.item}`]:{paddingTop:0}}})}return n}function ndg({theme:e,ownerState:g}){const{container:I,columnSpacing:i}=g;let n={};if(I&&i!==0){const C=WY({values:i,breakpoints:e.breakpoints.values});let r;typeof C=="object"&&(r=Cke({breakpoints:e.breakpoints.values,values:C})),n=ao({theme:e},C,(o,a)=>{var s;const A=e.spacing(o);return A!=="0px"?{width:`calc(100% + ${eb(A)})`,marginLeft:`-${eb(A)}`,[`& > .${fS.item}`]:{paddingLeft:eb(A)}}:(s=r)!=null&&s.includes(a)?{}:{width:"100%",marginLeft:0,[`& > .${fS.item}`]:{paddingLeft:0}}})}return n}function Cdg(e,g,I={}){if(!e||e<=0)return[];if(typeof e=="string"&&!Number.isNaN(Number(e))||typeof e=="number")return[I[`spacing-xs-${String(e)}`]];const i=[];return g.forEach(n=>{const C=e[n];Number(C)>0&&i.push(I[`spacing-${n}-${String(C)}`])}),i}const rdg=qt("div",{name:"MuiGrid",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e,{container:i,direction:n,item:C,spacing:r,wrap:o,zeroMinWidth:a,breakpoints:s}=I;let A=[];i&&(A=Cdg(r,s,g));const l=[];return s.forEach(c=>{const u=I[c];u&&l.push(g[`grid-${c}-${String(u)}`])}),[g.root,i&&g.container,C&&g.item,a&&g.zeroMinWidth,...A,n!=="row"&&g[`direction-xs-${String(n)}`],o!=="wrap"&&g[`wrap-xs-${String(o)}`],...l]}})(({ownerState:e})=>Ke({boxSizing:"border-box"},e.container&&{display:"flex",flexWrap:"wrap",width:"100%"},e.item&&{margin:0},e.zeroMinWidth&&{minWidth:0},e.wrap!=="wrap"&&{flexWrap:e.wrap}),Idg,idg,ndg,gdg);function odg(e,g){if(!e||e<=0)return[];if(typeof e=="string"&&!Number.isNaN(Number(e))||typeof e=="number")return[`spacing-xs-${String(e)}`];const I=[];return g.forEach(i=>{const n=e[i];if(Number(n)>0){const C=`spacing-${i}-${String(n)}`;I.push(C)}}),I}const adg=e=>{const{classes:g,container:I,direction:i,item:n,spacing:C,wrap:r,zeroMinWidth:o,breakpoints:a}=e;let s=[];I&&(s=odg(C,a));const A=[];a.forEach(c=>{const u=e[c];u&&A.push(`grid-${c}-${String(u)}`)});const l={root:["root",I&&"container",n&&"item",o&&"zeroMinWidth",...s,i!=="row"&&`direction-xs-${String(i)}`,r!=="wrap"&&`wrap-xs-${String(r)}`,...A]};return vi(l,jug,g)},Adg=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiGrid"}),{breakpoints:n}=fy(),C=Alg(i),{className:r,columns:o,columnSpacing:a,component:s="div",container:A=!1,direction:l="row",item:c=!1,rowSpacing:u,spacing:d=0,wrap:h="wrap",zeroMinWidth:m=!1}=C,f=Qt(C,tdg),b=u||d,p=a||d,y=U.useContext(Zue),Z=A?o||12:y,B={},G=Ke({},f);n.keys.forEach(V=>{f[V]!=null&&(B[V]=f[V],delete G[V])});const v=Ke({},C,{columns:Z,container:A,direction:l,item:c,rowSpacing:b,columnSpacing:p,wrap:h,zeroMinWidth:m,spacing:d},B,{breakpoints:n.keys}),w=adg(v);return Oe.jsx(Zue.Provider,{value:Z,children:Oe.jsx(rdg,Ke({ownerState:v,className:ug(w.root,r),as:s,ref:I},G))})}),vd=Adg,sdg=e=>{const g=U.useRef(null),[I,i]=U.useState(),n=U.useRef([]),[C,r]=U.useState(-1),[o,a]=U.useState(),[s,A]=U.useState(),l=U.useRef(["tree"]),c=U.useRef("tree"),u=S=>{l.current=S},d=S=>{c.current=S},h=U.useRef(["tree"]),m=U.useRef("tree"),f=S=>{h.current=S},b=S=>{m.current=S},[p,y]=U.useState({width:0,height:0}),[Z,B]=U.useState([0,0,0]);U.useEffect(()=>{const S=[12,12,12];let X=e.layout,W=e.layoutPanels;X||(p.width>p.height?X="vertical":X="horizontal"),W||(X==="vertical"?W="horizontal":W="vertical"),X==="vertical"?(S[0]=12,W=="vertical"?(S[1]=12,S[2]=12):(S[1]=6,S[2]=6)):(S[0]=6,W=="vertical"?(S[1]=6,S[2]=6):(S[1]=3,S[2]=3)),B(S)},[p]),U.useEffect(()=>{if(I){const S=sCg(I);y({width:I._assignedWidth,height:I._assignedHeight}),G(S),a(void 0),A(void 0)}},[I]);function G(S){const X=JSON.stringify(S),W={id:X,data:S},R=n.current.filter(H=>H.id!==X);n.current=[...R,{...W}],r(n.current.length-1)}function v(S,X){const W={altTrack:S,altDataStatistics:X};A(o),a(W)}U.useEffect(()=>(g.current&&g.current.api.subscribe("rawData",(X,W)=>{const R=lCg(n.current[C].data,W.id,W.data);G(R);let H;for(const Y in R.tracks)R.tracks[Y].alttype=="ov-data"?(H=R.tracks[Y],W.id in H.uids):(H=R.tracks[Y],W.id==H.uid&&H.data.details.dataStatistics&&v(H,H.data.details.dataStatistics))}),()=>{var S;(S=g.current)==null||S.api.unsubscribe("rawData")}),[g.current]);const w=()=>{let S=["tree"];l.current&&(S=l.current);let X="tree";return c.current&&(X=c.current),Oe.jsx("div",{className:"editor-alt-text-panel",children:C>=0&&n.current[C]&&Object.keys(n.current[C].data).length>0?Oe.jsx(Oe.Fragment,{children:Oe.jsx("div",{className:"editor-alt-text-body",children:Oe.jsx("div",{children:Eug(n.current[C].data,S,u,X,d)})})}):null})},V=()=>{let S=["tree"];h.current&&(S=h.current);let X="tree";m.current&&(X=m.current);let W;return o?(s?W=yue(S,f,X,b,o.altTrack,o.altDataStatistics,s.altDataStatistics):W=yue(S,f,X,b,o.altTrack,o.altDataStatistics),Oe.jsx("div",{className:"editor-data-panel",children:Oe.jsx("div",{className:"editor-alt-text-body",children:Oe.jsx("div",{children:W})})})):Oe.jsx(Oe.Fragment,{})};return Oe.jsx(Oe.Fragment,{children:Oe.jsxs(vd,{container:!0,rowSpacing:3,columnSpacing:{xs:1,sm:1},"aria-label":"altgosling-component-container",children:[Oe.jsx(vd,{item:!0,xs:Z[0],children:Oe.jsx("div",{"aria-label":"gosling-component-container",children:Oe.jsx(U2e,{ref:g,...e,compiled:(S,X,W)=>{i(W._processedSpec)}})})}),Oe.jsx(vd,{item:!0,xs:Z[1],children:Oe.jsx(w,{})}),Oe.jsx(vd,{item:!0,xs:Z[2],children:Oe.jsx(V,{})})]})})},ldg={title:"Basic Marks: bar",subtitle:"Tutorial Examples",tracks:[{layout:"linear",width:800,height:180,data:{url:"https://resgen.io/api/v1/tileset_info/?d=UvVPeLHuRDiYA3qwFlm7xQ",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1"],binSize:5},mark:"bar",x:{field:"start",type:"genomic",axis:"bottom"},xe:{field:"end",type:"genomic"},y:{field:"peak",type:"quantitative",axis:"right"},size:{value:5}}]},cdg={title:"Basic Marks: line",subtitle:"Tutorial Examples",tracks:[{layout:"linear",width:800,height:180,data:{url:"https://resgen.io/api/v1/tileset_info/?d=UvVPeLHuRDiYA3qwFlm7xQ",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1"]},mark:"line",x:{field:"position",type:"genomic",axis:"bottom"},y:{field:"peak",type:"quantitative",axis:"right"},size:{value:2}}]},udg={title:"Basic Marks: point",subtitle:"Tutorial Examples",tracks:[{layout:"linear",width:800,height:180,data:{url:"https://resgen.io/api/v1/tileset_info/?d=UvVPeLHuRDiYA3qwFlm7xQ",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1"]},mark:"point",x:{field:"position",type:"genomic",axis:"bottom"},y:{field:"peak",type:"quantitative",axis:"right"},size:{field:"peak",type:"quantitative"}}]},ddg={title:"Basic Marks: Rect",subtitle:"Tutorial Examples",tracks:[{width:800,height:40,data:{url:"https://raw.githubusercontent.com/sehilyi/gemini-datasets/master/data/UCSC.HG38.Human.CytoBandIdeogram.csv",type:"csv",chromosomeField:"Chromosome",genomicFields:["chromStart","chromEnd"]},mark:"rect",dataTransform:[{type:"filter",field:"Stain",oneOf:["acen"],not:!0}],color:{field:"Stain",type:"nominal",domain:["gneg","gpos25","gpos50","gpos75","gpos100","gvar"],range:["white","#D9D9D9","#979797","#636363","black","#A0A0F2"]},x:{field:"chromStart",type:"genomic",domain:{chromosome:"chr1"},axis:"top"},xe:{field:"chromEnd",type:"genomic"},size:{value:20},stroke:{value:"gray"},strokeWidth:{value:.5},style:{outline:"white"}}]},hdg={title:"Visual Encoding",subtitle:"Gosling provides diverse visual encoding methods",layout:"linear",arrangement:"vertical",centerRadius:.8,xDomain:{chromosome:"chr1",interval:[1,3000500]},views:[{tracks:[{id:"track-1",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"],binSize:4},mark:"rect",x:{field:"start",type:"genomic",axis:"top"},xe:{field:"end",type:"genomic"},row:{field:"sample",type:"nominal",legend:!0},color:{field:"peak",type:"quantitative",legend:!0},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},{tracks:[{id:"track-2",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]},mark:"bar",x:{field:"position",type:"genomic",axis:"top"},y:{field:"peak",type:"quantitative"},row:{field:"sample",type:"nominal"},color:{field:"sample",type:"nominal",legend:!0},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},{tracks:[{id:"track-3",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]},mark:"bar",x:{field:"position",type:"genomic",axis:"top"},y:{field:"peak",type:"quantitative",grid:!0},color:{field:"sample",type:"nominal",legend:!0},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},{id:"track-4",alignment:"overlay",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]},x:{field:"position",type:"genomic",axis:"top"},y:{field:"peak",type:"quantitative"},row:{field:"sample",type:"nominal"},color:{field:"sample",type:"nominal",legend:!0},tracks:[{mark:"line"},{mark:"point",size:{field:"peak",type:"quantitative",range:[0,2]}}],tooltip:[{field:"position",type:"genomic",alt:"Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130},{tracks:[{id:"track-5",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]},mark:"point",x:{field:"position",type:"genomic",axis:"top"},y:{field:"peak",type:"quantitative"},row:{field:"sample",type:"nominal"},size:{field:"peak",type:"quantitative"},color:{field:"sample",type:"nominal",legend:!0},opacity:{value:.5},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},{tracks:[{id:"track-6",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]},mark:"point",x:{field:"position",type:"genomic",axis:"top"},y:{field:"peak",type:"quantitative",grid:!0},size:{field:"peak",type:"quantitative"},color:{field:"sample",type:"nominal",legend:!0},opacity:{value:.5},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},{tracks:[{id:"track-7",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]},mark:"area",x:{field:"position",type:"genomic",axis:"top"},y:{field:"peak",type:"quantitative"},row:{field:"sample",type:"nominal"},color:{field:"sample",type:"nominal",legend:!0},stroke:{value:"white"},strokeWidth:{value:.5},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},{tracks:[{id:"track-8",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"],binSize:4},mark:"bar",x:{field:"start",type:"genomic",axis:"top"},xe:{field:"end",type:"genomic",axis:"top"},y:{field:"peak_min",type:"quantitative"},ye:{field:"peak_max",type:"quantitative"},row:{field:"sample",type:"nominal"},color:{field:"sample",type:"nominal",legend:!0},stroke:{value:"black"},strokeWidth:{value:.2},tooltip:[{field:"position",type:"genomic",alt:"Position"},{field:"peak_min",type:"quantitative",alt:"min(Value)",format:".2"},{field:"peak_max",type:"quantitative",alt:"max(Value)",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},{tracks:[{id:"track-9",data:{url:"https://raw.githubusercontent.com/sehilyi/gemini-datasets/master/data/circos-segdup-edited.txt",type:"csv",chromosomeField:"c2",genomicFields:["s1","e1","s2","e2"]},mark:"withinLink",x:{field:"s1",type:"genomic",domain:{chromosome:"chr1",interval:[1039e5,1041e5]}},xe:{field:"e1",type:"genomic"},x1:{field:"s2",type:"genomic",domain:{chromosome:"chr1"}},x1e:{field:"e2",type:"genomic"},color:{field:"s1",type:"nominal"},stroke:{value:"black"},strokeWidth:{value:.5},opacity:{value:.2},width:600,height:130}]}]},mdg={title:"Visual Encoding",subtitle:"Gosling provides diverse visual encoding methods",layout:"linear",arrangement:"vertical",centerRadius:.8,xDomain:{chromosome:"chr1",interval:[1,3000500]},views:[{tracks:[{id:"track-1",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"],binSize:4},mark:"rect",x:{field:"start",type:"genomic",axis:"top"},xe:{field:"end",type:"genomic"},row:{field:"sample",type:"nominal",legend:!0},color:{field:"peak",type:"quantitative",legend:!0},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},{tracks:[{id:"track-2",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]},mark:"bar",x:{field:"position",type:"genomic",axis:"top"},y:{field:"peak",type:"quantitative"},row:{field:"sample",type:"nominal"},color:{field:"sample",type:"nominal",legend:!0},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]}]},fdg={title:"Visual Encoding",subtitle:"Gosling provides diverse visual encoding methods",layout:"linear",arrangement:"vertical",centerRadius:.8,xDomain:{chromosome:"chr1",interval:[1,3000500]},views:[{id:"track-4",alignment:"overlay",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]},x:{field:"position",type:"genomic",axis:"top"},y:{field:"peak",type:"quantitative"},row:{field:"sample",type:"nominal"},color:{field:"sample",type:"nominal",legend:!0},tracks:[{mark:"line"},{mark:"point",size:{field:"peak",type:"quantitative",range:[0,2]}}],tooltip:[{field:"position",type:"genomic",alt:"Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},pdg={title:"Visual Encoding",subtitle:"Gosling provides diverse visual encoding methods",layout:"linear",arrangement:"vertical",centerRadius:.8,xDomain:{chromosome:"chr1",interval:[1,3000500]},views:[{id:"track-4",alignment:"overlay",x:{field:"position",type:"genomic",axis:"top"},y:{field:"peak",type:"quantitative"},row:{field:"sample",type:"nominal"},color:{field:"sample",type:"nominal",legend:!0},tracks:[{mark:"line",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]}},{mark:"point",size:{field:"peak",type:"quantitative",range:[0,2]},data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"]}}],tooltip:[{field:"position",type:"genomic",alt:"Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:600,height:130}]},bdg={title:"Rule Mark",subtitle:"Annotate visualization with horizontal and vertical lines",style:{dashed:[3,3]},views:[{alignment:"overlay",tracks:[{data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1"],binSize:4},mark:"bar",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},y:{field:"peak",type:"quantitative",domain:[0,.003]},color:{value:"lightgray"}},{data:{type:"json",values:[{c:"chr2",p:1e5,v:1e-4},{c:"chr5",p:1e5,v:4e-4},{c:"chr10",p:1e5,v:9e-4}],chromosomeField:"c",genomicFields:["p"]},mark:"rule",x:{field:"p",type:"genomic"},y:{field:"v",type:"quantitative",domain:[0,.003]},strokeWidth:{field:"v",type:"quantitative"},color:{value:"red"}},{data:{type:"json",values:[{c:"chr2",p:1e5,v:1e-4},{c:"chr5",p:1e5,v:4e-4},{c:"chr10",p:1e5,v:9e-4}],chromosomeField:"c",genomicFields:["p"]},mark:"rule",x:{field:"p",type:"genomic"},strokeWidth:{value:2},color:{value:"blue"}}],width:500,height:200}]},ydg={title:"Rule Mark",subtitle:"Annotate visualization with horizontal and vertical lines",style:{dashed:[3,3]},views:[{alignment:"overlay",tracks:[{data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1"],binSize:4},mark:"bar",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},y:{field:"peak",type:"quantitative",domain:[0,.003]},color:{value:"lightgray"}},{data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1"],binSize:4},mark:"point",x:{field:"start",type:"genomic"},y:{field:"peak",type:"quantitative",domain:[0,.003]},color:{value:"red"}}],width:500,height:200}]},Zdg={title:"GIVE",subtitle:"Reimplementation of GenoCAT examples",spacing:60,arrangement:"vertical",views:[{layout:"linear",tracks:[{alignment:"overlay",title:"Genes",data:{url:"https://resgen.io/api/v1/tileset_info/?d=M9A9klpwTci5Vf4bHZ864g",type:"beddb",genomicFields:[{index:1,name:"start"},{index:2,name:"end"}],valueFields:[{index:5,name:"strand",type:"nominal"},{index:3,name:"name",type:"nominal"}],exonIntervalFields:[{index:12,name:"start"},{index:13,name:"end"}]},tracks:[{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["+"]}],mark:"rect",x:{field:"end",type:"genomic",domain:{chromosome:"chr17",interval:[2e5,8e5]},axis:"top"},size:{value:7}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["-"]}],mark:"rect",x:{field:"start",type:"genomic"},size:{value:7}},{dataTransform:[{type:"filter",field:"type",oneOf:["exon"]}],mark:"rect",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},size:{value:14}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]}],mark:"rule",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},strokeWidth:{value:3}}],row:{field:"strand",type:"nominal",domain:["+","-"]},color:{value:"#4050B4"},width:700,height:50},{data:{url:"https://resgen.io/api/v1/tileset_info/?d=Zz3CBDSqQ3ySrOSe2yj1eg",type:"vector",column:"position",value:"peak",binSize:4},mark:"bar",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},y:{field:"peak",type:"quantitative"},color:{value:"#8A96D5"},stroke:{value:"#3C4DB4"},strokeWidth:{value:.5},width:700,height:40},{data:{url:"https://resgen.io/api/v1/tileset_info/?d=dc_SOjdCRgq_8PYf6W--7w",type:"vector",column:"position",value:"peak",binSize:4},mark:"bar",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},y:{field:"peak",type:"quantitative"},color:{value:"#8A96D5"},stroke:{value:"#3C4DB4"},strokeWidth:{value:.5},width:700,height:40},{data:{url:"https://resgen.io/api/v1/tileset_info/?d=Nolbrk9kS3CE0jJL_7OW1g",type:"vector",column:"position",value:"peak",binSize:4},mark:"bar",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},y:{field:"peak",type:"quantitative"},color:{value:"#8A96D5"},stroke:{value:"#3C4DB4"},strokeWidth:{value:.5},width:700,height:40},{alignment:"overlay",data:{url:"https://raw.githubusercontent.com/sehilyi/gemini-datasets/master/data/UCSC.HG38.Human.CytoBandIdeogram.csv",type:"csv",chromosomeField:"Chromosome",genomicFields:["chromStart","chromEnd"]},tracks:[{mark:"rect",dataTransform:[{type:"filter",field:"Stain",oneOf:["acen"],not:!0}]},{mark:"triangleRight",dataTransform:[{type:"filter",field:"Stain",oneOf:["acen"]},{type:"filter",field:"Name",include:"q"}]},{mark:"triangleLeft",dataTransform:[{type:"filter",field:"Stain",oneOf:["acen"]},{type:"filter",field:"Name",include:"p"}]}],x:{field:"chromStart",type:"genomic",domain:{chromosome:"chr17",interval:[2e7,5e7]}},xe:{field:"chromEnd",type:"genomic"},color:{value:"white"},size:{value:14},stroke:{value:"black"},strokeWidth:{value:.5},width:700,height:40},{data:{url:"https://raw.githubusercontent.com/vigsterkr/circos/master/data/5/segdup.txt",type:"csv",headerNames:["id","chr","p1","p2"],chromosomePrefix:"hs",chromosomeField:"chr",genomicFields:["p1","p2"],separator:" ",longToWideId:"id"},dataTransform:[{type:"filter",field:"chr",oneOf:["hs17"]}],mark:"rect",x:{field:"p1",type:"genomic"},xe:{field:"p2",type:"genomic"},color:{field:"chr_2",type:"nominal",domain:["chr1","chr2","chr3","chr4","chr5","chr6","chr7","chr8","chr9","chr10","chr11","chr12","chr13","chr14","chr15","chr16","chr17","chr18","chr19","chr20","chr21","chr22","chrX","chrY"]},opacity:{value:.5},size:{value:14},overlayOnPreviousTrack:!0,width:700,height:40}]},{layout:"linear",tracks:[{alignment:"overlay",data:{url:"https://raw.githubusercontent.com/sehilyi/gemini-datasets/master/data/UCSC.HG38.Human.CytoBandIdeogram.csv",type:"csv",chromosomeField:"Chromosome",genomicFields:["chromStart","chromEnd"]},tracks:[{mark:"rect",dataTransform:[{type:"filter",field:"Stain",oneOf:["acen"],not:!0}]},{mark:"triangleRight",dataTransform:[{type:"filter",field:"Stain",oneOf:["acen"]},{type:"filter",field:"Name",include:"q"}]},{mark:"triangleLeft",dataTransform:[{type:"filter",field:"Stain",oneOf:["acen"]},{type:"filter",field:"Name",include:"p"}]}],x:{field:"chromStart",type:"genomic",axis:"none"},xe:{field:"chromEnd",type:"genomic"},color:{value:"white"},size:{value:14},stroke:{value:"black"},strokeWidth:{value:.5},width:700,height:40},{data:{url:"https://raw.githubusercontent.com/vigsterkr/circos/master/data/5/segdup.txt",type:"csv",headerNames:["id","chr","p1","p2"],chromosomePrefix:"hs",chromosomeField:"chr",genomicFields:["p1","p2"],separator:" ",longToWideId:"id"},dataTransform:[{type:"filter",field:"chr_2",oneOf:["hs1"]}],mark:"rect",x:{field:"p1_2",type:"genomic"},xe:{field:"p2_2",type:"genomic"},color:{field:"chr",type:"nominal",domain:["chr1","chr2","chr3","chr4","chr5","chr6","chr7","chr8","chr9","chr10","chr11","chr12","chr13","chr14","chr15","chr16","chr17","chr18","chr19","chr20","chr21","chr22","chrX","chrY"]},opacity:{value:.5},size:{value:14},overlayOnPreviousTrack:!0,width:700,height:40},{data:{url:"https://resgen.io/api/v1/tileset_info/?d=Zz3CBDSqQ3ySrOSe2yj1eg",type:"vector",column:"position",value:"peak",binSize:4},mark:"bar",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},y:{field:"peak",type:"quantitative"},color:{value:"#8A96D5"},stroke:{value:"#3C4DB4"},strokeWidth:{value:.5},width:700,height:40},{data:{url:"https://resgen.io/api/v1/tileset_info/?d=dc_SOjdCRgq_8PYf6W--7w",type:"vector",column:"position",value:"peak",binSize:4},mark:"bar",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},y:{field:"peak",type:"quantitative"},color:{value:"#8A96D5"},stroke:{value:"#3C4DB4"},strokeWidth:{value:.5},width:700,height:40},{data:{url:"https://resgen.io/api/v1/tileset_info/?d=Nolbrk9kS3CE0jJL_7OW1g",type:"vector",column:"position",value:"peak",binSize:4},mark:"bar",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},y:{field:"peak",type:"quantitative"},color:{value:"#8A96D5"},stroke:{value:"#3C4DB4"},strokeWidth:{value:.5},width:700,height:40},{alignment:"overlay",title:"Genes",data:{url:"https://resgen.io/api/v1/tileset_info/?d=M9A9klpwTci5Vf4bHZ864g",type:"beddb",genomicFields:[{index:1,name:"start"},{index:2,name:"end"}],valueFields:[{index:5,name:"strand",type:"nominal"},{index:3,name:"name",type:"nominal"}],exonIntervalFields:[{index:12,name:"start"},{index:13,name:"end"}]},tracks:[{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["+"]}],mark:"rect",x:{field:"end",type:"genomic",domain:{chromosome:"chr1",interval:[109e6,112e6]},axis:"bottom"},size:{value:7}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["-"]}],mark:"rect",x:{field:"start",type:"genomic"},size:{value:7}},{dataTransform:[{type:"filter",field:"type",oneOf:["exon"]}],mark:"rect",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},size:{value:14}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]}],mark:"rule",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},strokeWidth:{value:3}}],row:{field:"strand",type:"nominal",domain:["+","-"]},color:{value:"#4050B4"},width:700,height:50}]}],style:{outlineWidth:0}},Gdg={layout:"linear",xDomain:{chromosome:"chr3",interval:[52168e3,5289e4]},arrangement:"horizontal",views:[{arrangement:"vertical",views:[{alignment:"overlay",title:"HiGlass",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=gene-annotation",type:"beddb",genomicFields:[{index:1,name:"start"},{index:2,name:"end"}],valueFields:[{index:5,name:"strand",type:"nominal"},{index:3,name:"name",type:"nominal"}],exonIntervalFields:[{index:12,name:"start"},{index:13,name:"end"}]},tracks:[{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["+"]}],mark:"triangleRight",x:{field:"end",type:"genomic",axis:"top"},size:{value:15}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]}],mark:"text",text:{field:"name",type:"nominal"},x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},style:{dy:-15}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["-"]}],mark:"triangleLeft",x:{field:"start",type:"genomic"},size:{value:15},style:{align:"right"}},{dataTransform:[{type:"filter",field:"type",oneOf:["exon"]}],mark:"rect",x:{field:"start",type:"genomic"},size:{value:15},xe:{field:"end",type:"genomic"}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["+"]}],mark:"rule",x:{field:"start",type:"genomic"},strokeWidth:{value:3},xe:{field:"end",type:"genomic"},style:{linePattern:{type:"triangleRight",size:5}}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["-"]}],mark:"rule",x:{field:"start",type:"genomic"},strokeWidth:{value:3},xe:{field:"end",type:"genomic"},style:{linePattern:{type:"triangleLeft",size:5}}}],row:{field:"strand",type:"nominal",domain:["+","-"]},color:{field:"strand",type:"nominal",domain:["+","-"],range:["#7585FF","#FF8A85"]},visibility:[{operation:"less-than",measure:"width",threshold:"|xe-x|",transitionPadding:10,target:"mark"}],opacity:{value:.8},width:350,height:100},{alignment:"overlay",title:"Corces et al.",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=gene-annotation",type:"beddb",genomicFields:[{index:1,name:"start"},{index:2,name:"end"}],valueFields:[{index:5,name:"strand",type:"nominal"},{index:3,name:"name",type:"nominal"}],exonIntervalFields:[{index:12,name:"start"},{index:13,name:"end"}]},tracks:[{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["+"]}],mark:"text",text:{field:"name",type:"nominal"},x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},size:{value:8},style:{textFontSize:8,dy:-12}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["-"]}],mark:"text",text:{field:"name",type:"nominal"},x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},size:{value:8},style:{textFontSize:8,dy:10}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["+"]}],mark:"rect",x:{field:"end",type:"genomic"},size:{value:7}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["-"]}],mark:"rect",x:{field:"start",type:"genomic"},size:{value:7}},{dataTransform:[{type:"filter",field:"type",oneOf:["exon"]}],mark:"rect",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},size:{value:14}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]}],mark:"rule",x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},strokeWidth:{value:3}}],row:{field:"strand",type:"nominal",domain:["+","-"]},color:{field:"strand",type:"nominal",domain:["+","-"],range:["#012DB8","#BE1E2C"]},visibility:[{operation:"less-than",measure:"width",threshold:"|xe-x|",transitionPadding:10,target:"mark"}],width:350,height:100},{alignment:"overlay",title:"IGV",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=gene-annotation",type:"beddb",genomicFields:[{index:1,name:"start"},{index:2,name:"end"}],valueFields:[{index:5,name:"strand",type:"nominal"},{index:3,name:"name",type:"nominal"}],exonIntervalFields:[{index:12,name:"start"},{index:13,name:"end"}]},tracks:[{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]}],mark:"text",text:{field:"name",type:"nominal"},x:{field:"start",type:"genomic",axis:"top"},xe:{field:"end",type:"genomic"}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]}],mark:"rect",x:{field:"start",type:"genomic",axis:"top"},size:{value:15},xe:{field:"end",type:"genomic"}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["-"]}],mark:"rule",x:{field:"start",type:"genomic",axis:"top"},strokeWidth:{value:0},xe:{field:"end",type:"genomic"},color:{value:"white"},opacity:{value:.6},style:{linePattern:{type:"triangleLeft",size:10}}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["+"]}],mark:"rule",x:{field:"start",type:"genomic",axis:"top"},strokeWidth:{value:0},xe:{field:"end",type:"genomic"},color:{value:"white"},opacity:{value:.6},style:{linePattern:{type:"triangleRight",size:10}}}],row:{field:"strand",type:"nominal",domain:["+","-"]},color:{value:"#0900B1"},visibility:[{operation:"less-than",measure:"width",threshold:"|xe-x|",transitionPadding:10,target:"mark"}],width:350,height:100}]},{arrangement:"vertical",views:[{alignment:"overlay",title:"Cyverse-QUBES",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=gene-annotation",type:"beddb",genomicFields:[{index:1,name:"start"},{index:2,name:"end"}],valueFields:[{index:5,name:"strand",type:"nominal"},{index:3,name:"name",type:"nominal"}],exonIntervalFields:[{index:12,name:"start"},{index:13,name:"end"}]},tracks:[{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]}],mark:"text",text:{field:"name",type:"nominal"},x:{field:"start",type:"genomic"},xe:{field:"end",type:"genomic"},color:{value:"black"}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["+"]}],mark:"triangleRight",x:{field:"end",type:"genomic",axis:"top"},color:{value:"#999999"}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["-"]}],mark:"triangleLeft",x:{field:"start",type:"genomic",axis:"top"},color:{value:"#999999"},style:{align:"right"}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]}],mark:"rect",x:{field:"start",type:"genomic",axis:"top"},xe:{field:"end",type:"genomic"},color:{value:"lightgray"}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]}],mark:"rule",x:{field:"start",type:"genomic",axis:"top"},strokeWidth:{value:5},xe:{field:"end",type:"genomic"},color:{value:"gray"}},{dataTransform:[{type:"filter",field:"type",oneOf:["exon"]}],mark:"rect",x:{field:"start",type:"genomic",axis:"top"},xe:{field:"end",type:"genomic"},color:{value:"#E2A6F5"},stroke:{value:"#BB57C9"},strokeWidth:{value:1}}],row:{field:"strand",type:"nominal",domain:["+","-"]},visibility:[{operation:"less-than",measure:"width",threshold:"|xe-x|",transitionPadding:10,target:"mark"}],size:{value:15},width:350,height:100},{alignment:"overlay",title:"GmGDV",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=gene-annotation",type:"beddb",genomicFields:[{index:1,name:"start"},{index:2,name:"end"}],valueFields:[{index:5,name:"strand",type:"nominal"},{index:3,name:"name",type:"nominal"}],exonIntervalFields:[{index:12,name:"start"},{index:13,name:"end"}]},tracks:[{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]}],mark:"text",text:{field:"name",type:"nominal"},x:{field:"start",type:"genomic",axis:"top"},xe:{field:"end",type:"genomic"},style:{dy:-14}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["+"]}],mark:"triangleRight",x:{field:"end",type:"genomic",axis:"top"},size:{value:15}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]},{type:"filter",field:"strand",oneOf:["-"]}],mark:"triangleLeft",x:{field:"start",type:"genomic",axis:"top"},size:{value:15},style:{align:"right"}},{dataTransform:[{type:"filter",field:"type",oneOf:["exon"]}],mark:"rect",x:{field:"start",type:"genomic",axis:"top"},size:{value:10},xe:{field:"end",type:"genomic"}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]}],mark:"rule",x:{field:"start",type:"genomic",axis:"top"},strokeWidth:{value:3},xe:{field:"end",type:"genomic"}}],row:{field:"strand",type:"nominal",domain:["+","-"]},color:{field:"strand",type:"nominal",domain:["+","-"],range:["blue","red"]},visibility:[{operation:"less-than",measure:"width",threshold:"|xe-x|",transitionPadding:10,target:"mark"}],width:350,height:100},{alignment:"overlay",data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=gene-annotation",type:"beddb",genomicFields:[{index:1,name:"start"},{index:2,name:"end"}],valueFields:[{index:5,name:"strand",type:"nominal"},{index:3,name:"name",type:"nominal"}],exonIntervalFields:[{index:12,name:"start"},{index:13,name:"end"}]},tracks:[{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]}],mark:"text",text:{field:"name",type:"nominal"},x:{field:"start",type:"genomic",axis:"top"},color:{value:"black"},xe:{field:"end",type:"genomic"}},{dataTransform:[{type:"filter",field:"type",oneOf:["gene"]}],mark:"rect",x:{field:"start",type:"genomic",axis:"top"},xe:{field:"end",type:"genomic"},color:{value:"#666666"}},{dataTransform:[{type:"filter",field:"type",oneOf:["exon"]}],mark:"rect",x:{field:"start",type:"genomic",axis:"top"},xe:{field:"end",type:"genomic"},color:{value:"#FF6666"}},{dataTransform:[{type:"filter",field:"type",oneOf:["intron"]}],mark:"rect",x:{field:"start",type:"genomic",axis:"top"},xe:{field:"end",type:"genomic"},color:{value:"#99FEFF"}}],size:{value:30},row:{field:"strand",type:"nominal",domain:["+","-"]},stroke:{value:"#777777"},strokeWidth:{value:1},visibility:[{operation:"less-than",measure:"width",threshold:"|xe-x|",transitionPadding:10,target:"mark"}],width:350,height:100}]}]};function Gue(e){return e!=null&&!(Array.isArray(e)&&e.length===0)}function OH(e,g=!1){return e&&(Gue(e.value)&&e.value!==""||g&&Gue(e.defaultValue)&&e.defaultValue!=="")}function vdg(e){return e.startAdornment}const Bdg=U.createContext(void 0),_8=Bdg;function Sdg(e){return li("MuiFormControl",e)}HI("MuiFormControl",["root","marginNone","marginNormal","marginDense","fullWidth","disabled"]);const wdg=["children","className","color","component","disabled","error","focused","fullWidth","hiddenLabel","margin","required","size","variant"],Vdg=e=>{const{classes:g,margin:I,fullWidth:i}=e,n={root:["root",I!=="none"&&`margin${si(I)}`,i&&"fullWidth"]};return vi(n,Sdg,g)},Rdg=qt("div",{name:"MuiFormControl",slot:"Root",overridesResolver:({ownerState:e},g)=>Ke({},g.root,g[`margin${si(e.margin)}`],e.fullWidth&&g.fullWidth)})(({ownerState:e})=>Ke({display:"inline-flex",flexDirection:"column",position:"relative",minWidth:0,padding:0,margin:0,border:0,verticalAlign:"top"},e.margin==="normal"&&{marginTop:16,marginBottom:8},e.margin==="dense"&&{marginTop:8,marginBottom:4},e.fullWidth&&{width:"100%"})),Wdg=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiFormControl"}),{children:n,className:C,color:r="primary",component:o="div",disabled:a=!1,error:s=!1,focused:A,fullWidth:l=!1,hiddenLabel:c=!1,margin:u="none",required:d=!1,size:h="medium",variant:m="outlined"}=i,f=Qt(i,wdg),b=Ke({},i,{color:r,component:o,disabled:a,error:s,fullWidth:l,hiddenLabel:c,margin:u,required:d,size:h,variant:m}),p=Vdg(b),[y,Z]=U.useState(()=>{let W=!1;return n&&U.Children.forEach(n,R=>{if(!xW(R,["Input","Select"]))return;const H=xW(R,["Select"])?R.props.input:R;H&&vdg(H.props)&&(W=!0)}),W}),[B,G]=U.useState(()=>{let W=!1;return n&&U.Children.forEach(n,R=>{xW(R,["Input","Select"])&&(OH(R.props,!0)||OH(R.props.inputProps,!0))&&(W=!0)}),W}),[v,w]=U.useState(!1);a&&v&&w(!1);const V=A!==void 0&&!a?A:v;let S;const X=U.useMemo(()=>({adornedStart:y,setAdornedStart:Z,color:r,disabled:a,error:s,filled:B,focused:V,fullWidth:l,hiddenLabel:c,size:h,onBlur:()=>{w(!1)},onEmpty:()=>{G(!1)},onFilled:()=>{G(!0)},onFocus:()=>{w(!0)},registerEffect:S,required:d,variant:m}),[y,r,a,s,B,V,l,c,S,d,h,m]);return Oe.jsx(_8.Provider,{value:X,children:Oe.jsx(Rdg,Ke({as:o,ownerState:b,className:ug(p.root,C),ref:I},f,{children:n}))})}),Xdg=Wdg;function Pw(){return U.useContext(_8)}function Jw({props:e,states:g,muiFormControl:I}){return g.reduce((i,n)=>(i[n]=e[n],I&&typeof e[n]>"u"&&(i[n]=I[n]),i),{})}function Hdg(e){return li("MuiFormLabel",e)}const Tdg=HI("MuiFormLabel",["root","colorSecondary","focused","disabled","error","filled","required","asterisk"]),Kv=Tdg,Ndg=["children","className","color","component","disabled","error","filled","focused","required"],kdg=e=>{const{classes:g,color:I,focused:i,disabled:n,error:C,filled:r,required:o}=e,a={root:["root",`color${si(I)}`,n&&"disabled",C&&"error",r&&"filled",i&&"focused",o&&"required"],asterisk:["asterisk",C&&"error"]};return vi(a,Hdg,g)},Ydg=qt("label",{name:"MuiFormLabel",slot:"Root",overridesResolver:({ownerState:e},g)=>Ke({},g.root,e.color==="secondary"&&g.colorSecondary,e.filled&&g.filled)})(({theme:e,ownerState:g})=>Ke({color:(e.vars||e).palette.text.secondary},e.typography.body1,{lineHeight:"1.4375em",padding:0,position:"relative",[`&.${Kv.focused}`]:{color:(e.vars||e).palette[g.color].main},[`&.${Kv.disabled}`]:{color:(e.vars||e).palette.text.disabled},[`&.${Kv.error}`]:{color:(e.vars||e).palette.error.main}})),Kdg=qt("span",{name:"MuiFormLabel",slot:"Asterisk",overridesResolver:(e,g)=>g.asterisk})(({theme:e})=>({[`&.${Kv.error}`]:{color:(e.vars||e).palette.error.main}})),xdg=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiFormLabel"}),{children:n,className:C,component:r="label"}=i,o=Qt(i,Ndg),a=Pw(),s=Jw({props:i,muiFormControl:a,states:["color","required","focused","disabled","error","filled"]}),A=Ke({},i,{color:s.color||"primary",component:r,disabled:s.disabled,error:s.error,filled:s.filled,focused:s.focused,required:s.required}),l=kdg(A);return Oe.jsxs(Ydg,Ke({as:r,ownerState:A,className:ug(l.root,C),ref:I},o,{children:[n,s.required&&Oe.jsxs(Kdg,{ownerState:A,"aria-hidden":!0,className:l.asterisk,children:[" ","*"]})]}))}),Ddg=xdg;function Fdg(e){return li("MuiInputLabel",e)}HI("MuiInputLabel",["root","focused","disabled","error","required","asterisk","formControl","sizeSmall","shrink","animated","standard","filled","outlined"]);const Edg=["disableAnimation","margin","shrink","variant","className"],Mdg=e=>{const{classes:g,formControl:I,size:i,shrink:n,disableAnimation:C,variant:r,required:o}=e,a={root:["root",I&&"formControl",!C&&"animated",n&&"shrink",i&&i!=="normal"&&`size${si(i)}`,r],asterisk:[o&&"asterisk"]},s=vi(a,Fdg,g);return Ke({},g,s)},zdg=qt(Ddg,{shouldForwardProp:e=>va(e)||e==="classes",name:"MuiInputLabel",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[{[`& .${Kv.asterisk}`]:g.asterisk},g.root,I.formControl&&g.formControl,I.size==="small"&&g.sizeSmall,I.shrink&&g.shrink,!I.disableAnimation&&g.animated,I.focused&&g.focused,g[I.variant]]}})(({theme:e,ownerState:g})=>Ke({display:"block",transformOrigin:"top left",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%"},g.formControl&&{position:"absolute",left:0,top:0,transform:"translate(0, 20px) scale(1)"},g.size==="small"&&{transform:"translate(0, 17px) scale(1)"},g.shrink&&{transform:"translate(0, -1.5px) scale(0.75)",transformOrigin:"top left",maxWidth:"133%"},!g.disableAnimation&&{transition:e.transitions.create(["color","transform","max-width"],{duration:e.transitions.duration.shorter,easing:e.transitions.easing.easeOut})},g.variant==="filled"&&Ke({zIndex:1,pointerEvents:"none",transform:"translate(12px, 16px) scale(1)",maxWidth:"calc(100% - 24px)"},g.size==="small"&&{transform:"translate(12px, 13px) scale(1)"},g.shrink&&Ke({userSelect:"none",pointerEvents:"auto",transform:"translate(12px, 7px) scale(0.75)",maxWidth:"calc(133% - 24px)"},g.size==="small"&&{transform:"translate(12px, 4px) scale(0.75)"})),g.variant==="outlined"&&Ke({zIndex:1,pointerEvents:"none",transform:"translate(14px, 16px) scale(1)",maxWidth:"calc(100% - 24px)"},g.size==="small"&&{transform:"translate(14px, 9px) scale(1)"},g.shrink&&{userSelect:"none",pointerEvents:"auto",maxWidth:"calc(133% - 32px)",transform:"translate(14px, -9px) scale(0.75)"}))),Pdg=U.forwardRef(function(g,I){const i=gi({name:"MuiInputLabel",props:g}),{disableAnimation:n=!1,shrink:C,className:r}=i,o=Qt(i,Edg),a=Pw();let s=C;typeof s>"u"&&a&&(s=a.filled||a.focused||a.adornedStart);const A=Jw({props:i,muiFormControl:a,states:["size","variant","required","focused"]}),l=Ke({},i,{disableAnimation:n,formControl:a,shrink:s,size:A.size,variant:A.variant,required:A.required,focused:A.focused}),c=Mdg(l);return Oe.jsx(zdg,Ke({"data-shrink":s,ownerState:l,ref:I,className:ug(c.root,r)},o,{classes:c}))}),Jdg=Pdg;function _H(e){return typeof e=="string"}function Odg(e,g,I){return e===void 0||_H(e)?g:Ke({},g,{ownerState:Ke({},g.ownerState,I)})}function rke(e,g=[]){if(e===void 0)return{};const I={};return Object.keys(e).filter(i=>i.match(/^on[A-Z]/)&&typeof e[i]=="function"&&!g.includes(i)).forEach(i=>{I[i]=e[i]}),I}function _dg(e,g,I){return typeof e=="function"?e(g,I):e}function vue(e){if(e===void 0)return{};const g={};return Object.keys(e).filter(I=>!(I.match(/^on[A-Z]/)&&typeof e[I]=="function")).forEach(I=>{g[I]=e[I]}),g}function Ldg(e){const{getSlotProps:g,additionalProps:I,externalSlotProps:i,externalForwardedProps:n,className:C}=e;if(!g){const u=ug(I==null?void 0:I.className,C,n==null?void 0:n.className,i==null?void 0:i.className),d=Ke({},I==null?void 0:I.style,n==null?void 0:n.style,i==null?void 0:i.style),h=Ke({},I,n,i);return u.length>0&&(h.className=u),Object.keys(d).length>0&&(h.style=d),{props:h,internalRef:void 0}}const r=rke(Ke({},n,i)),o=vue(i),a=vue(n),s=g(r),A=ug(s==null?void 0:s.className,I==null?void 0:I.className,C,n==null?void 0:n.className,i==null?void 0:i.className),l=Ke({},s==null?void 0:s.style,I==null?void 0:I.style,n==null?void 0:n.style,i==null?void 0:i.style),c=Ke({},s,I,a,o);return A.length>0&&(c.className=A),Object.keys(l).length>0&&(c.style=l),{props:c,internalRef:s.ref}}const Udg=["elementType","externalSlotProps","ownerState","skipResolvingSlotProps"];function p0(e){var g;const{elementType:I,externalSlotProps:i,ownerState:n,skipResolvingSlotProps:C=!1}=e,r=Qt(e,Udg),o=C?{}:_dg(i,n),{props:a,internalRef:s}=Ldg(Ke({},r,{externalSlotProps:o})),A=pn(s,o==null?void 0:o.ref,(g=e.additionalProps)==null?void 0:g.ref);return Odg(I,Ke({},a,{ref:A}),n)}const Qdg=U.createContext({}),E_=Qdg;function jdg(e){return li("MuiList",e)}HI("MuiList",["root","padding","dense","subheader"]);const $dg=["children","className","component","dense","disablePadding","subheader"],qdg=e=>{const{classes:g,disablePadding:I,dense:i,subheader:n}=e;return vi({root:["root",!I&&"padding",i&&"dense",n&&"subheader"]},jdg,g)},ehg=qt("ul",{name:"MuiList",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[g.root,!I.disablePadding&&g.padding,I.dense&&g.dense,I.subheader&&g.subheader]}})(({ownerState:e})=>Ke({listStyle:"none",margin:0,padding:0,position:"relative"},!e.disablePadding&&{paddingTop:8,paddingBottom:8},e.subheader&&{paddingTop:0})),thg=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiList"}),{children:n,className:C,component:r="ul",dense:o=!1,disablePadding:a=!1,subheader:s}=i,A=Qt(i,$dg),l=U.useMemo(()=>({dense:o}),[o]),c=Ke({},i,{component:r,dense:o,disablePadding:a}),u=qdg(c);return Oe.jsx(E_.Provider,{value:l,children:Oe.jsxs(ehg,Ke({as:r,className:ug(u.root,C),ref:I,ownerState:c},A,{children:[s,n]}))})}),ghg=thg,Ihg=["actions","autoFocus","autoFocusItem","children","className","disabledItemsFocusable","disableListWrap","onKeyDown","variant"];function qF(e,g,I){return e===g?e.firstChild:g&&g.nextElementSibling?g.nextElementSibling:I?null:e.firstChild}function Bue(e,g,I){return e===g?I?e.firstChild:e.lastChild:g&&g.previousElementSibling?g.previousElementSibling:I?null:e.lastChild}function oke(e,g){if(g===void 0)return!0;let I=e.innerText;return I===void 0&&(I=e.textContent),I=I.trim().toLowerCase(),I.length===0?!1:g.repeating?I[0]===g.keys[0]:I.indexOf(g.keys.join(""))===0}function wZ(e,g,I,i,n,C){let r=!1,o=n(e,g,g?I:!1);for(;o;){if(o===e.firstChild){if(r)return!1;r=!0}const a=i?!1:o.disabled||o.getAttribute("aria-disabled")==="true";if(!o.hasAttribute("tabindex")||!oke(o,C)||a)o=n(e,o,I);else return o.focus(),!0}return!1}const ihg=U.forwardRef(function(g,I){const{actions:i,autoFocus:n=!1,autoFocusItem:C=!1,children:r,className:o,disabledItemsFocusable:a=!1,disableListWrap:s=!1,onKeyDown:A,variant:l="selectedMenu"}=g,c=Qt(g,Ihg),u=U.useRef(null),d=U.useRef({keys:[],repeating:!0,previousKeyMatched:!0,lastTime:null});Ls(()=>{n&&u.current.focus()},[n]),U.useImperativeHandle(i,()=>({adjustStyleForScrollbar:(p,y)=>{const Z=!u.current.style.width;if(p.clientHeight{const y=u.current,Z=p.key,B=zC(y).activeElement;if(Z==="ArrowDown")p.preventDefault(),wZ(y,B,s,a,qF);else if(Z==="ArrowUp")p.preventDefault(),wZ(y,B,s,a,Bue);else if(Z==="Home")p.preventDefault(),wZ(y,null,s,a,qF);else if(Z==="End")p.preventDefault(),wZ(y,null,s,a,Bue);else if(Z.length===1){const G=d.current,v=Z.toLowerCase(),w=performance.now();G.keys.length>0&&(w-G.lastTime>500?(G.keys=[],G.repeating=!0,G.previousKeyMatched=!0):G.repeating&&v!==G.keys[0]&&(G.repeating=!1)),G.lastTime=w,G.keys.push(v);const V=B&&!G.repeating&&oke(B,G);G.previousKeyMatched&&(V||wZ(y,B,!1,a,qF,G))?p.preventDefault():G.previousKeyMatched=!1}A&&A(p)},m=pn(u,I);let f=-1;U.Children.forEach(r,(p,y)=>{if(!U.isValidElement(p)){f===y&&(f+=1,f>=r.length&&(f=-1));return}p.props.disabled||(l==="selectedMenu"&&p.props.selected||f===-1)&&(f=y),f===y&&(p.props.disabled||p.props.muiSkipListHighlight||p.type.muiSkipListHighlight)&&(f+=1,f>=r.length&&(f=-1))});const b=U.Children.map(r,(p,y)=>{if(y===f){const Z={};return C&&(Z.autoFocus=!0),p.props.tabIndex===void 0&&l==="selectedMenu"&&(Z.tabIndex=0),U.cloneElement(p,Z)}return p});return Oe.jsx(ghg,Ke({role:"menu",ref:m,className:o,onKeyDown:h,tabIndex:n?0:-1},c,{children:b}))}),nhg=ihg,Chg=["input","select","textarea","a[href]","button","[tabindex]","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])'].join(",");function rhg(e){const g=parseInt(e.getAttribute("tabindex")||"",10);return Number.isNaN(g)?e.contentEditable==="true"||(e.nodeName==="AUDIO"||e.nodeName==="VIDEO"||e.nodeName==="DETAILS")&&e.getAttribute("tabindex")===null?0:e.tabIndex:g}function ohg(e){if(e.tagName!=="INPUT"||e.type!=="radio"||!e.name)return!1;const g=i=>e.ownerDocument.querySelector(`input[type="radio"]${i}`);let I=g(`[name="${e.name}"]:checked`);return I||(I=g(`[name="${e.name}"]`)),I!==e}function ahg(e){return!(e.disabled||e.tagName==="INPUT"&&e.type==="hidden"||ohg(e))}function Ahg(e){const g=[],I=[];return Array.from(e.querySelectorAll(Chg)).forEach((i,n)=>{const C=rhg(i);C===-1||!ahg(i)||(C===0?g.push(i):I.push({documentOrder:n,tabIndex:C,node:i}))}),I.sort((i,n)=>i.tabIndex===n.tabIndex?i.documentOrder-n.documentOrder:i.tabIndex-n.tabIndex).map(i=>i.node).concat(g)}function shg(){return!0}function lhg(e){const{children:g,disableAutoFocus:I=!1,disableEnforceFocus:i=!1,disableRestoreFocus:n=!1,getTabbable:C=Ahg,isEnabled:r=shg,open:o}=e,a=U.useRef(!1),s=U.useRef(null),A=U.useRef(null),l=U.useRef(null),c=U.useRef(null),u=U.useRef(!1),d=U.useRef(null),h=pn(g.ref,d),m=U.useRef(null);U.useEffect(()=>{!o||!d.current||(u.current=!I)},[I,o]),U.useEffect(()=>{if(!o||!d.current)return;const p=zC(d.current);return d.current.contains(p.activeElement)||(d.current.hasAttribute("tabIndex")||d.current.setAttribute("tabIndex","-1"),u.current&&d.current.focus()),()=>{n||(l.current&&l.current.focus&&(a.current=!0,l.current.focus()),l.current=null)}},[o]),U.useEffect(()=>{if(!o||!d.current)return;const p=zC(d.current),y=G=>{m.current=G,!(i||!r()||G.key!=="Tab")&&p.activeElement===d.current&&G.shiftKey&&(a.current=!0,A.current&&A.current.focus())},Z=()=>{const G=d.current;if(G===null)return;if(!p.hasFocus()||!r()||a.current){a.current=!1;return}if(G.contains(p.activeElement)||i&&p.activeElement!==s.current&&p.activeElement!==A.current)return;if(p.activeElement!==c.current)c.current=null;else if(c.current!==null)return;if(!u.current)return;let v=[];if((p.activeElement===s.current||p.activeElement===A.current)&&(v=C(d.current)),v.length>0){var w,V;const S=!!((w=m.current)!=null&&w.shiftKey&&((V=m.current)==null?void 0:V.key)==="Tab"),X=v[0],W=v[v.length-1];typeof X!="string"&&typeof W!="string"&&(S?W.focus():X.focus())}else G.focus()};p.addEventListener("focusin",Z),p.addEventListener("keydown",y,!0);const B=setInterval(()=>{p.activeElement&&p.activeElement.tagName==="BODY"&&Z()},50);return()=>{clearInterval(B),p.removeEventListener("focusin",Z),p.removeEventListener("keydown",y,!0)}},[I,i,n,r,o,C]);const f=p=>{l.current===null&&(l.current=p.relatedTarget),u.current=!0,c.current=p.target;const y=g.props.onFocus;y&&y(p)},b=p=>{l.current===null&&(l.current=p.relatedTarget),u.current=!0};return Oe.jsxs(U.Fragment,{children:[Oe.jsx("div",{tabIndex:o?0:-1,onFocus:b,ref:s,"data-testid":"sentinelStart"}),U.cloneElement(g,{ref:h,onFocus:f}),Oe.jsx("div",{tabIndex:o?0:-1,onFocus:b,ref:A,"data-testid":"sentinelEnd"})]})}function chg(e){return typeof e=="function"?e():e}const uhg=U.forwardRef(function(g,I){const{children:i,container:n,disablePortal:C=!1}=g,[r,o]=U.useState(null),a=pn(U.isValidElement(i)?i.ref:null,I);if(Ls(()=>{C||o(chg(n)||document.body)},[n,C]),Ls(()=>{if(r&&!C)return FH(I,r),()=>{FH(I,null)}},[I,r,C]),C){if(U.isValidElement(i)){const s={ref:a};return U.cloneElement(i,s)}return Oe.jsx(U.Fragment,{children:i})}return Oe.jsx(U.Fragment,{children:r&&Aa.createPortal(i,r)})});function dhg(e){const g=zC(e);return g.body===e?Qc(e).innerWidth>g.documentElement.clientWidth:e.scrollHeight>e.clientHeight}function xv(e,g){g?e.setAttribute("aria-hidden","true"):e.removeAttribute("aria-hidden")}function Sue(e){return parseInt(Qc(e).getComputedStyle(e).paddingRight,10)||0}function hhg(e){const I=["TEMPLATE","SCRIPT","STYLE","LINK","MAP","META","NOSCRIPT","PICTURE","COL","COLGROUP","PARAM","SLOT","SOURCE","TRACK"].indexOf(e.tagName)!==-1,i=e.tagName==="INPUT"&&e.getAttribute("type")==="hidden";return I||i}function wue(e,g,I,i,n){const C=[g,I,...i];[].forEach.call(e.children,r=>{const o=C.indexOf(r)===-1,a=!hhg(r);o&&a&&xv(r,n)})}function eE(e,g){let I=-1;return e.some((i,n)=>g(i)?(I=n,!0):!1),I}function mhg(e,g){const I=[],i=e.container;if(!g.disableScrollLock){if(dhg(i)){const r=aNe(zC(i));I.push({value:i.style.paddingRight,property:"padding-right",el:i}),i.style.paddingRight=`${Sue(i)+r}px`;const o=zC(i).querySelectorAll(".mui-fixed");[].forEach.call(o,a=>{I.push({value:a.style.paddingRight,property:"padding-right",el:a}),a.style.paddingRight=`${Sue(a)+r}px`})}let C;if(i.parentNode instanceof DocumentFragment)C=zC(i).body;else{const r=i.parentElement,o=Qc(i);C=(r==null?void 0:r.nodeName)==="HTML"&&o.getComputedStyle(r).overflowY==="scroll"?r:i}I.push({value:C.style.overflow,property:"overflow",el:C},{value:C.style.overflowX,property:"overflow-x",el:C},{value:C.style.overflowY,property:"overflow-y",el:C}),C.style.overflow="hidden"}return()=>{I.forEach(({value:C,el:r,property:o})=>{C?r.style.setProperty(o,C):r.style.removeProperty(o)})}}function fhg(e){const g=[];return[].forEach.call(e.children,I=>{I.getAttribute("aria-hidden")==="true"&&g.push(I)}),g}class phg{constructor(){this.containers=void 0,this.modals=void 0,this.modals=[],this.containers=[]}add(g,I){let i=this.modals.indexOf(g);if(i!==-1)return i;i=this.modals.length,this.modals.push(g),g.modalRef&&xv(g.modalRef,!1);const n=fhg(I);wue(I,g.mount,g.modalRef,n,!0);const C=eE(this.containers,r=>r.container===I);return C!==-1?(this.containers[C].modals.push(g),i):(this.containers.push({modals:[g],container:I,restore:null,hiddenSiblings:n}),i)}mount(g,I){const i=eE(this.containers,C=>C.modals.indexOf(g)!==-1),n=this.containers[i];n.restore||(n.restore=mhg(n,I))}remove(g,I=!0){const i=this.modals.indexOf(g);if(i===-1)return i;const n=eE(this.containers,r=>r.modals.indexOf(g)!==-1),C=this.containers[n];if(C.modals.splice(C.modals.indexOf(g),1),this.modals.splice(i,1),C.modals.length===0)C.restore&&C.restore(),g.modalRef&&xv(g.modalRef,I),wue(C.container,g.mount,g.modalRef,C.hiddenSiblings,!1),this.containers.splice(n,1);else{const r=C.modals[C.modals.length-1];r.modalRef&&xv(r.modalRef,!1)}return i}isTopModal(g){return this.modals.length>0&&this.modals[this.modals.length-1]===g}}function bhg(e){return typeof e=="function"?e():e}function yhg(e){return e?e.props.hasOwnProperty("in"):!1}const Zhg=new phg;function Ghg(e){const{container:g,disableEscapeKeyDown:I=!1,disableScrollLock:i=!1,manager:n=Zhg,closeAfterTransition:C=!1,onTransitionEnter:r,onTransitionExited:o,children:a,onClose:s,open:A,rootRef:l}=e,c=U.useRef({}),u=U.useRef(null),d=U.useRef(null),h=pn(d,l),[m,f]=U.useState(!A),b=yhg(a);let p=!0;(e["aria-hidden"]==="false"||e["aria-hidden"]===!1)&&(p=!1);const y=()=>zC(u.current),Z=()=>(c.current.modalRef=d.current,c.current.mount=u.current,c.current),B=()=>{n.mount(Z(),{disableScrollLock:i}),d.current&&(d.current.scrollTop=0)},G=Zd(()=>{const Y=bhg(g)||y().body;n.add(Z(),Y),d.current&&B()}),v=U.useCallback(()=>n.isTopModal(Z()),[n]),w=Zd(Y=>{u.current=Y,Y&&(A&&v()?B():d.current&&xv(d.current,p))}),V=U.useCallback(()=>{n.remove(Z(),p)},[p,n]);U.useEffect(()=>()=>{V()},[V]),U.useEffect(()=>{A?G():(!b||!C)&&V()},[A,V,b,C,G]);const S=Y=>K=>{var F;(F=Y.onKeyDown)==null||F.call(Y,K),!(K.key!=="Escape"||K.which===229||!v())&&(I||(K.stopPropagation(),s&&s(K,"escapeKeyDown")))},X=Y=>K=>{var F;(F=Y.onClick)==null||F.call(Y,K),K.target===K.currentTarget&&s&&s(K,"backdropClick")};return{getRootProps:(Y={})=>{const K=rke(e);delete K.onTransitionEnter,delete K.onTransitionExited;const F=Ke({},K,Y);return Ke({role:"presentation"},F,{onKeyDown:S(F),ref:h})},getBackdropProps:(Y={})=>{const K=Y;return Ke({"aria-hidden":!0},K,{onClick:X(K),open:A})},getTransitionProps:()=>{const Y=()=>{f(!1),r&&r()},K=()=>{f(!0),o&&o(),C&&V()};return{onEnter:W_(Y,a==null?void 0:a.props.onEnter),onExited:W_(K,a==null?void 0:a.props.onExited)}},rootRef:h,portalRef:w,isTopModal:v,exited:m,hasTransition:b}}const vhg=["onChange","maxRows","minRows","style","value"];function l1(e){return parseInt(e,10)||0}const Bhg={shadow:{visibility:"hidden",position:"absolute",overflow:"hidden",height:0,top:0,left:0,transform:"translateZ(0)"}};function Vue(e){return e==null||Object.keys(e).length===0||e.outerHeightStyle===0&&!e.overflow}const Shg=U.forwardRef(function(g,I){const{onChange:i,maxRows:n,minRows:C=1,style:r,value:o}=g,a=Qt(g,vhg),{current:s}=U.useRef(o!=null),A=U.useRef(null),l=pn(I,A),c=U.useRef(null),u=U.useRef(0),[d,h]=U.useState({outerHeightStyle:0}),m=U.useCallback(()=>{const y=A.current,B=Qc(y).getComputedStyle(y);if(B.width==="0px")return{outerHeightStyle:0};const G=c.current;G.style.width=B.width,G.value=y.value||g.placeholder||"x",G.value.slice(-1)===` +`&&(G.value+=" ");const v=B.boxSizing,w=l1(B.paddingBottom)+l1(B.paddingTop),V=l1(B.borderBottomWidth)+l1(B.borderTopWidth),S=G.scrollHeight;G.value="x";const X=G.scrollHeight;let W=S;C&&(W=Math.max(Number(C)*X,W)),n&&(W=Math.min(Number(n)*X,W)),W=Math.max(W,X);const R=W+(v==="border-box"?w+V:0),H=Math.abs(W-S)<=1;return{outerHeightStyle:R,overflow:H}},[n,C,g.placeholder]),f=(y,Z)=>{const{outerHeightStyle:B,overflow:G}=Z;return u.current<20&&(B>0&&Math.abs((y.outerHeightStyle||0)-B)>1||y.overflow!==G)?(u.current+=1,{overflow:G,outerHeightStyle:B}):y},b=U.useCallback(()=>{const y=m();Vue(y)||h(Z=>f(Z,y))},[m]);Ls(()=>{const y=()=>{const S=m();Vue(S)||Aa.flushSync(()=>{h(X=>f(X,S))})},Z=()=>{u.current=0,y()};let B;const G=h8(Z),v=A.current,w=Qc(v);w.addEventListener("resize",G);let V;return typeof ResizeObserver<"u"&&(V=new ResizeObserver(Z),V.observe(v)),()=>{G.clear(),cancelAnimationFrame(B),w.removeEventListener("resize",G),V&&V.disconnect()}},[m]),Ls(()=>{b()}),U.useEffect(()=>{u.current=0},[o]);const p=y=>{u.current=0,s||b(),i&&i(y)};return Oe.jsxs(U.Fragment,{children:[Oe.jsx("textarea",Ke({value:o,onChange:p,ref:l,rows:C,style:Ke({height:d.outerHeightStyle,overflow:d.overflow?"hidden":void 0},r)},a)),Oe.jsx("textarea",{"aria-hidden":!0,className:g.className,readOnly:!0,ref:c,tabIndex:-1,style:Ke({},Bhg.shadow,r,{paddingTop:0,paddingBottom:0})})]})}),whg=["addEndListener","appear","children","easing","in","onEnter","onEntered","onEntering","onExit","onExited","onExiting","style","timeout","TransitionComponent"];function M_(e){return`scale(${e}, ${e**2})`}const Vhg={entering:{opacity:1,transform:M_(1)},entered:{opacity:1,transform:"none"}},tE=typeof navigator<"u"&&/^((?!chrome|android).)*(safari|mobile)/i.test(navigator.userAgent)&&/(os |version\/)15(.|_)4/i.test(navigator.userAgent),ake=U.forwardRef(function(g,I){const{addEndListener:i,appear:n=!0,children:C,easing:r,in:o,onEnter:a,onEntered:s,onEntering:A,onExit:l,onExited:c,onExiting:u,style:d,timeout:h="auto",TransitionComponent:m=D8}=g,f=Qt(g,whg),b=U.useRef(),p=U.useRef(),y=fy(),Z=U.useRef(null),B=pn(Z,C.ref,I),G=H=>Y=>{if(H){const K=Z.current;Y===void 0?H(K):H(K,Y)}},v=G(A),w=G((H,Y)=>{ONe(H);const{duration:K,delay:F,easing:J}=f0({style:d,timeout:h,easing:r},{mode:"enter"});let P;h==="auto"?(P=y.transitions.getAutoHeightDuration(H.clientHeight),p.current=P):P=K,H.style.transition=[y.transitions.create("opacity",{duration:P,delay:F}),y.transitions.create("transform",{duration:tE?P:P*.666,delay:F,easing:J})].join(","),a&&a(H,Y)}),V=G(s),S=G(u),X=G(H=>{const{duration:Y,delay:K,easing:F}=f0({style:d,timeout:h,easing:r},{mode:"exit"});let J;h==="auto"?(J=y.transitions.getAutoHeightDuration(H.clientHeight),p.current=J):J=Y,H.style.transition=[y.transitions.create("opacity",{duration:J,delay:K}),y.transitions.create("transform",{duration:tE?J:J*.666,delay:tE?K:K||J*.333,easing:F})].join(","),H.style.opacity=0,H.style.transform=M_(.75),l&&l(H)}),W=G(c),R=H=>{h==="auto"&&(b.current=setTimeout(H,p.current||0)),i&&i(Z.current,H)};return U.useEffect(()=>()=>{clearTimeout(b.current)},[]),Oe.jsx(m,Ke({appear:n,in:o,nodeRef:Z,onEnter:w,onEntered:V,onEntering:v,onExit:X,onExited:W,onExiting:S,addEndListener:R,timeout:h==="auto"?null:h},f,{children:(H,Y)=>U.cloneElement(C,Ke({style:Ke({opacity:0,transform:M_(.75),visibility:H==="exited"&&!o?"hidden":void 0},Vhg[H],d,C.props.style),ref:B},Y))}))});ake.muiSupportAuto=!0;const Rhg=ake,Whg=["addEndListener","appear","children","easing","in","onEnter","onEntered","onEntering","onExit","onExited","onExiting","style","timeout","TransitionComponent"],Xhg={entering:{opacity:1},entered:{opacity:1}},Hhg=U.forwardRef(function(g,I){const i=fy(),n={enter:i.transitions.duration.enteringScreen,exit:i.transitions.duration.leavingScreen},{addEndListener:C,appear:r=!0,children:o,easing:a,in:s,onEnter:A,onEntered:l,onEntering:c,onExit:u,onExited:d,onExiting:h,style:m,timeout:f=n,TransitionComponent:b=D8}=g,p=Qt(g,Whg),y=U.useRef(null),Z=pn(y,o.ref,I),B=R=>H=>{if(R){const Y=y.current;H===void 0?R(Y):R(Y,H)}},G=B(c),v=B((R,H)=>{ONe(R);const Y=f0({style:m,timeout:f,easing:a},{mode:"enter"});R.style.webkitTransition=i.transitions.create("opacity",Y),R.style.transition=i.transitions.create("opacity",Y),A&&A(R,H)}),w=B(l),V=B(h),S=B(R=>{const H=f0({style:m,timeout:f,easing:a},{mode:"exit"});R.style.webkitTransition=i.transitions.create("opacity",H),R.style.transition=i.transitions.create("opacity",H),u&&u(R)}),X=B(d),W=R=>{C&&C(y.current,R)};return Oe.jsx(b,Ke({appear:r,in:s,nodeRef:y,onEnter:v,onEntered:w,onEntering:G,onExit:S,onExited:X,onExiting:V,addEndListener:W,timeout:f},p,{children:(R,H)=>U.cloneElement(o,Ke({style:Ke({opacity:0,visibility:R==="exited"&&!s?"hidden":void 0},Xhg[R],m,o.props.style),ref:Z},H))}))}),Thg=Hhg;function Nhg(e){return li("MuiBackdrop",e)}HI("MuiBackdrop",["root","invisible"]);const khg=["children","className","component","components","componentsProps","invisible","open","slotProps","slots","TransitionComponent","transitionDuration"],Yhg=e=>{const{classes:g,invisible:I}=e;return vi({root:["root",I&&"invisible"]},Nhg,g)},Khg=qt("div",{name:"MuiBackdrop",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[g.root,I.invisible&&g.invisible]}})(({ownerState:e})=>Ke({position:"fixed",display:"flex",alignItems:"center",justifyContent:"center",right:0,bottom:0,top:0,left:0,backgroundColor:"rgba(0, 0, 0, 0.5)",WebkitTapHighlightColor:"transparent"},e.invisible&&{backgroundColor:"transparent"})),xhg=U.forwardRef(function(g,I){var i,n,C;const r=gi({props:g,name:"MuiBackdrop"}),{children:o,className:a,component:s="div",components:A={},componentsProps:l={},invisible:c=!1,open:u,slotProps:d={},slots:h={},TransitionComponent:m=Thg,transitionDuration:f}=r,b=Qt(r,khg),p=Ke({},r,{component:s,invisible:c}),y=Yhg(p),Z=(i=d.root)!=null?i:l.root;return Oe.jsx(m,Ke({in:u,timeout:f},b,{children:Oe.jsx(Khg,Ke({"aria-hidden":!0},Z,{as:(n=(C=h.root)!=null?C:A.Root)!=null?n:s,className:ug(y.root,a,Z==null?void 0:Z.className),ownerState:Ke({},p,Z==null?void 0:Z.ownerState),classes:y,ref:I,children:o}))}))}),Dhg=xhg;function Fhg(e){return li("MuiModal",e)}HI("MuiModal",["root","hidden","backdrop"]);const Ehg=["BackdropComponent","BackdropProps","classes","className","closeAfterTransition","children","container","component","components","componentsProps","disableAutoFocus","disableEnforceFocus","disableEscapeKeyDown","disablePortal","disableRestoreFocus","disableScrollLock","hideBackdrop","keepMounted","onBackdropClick","onClose","onTransitionEnter","onTransitionExited","open","slotProps","slots","theme"],Mhg=e=>{const{open:g,exited:I,classes:i}=e;return vi({root:["root",!g&&I&&"hidden"],backdrop:["backdrop"]},Fhg,i)},zhg=qt("div",{name:"MuiModal",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[g.root,!I.open&&I.exited&&g.hidden]}})(({theme:e,ownerState:g})=>Ke({position:"fixed",zIndex:(e.vars||e).zIndex.modal,right:0,bottom:0,top:0,left:0},!g.open&&g.exited&&{visibility:"hidden"})),Phg=qt(Dhg,{name:"MuiModal",slot:"Backdrop",overridesResolver:(e,g)=>g.backdrop})({zIndex:-1}),Jhg=U.forwardRef(function(g,I){var i,n,C,r,o,a;const s=gi({name:"MuiModal",props:g}),{BackdropComponent:A=Phg,BackdropProps:l,className:c,closeAfterTransition:u=!1,children:d,container:h,component:m,components:f={},componentsProps:b={},disableAutoFocus:p=!1,disableEnforceFocus:y=!1,disableEscapeKeyDown:Z=!1,disablePortal:B=!1,disableRestoreFocus:G=!1,disableScrollLock:v=!1,hideBackdrop:w=!1,keepMounted:V=!1,onBackdropClick:S,open:X,slotProps:W,slots:R}=s,H=Qt(s,Ehg),Y=Ke({},s,{closeAfterTransition:u,disableAutoFocus:p,disableEnforceFocus:y,disableEscapeKeyDown:Z,disablePortal:B,disableRestoreFocus:G,disableScrollLock:v,hideBackdrop:w,keepMounted:V}),{getRootProps:K,getBackdropProps:F,getTransitionProps:J,portalRef:P,isTopModal:ge,exited:q,hasTransition:$}=Ghg(Ke({},Y,{rootRef:I})),j=Ke({},Y,{exited:q}),te=Mhg(j),Q={};if(d.props.tabIndex===void 0&&(Q.tabIndex="-1"),$){const{onEnter:We,onExited:Be}=J();Q.onEnter=We,Q.onExited=Be}const ie=(i=(n=R==null?void 0:R.root)!=null?n:f.Root)!=null?i:zhg,he=(C=(r=R==null?void 0:R.backdrop)!=null?r:f.Backdrop)!=null?C:A,ne=(o=W==null?void 0:W.root)!=null?o:b.root,be=(a=W==null?void 0:W.backdrop)!=null?a:b.backdrop,pe=p0({elementType:ie,externalSlotProps:ne,externalForwardedProps:H,getSlotProps:K,additionalProps:{ref:I,as:m},ownerState:j,className:ug(c,ne==null?void 0:ne.className,te==null?void 0:te.root,!j.open&&j.exited&&(te==null?void 0:te.hidden))}),ve=p0({elementType:he,externalSlotProps:be,additionalProps:l,getSlotProps:We=>F(Ke({},We,{onClick:Be=>{S&&S(Be),We!=null&&We.onClick&&We.onClick(Be)}})),className:ug(be==null?void 0:be.className,l==null?void 0:l.className,te==null?void 0:te.backdrop),ownerState:j});return!V&&!X&&(!$||q)?null:Oe.jsx(uhg,{ref:P,container:h,disablePortal:B,children:Oe.jsxs(ie,Ke({},pe,{children:[!w&&A?Oe.jsx(he,Ke({},ve)):null,Oe.jsx(lhg,{disableEnforceFocus:y,disableAutoFocus:p,disableRestoreFocus:G,isEnabled:ge,open:X,children:U.cloneElement(d,Q)})]}))})}),Ohg=Jhg;function _hg(e){return li("MuiPaper",e)}HI("MuiPaper",["root","rounded","outlined","elevation","elevation0","elevation1","elevation2","elevation3","elevation4","elevation5","elevation6","elevation7","elevation8","elevation9","elevation10","elevation11","elevation12","elevation13","elevation14","elevation15","elevation16","elevation17","elevation18","elevation19","elevation20","elevation21","elevation22","elevation23","elevation24"]);const Lhg=["className","component","elevation","square","variant"],Uhg=e=>{const{square:g,elevation:I,variant:i,classes:n}=e,C={root:["root",i,!g&&"rounded",i==="elevation"&&`elevation${I}`]};return vi(C,_hg,n)},Qhg=qt("div",{name:"MuiPaper",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[g.root,g[I.variant],!I.square&&g.rounded,I.variant==="elevation"&&g[`elevation${I.elevation}`]]}})(({theme:e,ownerState:g})=>{var I;return Ke({backgroundColor:(e.vars||e).palette.background.paper,color:(e.vars||e).palette.text.primary,transition:e.transitions.create("box-shadow")},!g.square&&{borderRadius:e.shape.borderRadius},g.variant==="outlined"&&{border:`1px solid ${(e.vars||e).palette.divider}`},g.variant==="elevation"&&Ke({boxShadow:(e.vars||e).shadows[g.elevation]},!e.vars&&e.palette.mode==="dark"&&{backgroundImage:`linear-gradient(${rA("#fff",oue(g.elevation))}, ${rA("#fff",oue(g.elevation))})`},e.vars&&{backgroundImage:(I=e.vars.overlays)==null?void 0:I[g.elevation]}))}),jhg=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiPaper"}),{className:n,component:C="div",elevation:r=1,square:o=!1,variant:a="elevation"}=i,s=Qt(i,Lhg),A=Ke({},i,{component:C,elevation:r,square:o,variant:a}),l=Uhg(A);return Oe.jsx(Qhg,Ke({as:C,ownerState:A,className:ug(l.root,n),ref:I},s))}),$hg=jhg;function qhg(e){return li("MuiPopover",e)}HI("MuiPopover",["root","paper"]);const emg=["onEntering"],tmg=["action","anchorEl","anchorOrigin","anchorPosition","anchorReference","children","className","container","elevation","marginThreshold","open","PaperProps","slots","slotProps","transformOrigin","TransitionComponent","transitionDuration","TransitionProps","disableScrollLock"],gmg=["slotProps"];function Rue(e,g){let I=0;return typeof g=="number"?I=g:g==="center"?I=e.height/2:g==="bottom"&&(I=e.height),I}function Wue(e,g){let I=0;return typeof g=="number"?I=g:g==="center"?I=e.width/2:g==="right"&&(I=e.width),I}function Xue(e){return[e.horizontal,e.vertical].map(g=>typeof g=="number"?`${g}px`:g).join(" ")}function gE(e){return typeof e=="function"?e():e}const Img=e=>{const{classes:g}=e;return vi({root:["root"],paper:["paper"]},qhg,g)},img=qt(Ohg,{name:"MuiPopover",slot:"Root",overridesResolver:(e,g)=>g.root})({}),Ake=qt($hg,{name:"MuiPopover",slot:"Paper",overridesResolver:(e,g)=>g.paper})({position:"absolute",overflowY:"auto",overflowX:"hidden",minWidth:16,minHeight:16,maxWidth:"calc(100% - 32px)",maxHeight:"calc(100% - 32px)",outline:0}),nmg=U.forwardRef(function(g,I){var i,n,C;const r=gi({props:g,name:"MuiPopover"}),{action:o,anchorEl:a,anchorOrigin:s={vertical:"top",horizontal:"left"},anchorPosition:A,anchorReference:l="anchorEl",children:c,className:u,container:d,elevation:h=8,marginThreshold:m=16,open:f,PaperProps:b={},slots:p,slotProps:y,transformOrigin:Z={vertical:"top",horizontal:"left"},TransitionComponent:B=Rhg,transitionDuration:G="auto",TransitionProps:{onEntering:v}={},disableScrollLock:w=!1}=r,V=Qt(r.TransitionProps,emg),S=Qt(r,tmg),X=(i=y==null?void 0:y.paper)!=null?i:b,W=U.useRef(),R=pn(W,X.ref),H=Ke({},r,{anchorOrigin:s,anchorReference:l,elevation:h,marginThreshold:m,externalPaperSlotProps:X,transformOrigin:Z,TransitionComponent:B,transitionDuration:G,TransitionProps:V}),Y=Img(H),K=U.useCallback(()=>{if(l==="anchorPosition")return A;const We=gE(a),Je=(We&&We.nodeType===1?We:zC(W.current).body).getBoundingClientRect();return{top:Je.top+Rue(Je,s.vertical),left:Je.left+Wue(Je,s.horizontal)}},[a,s.horizontal,s.vertical,A,l]),F=U.useCallback(We=>({vertical:Rue(We,Z.vertical),horizontal:Wue(We,Z.horizontal)}),[Z.horizontal,Z.vertical]),J=U.useCallback(We=>{const Be={width:We.offsetWidth,height:We.offsetHeight},Je=F(Be);if(l==="none")return{top:null,left:null,transformOrigin:Xue(Je)};const Pe=K();let De=Pe.top-Je.vertical,Qe=Pe.left-Je.horizontal;const _e=De+Be.height,gt=Qe+Be.width,lt=Qc(gE(a)),tt=lt.innerHeight-m,Xe=lt.innerWidth-m;if(m!==null&&Dett){const ae=_e-tt;De-=ae,Je.vertical+=ae}if(m!==null&&QeXe){const ae=gt-Xe;Qe-=ae,Je.horizontal+=ae}return{top:`${Math.round(De)}px`,left:`${Math.round(Qe)}px`,transformOrigin:Xue(Je)}},[a,l,K,F,m]),[P,ge]=U.useState(f),q=U.useCallback(()=>{const We=W.current;if(!We)return;const Be=J(We);Be.top!==null&&(We.style.top=Be.top),Be.left!==null&&(We.style.left=Be.left),We.style.transformOrigin=Be.transformOrigin,ge(!0)},[J]);U.useEffect(()=>(w&&window.addEventListener("scroll",q),()=>window.removeEventListener("scroll",q)),[a,w,q]);const $=(We,Be)=>{v&&v(We,Be),q()},j=()=>{ge(!1)};U.useEffect(()=>{f&&q()}),U.useImperativeHandle(o,()=>f?{updatePosition:()=>{q()}}:null,[f,q]),U.useEffect(()=>{if(!f)return;const We=h8(()=>{q()}),Be=Qc(a);return Be.addEventListener("resize",We),()=>{We.clear(),Be.removeEventListener("resize",We)}},[a,f,q]);let te=G;G==="auto"&&!B.muiSupportAuto&&(te=void 0);const Q=d||(a?zC(gE(a)).body:void 0),ie=(n=p==null?void 0:p.root)!=null?n:img,he=(C=p==null?void 0:p.paper)!=null?C:Ake,ne=p0({elementType:he,externalSlotProps:Ke({},X,{style:P?X.style:Ke({},X.style,{opacity:0})}),additionalProps:{elevation:h,ref:R},ownerState:H,className:ug(Y.paper,X==null?void 0:X.className)}),be=p0({elementType:ie,externalSlotProps:(y==null?void 0:y.root)||{},externalForwardedProps:S,additionalProps:{ref:I,slotProps:{backdrop:{invisible:!0}},container:Q,open:f},ownerState:H,className:ug(Y.root,u)}),{slotProps:pe}=be,ve=Qt(be,gmg);return Oe.jsx(ie,Ke({},ve,!_H(ie)&&{slotProps:pe,disableScrollLock:w},{children:Oe.jsx(B,Ke({appear:!0,in:f,onEntering:$,onExited:j,timeout:te},V,{children:Oe.jsx(he,Ke({},ne,{children:c}))}))}))}),Cmg=nmg;function rmg(e){return li("MuiMenu",e)}HI("MuiMenu",["root","paper","list"]);const omg=["onEntering"],amg=["autoFocus","children","className","disableAutoFocusItem","MenuListProps","onClose","open","PaperProps","PopoverClasses","transitionDuration","TransitionProps","variant","slots","slotProps"],Amg={vertical:"top",horizontal:"right"},smg={vertical:"top",horizontal:"left"},lmg=e=>{const{classes:g}=e;return vi({root:["root"],paper:["paper"],list:["list"]},rmg,g)},cmg=qt(Cmg,{shouldForwardProp:e=>va(e)||e==="classes",name:"MuiMenu",slot:"Root",overridesResolver:(e,g)=>g.root})({}),umg=qt(Ake,{name:"MuiMenu",slot:"Paper",overridesResolver:(e,g)=>g.paper})({maxHeight:"calc(100% - 96px)",WebkitOverflowScrolling:"touch"}),dmg=qt(nhg,{name:"MuiMenu",slot:"List",overridesResolver:(e,g)=>g.list})({outline:0}),hmg=U.forwardRef(function(g,I){var i,n;const C=gi({props:g,name:"MuiMenu"}),{autoFocus:r=!0,children:o,className:a,disableAutoFocusItem:s=!1,MenuListProps:A={},onClose:l,open:c,PaperProps:u={},PopoverClasses:d,transitionDuration:h="auto",TransitionProps:{onEntering:m}={},variant:f="selectedMenu",slots:b={},slotProps:p={}}=C,y=Qt(C.TransitionProps,omg),Z=Qt(C,amg),B=fy(),G=B.direction==="rtl",v=Ke({},C,{autoFocus:r,disableAutoFocusItem:s,MenuListProps:A,onEntering:m,PaperProps:u,transitionDuration:h,TransitionProps:y,variant:f}),w=lmg(v),V=r&&!s&&c,S=U.useRef(null),X=(J,P)=>{S.current&&S.current.adjustStyleForScrollbar(J,B),m&&m(J,P)},W=J=>{J.key==="Tab"&&(J.preventDefault(),l&&l(J,"tabKeyDown"))};let R=-1;U.Children.map(o,(J,P)=>{U.isValidElement(J)&&(J.props.disabled||(f==="selectedMenu"&&J.props.selected||R===-1)&&(R=P))});const H=(i=b.paper)!=null?i:umg,Y=(n=p.paper)!=null?n:u,K=p0({elementType:b.root,externalSlotProps:p.root,ownerState:v,className:[w.root,a]}),F=p0({elementType:H,externalSlotProps:Y,ownerState:v,className:w.paper});return Oe.jsx(cmg,Ke({onClose:l,anchorOrigin:{vertical:"bottom",horizontal:G?"right":"left"},transformOrigin:G?Amg:smg,slots:{paper:H,root:b.root},slotProps:{root:K,paper:F},open:c,ref:I,transitionDuration:h,TransitionProps:Ke({onEntering:X},y),ownerState:v},Z,{classes:d,children:Oe.jsx(dmg,Ke({onKeyDown:W,actions:S,autoFocus:r&&(R===-1||s),autoFocusItem:V,variant:f},A,{className:ug(w.list,A.className),children:o}))}))}),mmg=hmg;function fmg(e){return li("MuiNativeSelect",e)}const pmg=HI("MuiNativeSelect",["root","select","multiple","filled","outlined","standard","disabled","icon","iconOpen","iconFilled","iconOutlined","iconStandard","nativeInput","error"]),L8=pmg,bmg=["className","disabled","error","IconComponent","inputRef","variant"],ymg=e=>{const{classes:g,variant:I,disabled:i,multiple:n,open:C,error:r}=e,o={select:["select",I,i&&"disabled",n&&"multiple",r&&"error"],icon:["icon",`icon${si(I)}`,C&&"iconOpen",i&&"disabled"]};return vi(o,fmg,g)},ske=({ownerState:e,theme:g})=>Ke({MozAppearance:"none",WebkitAppearance:"none",userSelect:"none",borderRadius:0,cursor:"pointer","&:focus":Ke({},g.vars?{backgroundColor:`rgba(${g.vars.palette.common.onBackgroundChannel} / 0.05)`}:{backgroundColor:g.palette.mode==="light"?"rgba(0, 0, 0, 0.05)":"rgba(255, 255, 255, 0.05)"},{borderRadius:0}),"&::-ms-expand":{display:"none"},[`&.${L8.disabled}`]:{cursor:"default"},"&[multiple]":{height:"auto"},"&:not([multiple]) option, &:not([multiple]) optgroup":{backgroundColor:(g.vars||g).palette.background.paper},"&&&":{paddingRight:24,minWidth:16}},e.variant==="filled"&&{"&&&":{paddingRight:32}},e.variant==="outlined"&&{borderRadius:(g.vars||g).shape.borderRadius,"&:focus":{borderRadius:(g.vars||g).shape.borderRadius},"&&&":{paddingRight:32}}),Zmg=qt("select",{name:"MuiNativeSelect",slot:"Select",shouldForwardProp:va,overridesResolver:(e,g)=>{const{ownerState:I}=e;return[g.select,g[I.variant],I.error&&g.error,{[`&.${L8.multiple}`]:g.multiple}]}})(ske),lke=({ownerState:e,theme:g})=>Ke({position:"absolute",right:0,top:"calc(50% - .5em)",pointerEvents:"none",color:(g.vars||g).palette.action.active,[`&.${L8.disabled}`]:{color:(g.vars||g).palette.action.disabled}},e.open&&{transform:"rotate(180deg)"},e.variant==="filled"&&{right:7},e.variant==="outlined"&&{right:7}),Gmg=qt("svg",{name:"MuiNativeSelect",slot:"Icon",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[g.icon,I.variant&&g[`icon${si(I.variant)}`],I.open&&g.iconOpen]}})(lke),vmg=U.forwardRef(function(g,I){const{className:i,disabled:n,error:C,IconComponent:r,inputRef:o,variant:a="standard"}=g,s=Qt(g,bmg),A=Ke({},g,{disabled:n,variant:a,error:C}),l=ymg(A);return Oe.jsxs(U.Fragment,{children:[Oe.jsx(Zmg,Ke({ownerState:A,className:ug(l.select,i),disabled:n,ref:o||I},s)),g.multiple?null:Oe.jsx(Gmg,{as:r,ownerState:A,className:l.icon})]})}),Bmg=vmg;function Smg(e){return li("MuiSelect",e)}const wmg=HI("MuiSelect",["root","select","multiple","filled","outlined","standard","disabled","focused","icon","iconOpen","iconFilled","iconOutlined","iconStandard","nativeInput","error"]),VZ=wmg;var Hue;const Vmg=["aria-describedby","aria-label","autoFocus","autoWidth","children","className","defaultOpen","defaultValue","disabled","displayEmpty","error","IconComponent","inputRef","labelId","MenuProps","multiple","name","onBlur","onChange","onClose","onFocus","onOpen","open","readOnly","renderValue","SelectDisplayProps","tabIndex","type","value","variant"],Rmg=qt("div",{name:"MuiSelect",slot:"Select",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[{[`&.${VZ.select}`]:g.select},{[`&.${VZ.select}`]:g[I.variant]},{[`&.${VZ.error}`]:g.error},{[`&.${VZ.multiple}`]:g.multiple}]}})(ske,{[`&.${VZ.select}`]:{height:"auto",minHeight:"1.4375em",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}}),Wmg=qt("svg",{name:"MuiSelect",slot:"Icon",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[g.icon,I.variant&&g[`icon${si(I.variant)}`],I.open&&g.iconOpen]}})(lke),Xmg=qt("input",{shouldForwardProp:e=>Acg(e)&&e!=="classes",name:"MuiSelect",slot:"NativeInput",overridesResolver:(e,g)=>g.nativeInput})({bottom:0,left:0,position:"absolute",opacity:0,pointerEvents:"none",width:"100%",boxSizing:"border-box"});function Tue(e,g){return typeof g=="object"&&g!==null?e===g:String(e)===String(g)}function Hmg(e){return e==null||typeof e=="string"&&!e.trim()}const Tmg=e=>{const{classes:g,variant:I,disabled:i,multiple:n,open:C,error:r}=e,o={select:["select",I,i&&"disabled",n&&"multiple",r&&"error"],icon:["icon",`icon${si(I)}`,C&&"iconOpen",i&&"disabled"],nativeInput:["nativeInput"]};return vi(o,Smg,g)},Nmg=U.forwardRef(function(g,I){var i;const{"aria-describedby":n,"aria-label":C,autoFocus:r,autoWidth:o,children:a,className:s,defaultOpen:A,defaultValue:l,disabled:c,displayEmpty:u,error:d=!1,IconComponent:h,inputRef:m,labelId:f,MenuProps:b={},multiple:p,name:y,onBlur:Z,onChange:B,onClose:G,onFocus:v,onOpen:w,open:V,readOnly:S,renderValue:X,SelectDisplayProps:W={},tabIndex:R,value:H,variant:Y="standard"}=g,K=Qt(g,Vmg),[F,J]=X_({controlled:H,default:l,name:"Select"}),[P,ge]=X_({controlled:V,default:A,name:"Select"}),q=U.useRef(null),$=U.useRef(null),[j,te]=U.useState(null),{current:Q}=U.useRef(V!=null),[ie,he]=U.useState(),ne=pn(I,m),be=U.useCallback(we=>{$.current=we,we&&te(we)},[]),pe=j==null?void 0:j.parentNode;U.useImperativeHandle(ne,()=>({focus:()=>{$.current.focus()},node:q.current,value:F}),[F]),U.useEffect(()=>{A&&P&&j&&!Q&&(he(o?null:pe.clientWidth),$.current.focus())},[j,o]),U.useEffect(()=>{r&&$.current.focus()},[r]),U.useEffect(()=>{if(!f)return;const we=zC($.current).getElementById(f);if(we){const je=()=>{getSelection().isCollapsed&&$.current.focus()};return we.addEventListener("click",je),()=>{we.removeEventListener("click",je)}}},[f]);const ve=(we,je)=>{we?w&&w(je):G&&G(je),Q||(he(o?null:pe.clientWidth),ge(we))},We=we=>{we.button===0&&(we.preventDefault(),$.current.focus(),ve(!0,we))},Be=we=>{ve(!1,we)},Je=U.Children.toArray(a),Pe=we=>{const je=Je.find(at=>at.props.value===we.target.value);je!==void 0&&(J(je.props.value),B&&B(we,je))},De=we=>je=>{let at;if(je.currentTarget.hasAttribute("tabindex")){if(p){at=Array.isArray(F)?F.slice():[];const bt=F.indexOf(we.props.value);bt===-1?at.push(we.props.value):at.splice(bt,1)}else at=we.props.value;if(we.props.onClick&&we.props.onClick(je),F!==at&&(J(at),B)){const bt=je.nativeEvent||je,ct=new bt.constructor(bt.type,bt);Object.defineProperty(ct,"target",{writable:!0,value:{value:at,name:y}}),B(ct,we)}p||ve(!1,je)}},Qe=we=>{S||[" ","ArrowUp","ArrowDown","Enter"].indexOf(we.key)!==-1&&(we.preventDefault(),ve(!0,we))},_e=j!==null&&P,gt=we=>{!_e&&Z&&(Object.defineProperty(we,"target",{writable:!0,value:{value:F,name:y}}),Z(we))};delete K["aria-invalid"];let lt,tt;const Xe=[];let ae=!1;(OH({value:F})||u)&&(X?lt=X(F):ae=!0);const ye=Je.map(we=>{if(!U.isValidElement(we))return null;let je;if(p){if(!Array.isArray(F))throw new Error(Uc(2));je=F.some(at=>Tue(at,we.props.value)),je&&ae&&Xe.push(we.props.children)}else je=Tue(F,we.props.value),je&&ae&&(tt=we.props.children);return U.cloneElement(we,{"aria-selected":je?"true":"false",onClick:De(we),onKeyUp:at=>{at.key===" "&&at.preventDefault(),we.props.onKeyUp&&we.props.onKeyUp(at)},role:"option",selected:je,value:void 0,"data-value":we.props.value})});ae&&(p?Xe.length===0?lt=null:lt=Xe.reduce((we,je,at)=>(we.push(je),at{const{ownerState:I}=e;return[g.root,I.formControl&&g.formControl,I.startAdornment&&g.adornedStart,I.endAdornment&&g.adornedEnd,I.error&&g.error,I.size==="small"&&g.sizeSmall,I.multiline&&g.multiline,I.color&&g[`color${si(I.color)}`],I.fullWidth&&g.fullWidth,I.hiddenLabel&&g.hiddenLabel]},MY=(e,g)=>{const{ownerState:I}=e;return[g.input,I.size==="small"&&g.inputSizeSmall,I.multiline&&g.inputMultiline,I.type==="search"&&g.inputTypeSearch,I.startAdornment&&g.inputAdornedStart,I.endAdornment&&g.inputAdornedEnd,I.hiddenLabel&&g.inputHiddenLabel]},Emg=e=>{const{classes:g,color:I,disabled:i,error:n,endAdornment:C,focused:r,formControl:o,fullWidth:a,hiddenLabel:s,multiline:A,readOnly:l,size:c,startAdornment:u,type:d}=e,h={root:["root",`color${si(I)}`,i&&"disabled",n&&"error",a&&"fullWidth",r&&"focused",o&&"formControl",c&&c!=="medium"&&`size${si(c)}`,A&&"multiline",u&&"adornedStart",C&&"adornedEnd",s&&"hiddenLabel",l&&"readOnly"],input:["input",i&&"disabled",d==="search"&&"inputTypeSearch",A&&"inputMultiline",c==="small"&&"inputSizeSmall",s&&"inputHiddenLabel",u&&"inputAdornedStart",C&&"inputAdornedEnd",l&&"readOnly"]};return vi(h,xmg,g)},zY=qt("div",{name:"MuiInputBase",slot:"Root",overridesResolver:EY})(({theme:e,ownerState:g})=>Ke({},e.typography.body1,{color:(e.vars||e).palette.text.primary,lineHeight:"1.4375em",boxSizing:"border-box",position:"relative",cursor:"text",display:"inline-flex",alignItems:"center",[`&.${b0.disabled}`]:{color:(e.vars||e).palette.text.disabled,cursor:"default"}},g.multiline&&Ke({padding:"4px 0 5px"},g.size==="small"&&{paddingTop:1}),g.fullWidth&&{width:"100%"})),PY=qt("input",{name:"MuiInputBase",slot:"Input",overridesResolver:MY})(({theme:e,ownerState:g})=>{const I=e.palette.mode==="light",i=Ke({color:"currentColor"},e.vars?{opacity:e.vars.opacity.inputPlaceholder}:{opacity:I?.42:.5},{transition:e.transitions.create("opacity",{duration:e.transitions.duration.shorter})}),n={opacity:"0 !important"},C=e.vars?{opacity:e.vars.opacity.inputPlaceholder}:{opacity:I?.42:.5};return Ke({font:"inherit",letterSpacing:"inherit",color:"currentColor",padding:"4px 0 5px",border:0,boxSizing:"content-box",background:"none",height:"1.4375em",margin:0,WebkitTapHighlightColor:"transparent",display:"block",minWidth:0,width:"100%",animationName:"mui-auto-fill-cancel",animationDuration:"10ms","&::-webkit-input-placeholder":i,"&::-moz-placeholder":i,"&:-ms-input-placeholder":i,"&::-ms-input-placeholder":i,"&:focus":{outline:0},"&:invalid":{boxShadow:"none"},"&::-webkit-search-decoration":{WebkitAppearance:"none"},[`label[data-shrink=false] + .${b0.formControl} &`]:{"&::-webkit-input-placeholder":n,"&::-moz-placeholder":n,"&:-ms-input-placeholder":n,"&::-ms-input-placeholder":n,"&:focus::-webkit-input-placeholder":C,"&:focus::-moz-placeholder":C,"&:focus:-ms-input-placeholder":C,"&:focus::-ms-input-placeholder":C},[`&.${b0.disabled}`]:{opacity:1,WebkitTextFillColor:(e.vars||e).palette.text.disabled},"&:-webkit-autofill":{animationDuration:"5000s",animationName:"mui-auto-fill"}},g.size==="small"&&{paddingTop:1},g.multiline&&{height:"auto",resize:"none",padding:0,paddingTop:0},g.type==="search"&&{MozAppearance:"textfield"})}),Mmg=Oe.jsx(Kmg,{styles:{"@keyframes mui-auto-fill":{from:{display:"block"}},"@keyframes mui-auto-fill-cancel":{from:{display:"block"}}}}),zmg=U.forwardRef(function(g,I){var i;const n=gi({props:g,name:"MuiInputBase"}),{"aria-describedby":C,autoComplete:r,autoFocus:o,className:a,components:s={},componentsProps:A={},defaultValue:l,disabled:c,disableInjectingGlobalStyles:u,endAdornment:d,fullWidth:h=!1,id:m,inputComponent:f="input",inputProps:b={},inputRef:p,maxRows:y,minRows:Z,multiline:B=!1,name:G,onBlur:v,onChange:w,onClick:V,onFocus:S,onKeyDown:X,onKeyUp:W,placeholder:R,readOnly:H,renderSuffix:Y,rows:K,slotProps:F={},slots:J={},startAdornment:P,type:ge="text",value:q}=n,$=Qt(n,Fmg),j=b.value!=null?b.value:q,{current:te}=U.useRef(j!=null),Q=U.useRef(),ie=U.useCallback(T=>{},[]),he=pn(Q,p,b.ref,ie),[ne,be]=U.useState(!1),pe=Pw(),ve=Jw({props:n,muiFormControl:pe,states:["color","disabled","error","hiddenLabel","size","required","filled"]});ve.focused=pe?pe.focused:ne,U.useEffect(()=>{!pe&&c&&ne&&(be(!1),v&&v())},[pe,c,ne,v]);const We=pe&&pe.onFilled,Be=pe&&pe.onEmpty,Je=U.useCallback(T=>{OH(T)?We&&We():Be&&Be()},[We,Be]);Ls(()=>{te&&Je({value:j})},[j,Je,te]);const Pe=T=>{if(ve.disabled){T.stopPropagation();return}S&&S(T),b.onFocus&&b.onFocus(T),pe&&pe.onFocus?pe.onFocus(T):be(!0)},De=T=>{v&&v(T),b.onBlur&&b.onBlur(T),pe&&pe.onBlur?pe.onBlur(T):be(!1)},Qe=(T,...k)=>{if(!te){const Ie=T.target||Q.current;if(Ie==null)throw new Error(Uc(1));Je({value:Ie.value})}b.onChange&&b.onChange(T,...k),w&&w(T,...k)};U.useEffect(()=>{Je(Q.current)},[]);const _e=T=>{Q.current&&T.currentTarget===T.target&&Q.current.focus(),V&&V(T)};let gt=f,lt=b;B&>==="input"&&(K?lt=Ke({type:void 0,minRows:K,maxRows:K},lt):lt=Ke({type:void 0,maxRows:y,minRows:Z},lt),gt=Shg);const tt=T=>{Je(T.animationName==="mui-auto-fill-cancel"?Q.current:{value:"x"})};U.useEffect(()=>{pe&&pe.setAdornedStart(!!P)},[pe,P]);const Xe=Ke({},n,{color:ve.color||"primary",disabled:ve.disabled,endAdornment:d,error:ve.error,focused:ve.focused,formControl:pe,fullWidth:h,hiddenLabel:ve.hiddenLabel,multiline:B,size:ve.size,startAdornment:P,type:ge}),ae=Emg(Xe),ye=J.root||s.Root||zY,He=F.root||A.root||{},x=J.input||s.Input||PY;return lt=Ke({},lt,(i=F.input)!=null?i:A.input),Oe.jsxs(U.Fragment,{children:[!u&&Mmg,Oe.jsxs(ye,Ke({},He,!_H(ye)&&{ownerState:Ke({},Xe,He.ownerState)},{ref:I,onClick:_e},$,{className:ug(ae.root,He.className,a,H&&"MuiInputBase-readOnly"),children:[P,Oe.jsx(_8.Provider,{value:null,children:Oe.jsx(x,Ke({ownerState:Xe,"aria-invalid":ve.error,"aria-describedby":C,autoComplete:r,autoFocus:o,defaultValue:l,disabled:ve.disabled,id:m,onAnimationStart:tt,name:G,placeholder:R,readOnly:H,required:ve.required,rows:K,value:j,onKeyDown:X,onKeyUp:W,type:ge},lt,!_H(x)&&{as:gt,ownerState:Ke({},Xe,lt.ownerState)},{ref:he,className:ug(ae.input,lt.className,H&&"MuiInputBase-readOnly"),onBlur:De,onChange:Qe,onFocus:Pe}))}),d,Y?Y(Ke({},ve,{startAdornment:P})):null]}))]})}),U8=zmg;function Pmg(e){return li("MuiInput",e)}const Jmg=Ke({},b0,HI("MuiInput",["root","underline","input"])),RZ=Jmg,Omg=["disableUnderline","components","componentsProps","fullWidth","inputComponent","multiline","slotProps","slots","type"],_mg=e=>{const{classes:g,disableUnderline:I}=e,n=vi({root:["root",!I&&"underline"],input:["input"]},Pmg,g);return Ke({},g,n)},Lmg=qt(zY,{shouldForwardProp:e=>va(e)||e==="classes",name:"MuiInput",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[...EY(e,g),!I.disableUnderline&&g.underline]}})(({theme:e,ownerState:g})=>{let i=e.palette.mode==="light"?"rgba(0, 0, 0, 0.42)":"rgba(255, 255, 255, 0.7)";return e.vars&&(i=`rgba(${e.vars.palette.common.onBackgroundChannel} / ${e.vars.opacity.inputUnderline})`),Ke({position:"relative"},g.formControl&&{"label + &":{marginTop:16}},!g.disableUnderline&&{"&:after":{borderBottom:`2px solid ${(e.vars||e).palette[g.color].main}`,left:0,bottom:0,content:'""',position:"absolute",right:0,transform:"scaleX(0)",transition:e.transitions.create("transform",{duration:e.transitions.duration.shorter,easing:e.transitions.easing.easeOut}),pointerEvents:"none"},[`&.${RZ.focused}:after`]:{transform:"scaleX(1) translateX(0)"},[`&.${RZ.error}`]:{"&:before, &:after":{borderBottomColor:(e.vars||e).palette.error.main}},"&:before":{borderBottom:`1px solid ${i}`,left:0,bottom:0,content:'"\\00a0"',position:"absolute",right:0,transition:e.transitions.create("border-bottom-color",{duration:e.transitions.duration.shorter}),pointerEvents:"none"},[`&:hover:not(.${RZ.disabled}, .${RZ.error}):before`]:{borderBottom:`2px solid ${(e.vars||e).palette.text.primary}`,"@media (hover: none)":{borderBottom:`1px solid ${i}`}},[`&.${RZ.disabled}:before`]:{borderBottomStyle:"dotted"}})}),Umg=qt(PY,{name:"MuiInput",slot:"Input",overridesResolver:MY})({}),cke=U.forwardRef(function(g,I){var i,n,C,r;const o=gi({props:g,name:"MuiInput"}),{disableUnderline:a,components:s={},componentsProps:A,fullWidth:l=!1,inputComponent:c="input",multiline:u=!1,slotProps:d,slots:h={},type:m="text"}=o,f=Qt(o,Omg),b=_mg(o),y={root:{ownerState:{disableUnderline:a}}},Z=d??A?MC(d??A,y):y,B=(i=(n=h.root)!=null?n:s.Root)!=null?i:Lmg,G=(C=(r=h.input)!=null?r:s.Input)!=null?C:Umg;return Oe.jsx(U8,Ke({slots:{root:B,input:G},slotProps:Z,fullWidth:l,inputComponent:c,multiline:u,ref:I,type:m},f,{classes:b}))});cke.muiName="Input";const Qmg=cke;function jmg(e){return li("MuiFilledInput",e)}const $mg=Ke({},b0,HI("MuiFilledInput",["root","underline","input"])),Eu=$mg,qmg=["disableUnderline","components","componentsProps","fullWidth","hiddenLabel","inputComponent","multiline","slotProps","slots","type"],efg=e=>{const{classes:g,disableUnderline:I}=e,n=vi({root:["root",!I&&"underline"],input:["input"]},jmg,g);return Ke({},g,n)},tfg=qt(zY,{shouldForwardProp:e=>va(e)||e==="classes",name:"MuiFilledInput",slot:"Root",overridesResolver:(e,g)=>{const{ownerState:I}=e;return[...EY(e,g),!I.disableUnderline&&g.underline]}})(({theme:e,ownerState:g})=>{var I;const i=e.palette.mode==="light",n=i?"rgba(0, 0, 0, 0.42)":"rgba(255, 255, 255, 0.7)",C=i?"rgba(0, 0, 0, 0.06)":"rgba(255, 255, 255, 0.09)",r=i?"rgba(0, 0, 0, 0.09)":"rgba(255, 255, 255, 0.13)",o=i?"rgba(0, 0, 0, 0.12)":"rgba(255, 255, 255, 0.12)";return Ke({position:"relative",backgroundColor:e.vars?e.vars.palette.FilledInput.bg:C,borderTopLeftRadius:(e.vars||e).shape.borderRadius,borderTopRightRadius:(e.vars||e).shape.borderRadius,transition:e.transitions.create("background-color",{duration:e.transitions.duration.shorter,easing:e.transitions.easing.easeOut}),"&:hover":{backgroundColor:e.vars?e.vars.palette.FilledInput.hoverBg:r,"@media (hover: none)":{backgroundColor:e.vars?e.vars.palette.FilledInput.bg:C}},[`&.${Eu.focused}`]:{backgroundColor:e.vars?e.vars.palette.FilledInput.bg:C},[`&.${Eu.disabled}`]:{backgroundColor:e.vars?e.vars.palette.FilledInput.disabledBg:o}},!g.disableUnderline&&{"&:after":{borderBottom:`2px solid ${(I=(e.vars||e).palette[g.color||"primary"])==null?void 0:I.main}`,left:0,bottom:0,content:'""',position:"absolute",right:0,transform:"scaleX(0)",transition:e.transitions.create("transform",{duration:e.transitions.duration.shorter,easing:e.transitions.easing.easeOut}),pointerEvents:"none"},[`&.${Eu.focused}:after`]:{transform:"scaleX(1) translateX(0)"},[`&.${Eu.error}`]:{"&:before, &:after":{borderBottomColor:(e.vars||e).palette.error.main}},"&:before":{borderBottom:`1px solid ${e.vars?`rgba(${e.vars.palette.common.onBackgroundChannel} / ${e.vars.opacity.inputUnderline})`:n}`,left:0,bottom:0,content:'"\\00a0"',position:"absolute",right:0,transition:e.transitions.create("border-bottom-color",{duration:e.transitions.duration.shorter}),pointerEvents:"none"},[`&:hover:not(.${Eu.disabled}, .${Eu.error}):before`]:{borderBottom:`1px solid ${(e.vars||e).palette.text.primary}`},[`&.${Eu.disabled}:before`]:{borderBottomStyle:"dotted"}},g.startAdornment&&{paddingLeft:12},g.endAdornment&&{paddingRight:12},g.multiline&&Ke({padding:"25px 12px 8px"},g.size==="small"&&{paddingTop:21,paddingBottom:4},g.hiddenLabel&&{paddingTop:16,paddingBottom:17},g.hiddenLabel&&g.size==="small"&&{paddingTop:8,paddingBottom:9}))}),gfg=qt(PY,{name:"MuiFilledInput",slot:"Input",overridesResolver:MY})(({theme:e,ownerState:g})=>Ke({paddingTop:25,paddingRight:12,paddingBottom:8,paddingLeft:12},!e.vars&&{"&:-webkit-autofill":{WebkitBoxShadow:e.palette.mode==="light"?null:"0 0 0 100px #266798 inset",WebkitTextFillColor:e.palette.mode==="light"?null:"#fff",caretColor:e.palette.mode==="light"?null:"#fff",borderTopLeftRadius:"inherit",borderTopRightRadius:"inherit"}},e.vars&&{"&:-webkit-autofill":{borderTopLeftRadius:"inherit",borderTopRightRadius:"inherit"},[e.getColorSchemeSelector("dark")]:{"&:-webkit-autofill":{WebkitBoxShadow:"0 0 0 100px #266798 inset",WebkitTextFillColor:"#fff",caretColor:"#fff"}}},g.size==="small"&&{paddingTop:21,paddingBottom:4},g.hiddenLabel&&{paddingTop:16,paddingBottom:17},g.startAdornment&&{paddingLeft:0},g.endAdornment&&{paddingRight:0},g.hiddenLabel&&g.size==="small"&&{paddingTop:8,paddingBottom:9},g.multiline&&{paddingTop:0,paddingBottom:0,paddingLeft:0,paddingRight:0})),uke=U.forwardRef(function(g,I){var i,n,C,r;const o=gi({props:g,name:"MuiFilledInput"}),{components:a={},componentsProps:s,fullWidth:A=!1,inputComponent:l="input",multiline:c=!1,slotProps:u,slots:d={},type:h="text"}=o,m=Qt(o,qmg),f=Ke({},o,{fullWidth:A,inputComponent:l,multiline:c,type:h}),b=efg(o),p={root:{ownerState:f},input:{ownerState:f}},y=u??s?MC(p,u??s):p,Z=(i=(n=d.root)!=null?n:a.Root)!=null?i:tfg,B=(C=(r=d.input)!=null?r:a.Input)!=null?C:gfg;return Oe.jsx(U8,Ke({slots:{root:Z,input:B},componentsProps:y,fullWidth:A,inputComponent:l,multiline:c,ref:I,type:h},m,{classes:b}))});uke.muiName="Input";const Ifg=uke;var Nue;const ifg=["children","classes","className","label","notched"],nfg=qt("fieldset",{shouldForwardProp:va})({textAlign:"left",position:"absolute",bottom:0,right:0,top:-5,left:0,margin:0,padding:"0 8px",pointerEvents:"none",borderRadius:"inherit",borderStyle:"solid",borderWidth:1,overflow:"hidden",minWidth:"0%"}),Cfg=qt("legend",{shouldForwardProp:va})(({ownerState:e,theme:g})=>Ke({float:"unset",width:"auto",overflow:"hidden"},!e.withLabel&&{padding:0,lineHeight:"11px",transition:g.transitions.create("width",{duration:150,easing:g.transitions.easing.easeOut})},e.withLabel&&Ke({display:"block",padding:0,height:11,fontSize:"0.75em",visibility:"hidden",maxWidth:.01,transition:g.transitions.create("max-width",{duration:50,easing:g.transitions.easing.easeOut}),whiteSpace:"nowrap","& > span":{paddingLeft:5,paddingRight:5,display:"inline-block",opacity:0,visibility:"visible"}},e.notched&&{maxWidth:"100%",transition:g.transitions.create("max-width",{duration:100,easing:g.transitions.easing.easeOut,delay:50})})));function rfg(e){const{className:g,label:I,notched:i}=e,n=Qt(e,ifg),C=I!=null&&I!=="",r=Ke({},e,{notched:i,withLabel:C});return Oe.jsx(nfg,Ke({"aria-hidden":!0,className:g,ownerState:r},n,{children:Oe.jsx(Cfg,{ownerState:r,children:C?Oe.jsx("span",{children:I}):Nue||(Nue=Oe.jsx("span",{className:"notranslate",children:"​"}))})}))}function ofg(e){return li("MuiOutlinedInput",e)}const afg=Ke({},b0,HI("MuiOutlinedInput",["root","notchedOutline","input"])),Rl=afg,Afg=["components","fullWidth","inputComponent","label","multiline","notched","slots","type"],sfg=e=>{const{classes:g}=e,i=vi({root:["root"],notchedOutline:["notchedOutline"],input:["input"]},ofg,g);return Ke({},g,i)},lfg=qt(zY,{shouldForwardProp:e=>va(e)||e==="classes",name:"MuiOutlinedInput",slot:"Root",overridesResolver:EY})(({theme:e,ownerState:g})=>{const I=e.palette.mode==="light"?"rgba(0, 0, 0, 0.23)":"rgba(255, 255, 255, 0.23)";return Ke({position:"relative",borderRadius:(e.vars||e).shape.borderRadius,[`&:hover .${Rl.notchedOutline}`]:{borderColor:(e.vars||e).palette.text.primary},"@media (hover: none)":{[`&:hover .${Rl.notchedOutline}`]:{borderColor:e.vars?`rgba(${e.vars.palette.common.onBackgroundChannel} / 0.23)`:I}},[`&.${Rl.focused} .${Rl.notchedOutline}`]:{borderColor:(e.vars||e).palette[g.color].main,borderWidth:2},[`&.${Rl.error} .${Rl.notchedOutline}`]:{borderColor:(e.vars||e).palette.error.main},[`&.${Rl.disabled} .${Rl.notchedOutline}`]:{borderColor:(e.vars||e).palette.action.disabled}},g.startAdornment&&{paddingLeft:14},g.endAdornment&&{paddingRight:14},g.multiline&&Ke({padding:"16.5px 14px"},g.size==="small"&&{padding:"8.5px 14px"}))}),cfg=qt(rfg,{name:"MuiOutlinedInput",slot:"NotchedOutline",overridesResolver:(e,g)=>g.notchedOutline})(({theme:e})=>{const g=e.palette.mode==="light"?"rgba(0, 0, 0, 0.23)":"rgba(255, 255, 255, 0.23)";return{borderColor:e.vars?`rgba(${e.vars.palette.common.onBackgroundChannel} / 0.23)`:g}}),ufg=qt(PY,{name:"MuiOutlinedInput",slot:"Input",overridesResolver:MY})(({theme:e,ownerState:g})=>Ke({padding:"16.5px 14px"},!e.vars&&{"&:-webkit-autofill":{WebkitBoxShadow:e.palette.mode==="light"?null:"0 0 0 100px #266798 inset",WebkitTextFillColor:e.palette.mode==="light"?null:"#fff",caretColor:e.palette.mode==="light"?null:"#fff",borderRadius:"inherit"}},e.vars&&{"&:-webkit-autofill":{borderRadius:"inherit"},[e.getColorSchemeSelector("dark")]:{"&:-webkit-autofill":{WebkitBoxShadow:"0 0 0 100px #266798 inset",WebkitTextFillColor:"#fff",caretColor:"#fff"}}},g.size==="small"&&{padding:"8.5px 14px"},g.multiline&&{padding:0},g.startAdornment&&{paddingLeft:0},g.endAdornment&&{paddingRight:0})),dke=U.forwardRef(function(g,I){var i,n,C,r,o;const a=gi({props:g,name:"MuiOutlinedInput"}),{components:s={},fullWidth:A=!1,inputComponent:l="input",label:c,multiline:u=!1,notched:d,slots:h={},type:m="text"}=a,f=Qt(a,Afg),b=sfg(a),p=Pw(),y=Jw({props:a,muiFormControl:p,states:["color","disabled","error","focused","hiddenLabel","size","required"]}),Z=Ke({},a,{color:y.color||"primary",disabled:y.disabled,error:y.error,focused:y.focused,formControl:p,fullWidth:A,hiddenLabel:y.hiddenLabel,multiline:u,size:y.size,type:m}),B=(i=(n=h.root)!=null?n:s.Root)!=null?i:lfg,G=(C=(r=h.input)!=null?r:s.Input)!=null?C:ufg;return Oe.jsx(U8,Ke({slots:{root:B,input:G},renderSuffix:v=>Oe.jsx(cfg,{ownerState:Z,className:b.notchedOutline,label:c!=null&&c!==""&&y.required?o||(o=Oe.jsxs(U.Fragment,{children:[c," ","*"]})):c,notched:typeof d<"u"?d:!!(v.startAdornment||v.filled||v.focused)}),fullWidth:A,inputComponent:l,multiline:u,ref:I,type:m},f,{classes:Ke({},b,{notchedOutline:null})}))});dke.muiName="Input";const dfg=dke,hfg=["autoWidth","children","classes","className","defaultOpen","displayEmpty","IconComponent","id","input","inputProps","label","labelId","MenuProps","multiple","native","onClose","onOpen","open","renderValue","SelectDisplayProps","variant"],mfg=["root"],ffg=e=>{const{classes:g}=e;return g},Q8={name:"MuiSelect",overridesResolver:(e,g)=>g.root,shouldForwardProp:e=>va(e)&&e!=="variant",slot:"Root"},pfg=qt(Qmg,Q8)(""),bfg=qt(dfg,Q8)(""),yfg=qt(Ifg,Q8)(""),hke=U.forwardRef(function(g,I){const i=gi({name:"MuiSelect",props:g}),{autoWidth:n=!1,children:C,classes:r={},className:o,defaultOpen:a=!1,displayEmpty:s=!1,IconComponent:A=Ymg,id:l,input:c,inputProps:u,label:d,labelId:h,MenuProps:m,multiple:f=!1,native:b=!1,onClose:p,onOpen:y,open:Z,renderValue:B,SelectDisplayProps:G,variant:v="outlined"}=i,w=Qt(i,hfg),V=b?Bmg:kmg,S=Pw(),X=Jw({props:i,muiFormControl:S,states:["variant","error"]}),W=X.variant||v,R=Ke({},i,{variant:W,classes:r}),H=ffg(R),Y=Qt(H,mfg),K=c||{standard:Oe.jsx(pfg,{ownerState:R}),outlined:Oe.jsx(bfg,{label:d,ownerState:R}),filled:Oe.jsx(yfg,{ownerState:R})}[W],F=pn(I,K.ref);return Oe.jsx(U.Fragment,{children:U.cloneElement(K,Ke({inputComponent:V,inputProps:Ke({children:C,error:X.error,IconComponent:A,variant:W,type:void 0,multiple:f},b?{id:l}:{autoWidth:n,defaultOpen:a,displayEmpty:s,labelId:h,MenuProps:m,onClose:p,onOpen:y,open:Z,renderValue:B,SelectDisplayProps:Ke({id:l},G)},u,{classes:u?MC(Y,u.classes):Y},c?c.props.inputProps:{})},f&&b&&W==="outlined"?{notched:!0}:{},{ref:F,className:ug(K.props.className,o,H.root)},!c&&{variant:W},w))})});hke.muiName="Select";const Zfg=hke;function Gfg(e){const{className:g,classes:I,pulsate:i=!1,rippleX:n,rippleY:C,rippleSize:r,in:o,onExited:a,timeout:s}=e,[A,l]=U.useState(!1),c=ug(g,I.ripple,I.rippleVisible,i&&I.ripplePulsate),u={width:r,height:r,top:-(r/2)+C,left:-(r/2)+n},d=ug(I.child,A&&I.childLeaving,i&&I.childPulsate);return!o&&!A&&l(!0),U.useEffect(()=>{if(!o&&a!=null){const h=setTimeout(a,s);return()=>{clearTimeout(h)}}},[a,o,s]),Oe.jsx("span",{className:c,style:u,children:Oe.jsx("span",{className:d})})}const vfg=HI("MuiTouchRipple",["root","ripple","rippleVisible","ripplePulsate","child","childLeaving","childPulsate"]),Yr=vfg,Bfg=["center","classes","className"];let JY=e=>e,kue,Yue,Kue,xue;const z_=550,Sfg=80,wfg=B8(kue||(kue=JY` 0% { transform: scale(0); opacity: 0.1; @@ -2029,7 +2029,7 @@ ${s}`:s,l=Tet(o).parse(A,c=>SI(this,x$,t2e).call(this,c,r,I,i));if(C&&((g=l[0])! transform: scale(1); opacity: 0.3; } -`)),vfg=B8(Yue||(Yue=JY` +`)),Vfg=B8(Yue||(Yue=JY` 0% { opacity: 1; } @@ -2037,7 +2037,7 @@ ${s}`:s,l=Tet(o).parse(A,c=>SI(this,x$,t2e).call(this,c,r,I,i));if(C&&((g=l[0])! 100% { opacity: 0; } -`)),Bfg=B8(Kue||(Kue=JY` +`)),Rfg=B8(Kue||(Kue=JY` 0% { transform: scale(1); } @@ -2049,7 +2049,7 @@ ${s}`:s,l=Tet(o).parse(A,c=>SI(this,x$,t2e).call(this,c,r,I,i));if(C&&((g=l[0])! 100% { transform: scale(1); } -`)),Sfg=qt("span",{name:"MuiTouchRipple",slot:"Root"})({overflow:"hidden",pointerEvents:"none",position:"absolute",zIndex:0,top:0,right:0,bottom:0,left:0,borderRadius:"inherit"}),wfg=qt(pfg,{name:"MuiTouchRipple",slot:"Ripple"})(xue||(xue=JY` +`)),Wfg=qt("span",{name:"MuiTouchRipple",slot:"Root"})({overflow:"hidden",pointerEvents:"none",position:"absolute",zIndex:0,top:0,right:0,bottom:0,left:0,borderRadius:"inherit"}),Xfg=qt(Gfg,{name:"MuiTouchRipple",slot:"Ripple"})(xue||(xue=JY` opacity: 0; position: absolute; @@ -2092,4 +2092,4 @@ ${s}`:s,l=Tet(o).parse(A,c=>SI(this,x$,t2e).call(this,c,r,I,i));if(C&&((g=l[0])! animation-iteration-count: infinite; animation-delay: 200ms; } -`),Yr.rippleVisible,Gfg,z_,({theme:e})=>e.transitions.easing.easeInOut,Yr.ripplePulsate,({theme:e})=>e.transitions.duration.shorter,Yr.child,Yr.childLeaving,vfg,z_,({theme:e})=>e.transitions.easing.easeInOut,Yr.childPulsate,Bfg,({theme:e})=>e.transitions.easing.easeInOut),Vfg=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiTouchRipple"}),{center:n=!1,classes:C={},className:r}=i,o=Qt(i,yfg),[a,s]=U.useState([]),A=U.useRef(0),l=U.useRef(null);U.useEffect(()=>{l.current&&(l.current(),l.current=null)},[a]);const c=U.useRef(!1),u=U.useRef(0),d=U.useRef(null),h=U.useRef(null);U.useEffect(()=>()=>{u.current&&clearTimeout(u.current)},[]);const m=U.useCallback(y=>{const{pulsate:Z,rippleX:B,rippleY:G,rippleSize:v,cb:w}=y;s(V=>[...V,Oe.jsx(wfg,{classes:{ripple:ug(C.ripple,Yr.ripple),rippleVisible:ug(C.rippleVisible,Yr.rippleVisible),ripplePulsate:ug(C.ripplePulsate,Yr.ripplePulsate),child:ug(C.child,Yr.child),childLeaving:ug(C.childLeaving,Yr.childLeaving),childPulsate:ug(C.childPulsate,Yr.childPulsate)},timeout:z_,pulsate:Z,rippleX:B,rippleY:G,rippleSize:v},A.current)]),A.current+=1,l.current=w},[C]),f=U.useCallback((y={},Z={},B=()=>{})=>{const{pulsate:G=!1,center:v=n||Z.pulsate,fakeElement:w=!1}=Z;if((y==null?void 0:y.type)==="mousedown"&&c.current){c.current=!1;return}(y==null?void 0:y.type)==="touchstart"&&(c.current=!0);const V=w?null:h.current,S=V?V.getBoundingClientRect():{width:0,height:0,left:0,top:0};let X,W,R;if(v||y===void 0||y.clientX===0&&y.clientY===0||!y.clientX&&!y.touches)X=Math.round(S.width/2),W=Math.round(S.height/2);else{const{clientX:H,clientY:Y}=y.touches&&y.touches.length>0?y.touches[0]:y;X=Math.round(H-S.left),W=Math.round(Y-S.top)}if(v)R=Math.sqrt((2*S.width**2+S.height**2)/3),R%2===0&&(R+=1);else{const H=Math.max(Math.abs((V?V.clientWidth:0)-X),X)*2+2,Y=Math.max(Math.abs((V?V.clientHeight:0)-W),W)*2+2;R=Math.sqrt(H**2+Y**2)}y!=null&&y.touches?d.current===null&&(d.current=()=>{m({pulsate:G,rippleX:X,rippleY:W,rippleSize:R,cb:B})},u.current=setTimeout(()=>{d.current&&(d.current(),d.current=null)},Zfg)):m({pulsate:G,rippleX:X,rippleY:W,rippleSize:R,cb:B})},[n,m]),b=U.useCallback(()=>{f({},{pulsate:!0})},[f]),p=U.useCallback((y,Z)=>{if(clearTimeout(u.current),(y==null?void 0:y.type)==="touchend"&&d.current){d.current(),d.current=null,u.current=setTimeout(()=>{p(y,Z)});return}d.current=null,s(B=>B.length>0?B.slice(1):B),l.current=Z},[]);return U.useImperativeHandle(I,()=>({pulsate:b,start:f,stop:p}),[b,f,p]),Oe.jsx(Sfg,Ke({className:ug(Yr.root,C.root,r),ref:h},o,{children:Oe.jsx(sug,{component:null,exit:!0,children:a})}))}),Rfg=Vfg;function Wfg(e){return li("MuiButtonBase",e)}const Xfg=HI("MuiButtonBase",["root","disabled","focusVisible"]),Hfg=Xfg,Tfg=["action","centerRipple","children","className","component","disabled","disableRipple","disableTouchRipple","focusRipple","focusVisibleClassName","LinkComponent","onBlur","onClick","onContextMenu","onDragLeave","onFocus","onFocusVisible","onKeyDown","onKeyUp","onMouseDown","onMouseLeave","onMouseUp","onTouchEnd","onTouchMove","onTouchStart","tabIndex","TouchRippleProps","touchRippleRef","type"],Nfg=e=>{const{disabled:g,focusVisible:I,focusVisibleClassName:i,classes:n}=e,r=vi({root:["root",g&&"disabled",I&&"focusVisible"]},Wfg,n);return I&&i&&(r.root+=` ${i}`),r},kfg=qt("button",{name:"MuiButtonBase",slot:"Root",overridesResolver:(e,g)=>g.root})({display:"inline-flex",alignItems:"center",justifyContent:"center",position:"relative",boxSizing:"border-box",WebkitTapHighlightColor:"transparent",backgroundColor:"transparent",outline:0,border:0,margin:0,borderRadius:0,padding:0,cursor:"pointer",userSelect:"none",verticalAlign:"middle",MozAppearance:"none",WebkitAppearance:"none",textDecoration:"none",color:"inherit","&::-moz-focus-inner":{borderStyle:"none"},[`&.${Hfg.disabled}`]:{pointerEvents:"none",cursor:"default"},"@media print":{colorAdjust:"exact"}}),Yfg=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiButtonBase"}),{action:n,centerRipple:C=!1,children:r,className:o,component:a="button",disabled:s=!1,disableRipple:A=!1,disableTouchRipple:l=!1,focusRipple:c=!1,LinkComponent:u="a",onBlur:d,onClick:h,onContextMenu:m,onDragLeave:f,onFocus:b,onFocusVisible:p,onKeyDown:y,onKeyUp:Z,onMouseDown:B,onMouseLeave:G,onMouseUp:v,onTouchEnd:w,onTouchMove:V,onTouchStart:S,tabIndex:X=0,TouchRippleProps:W,touchRippleRef:R,type:H}=i,Y=Qt(i,Tfg),K=U.useRef(null),F=U.useRef(null),J=pn(F,R),{isFocusVisibleRef:P,onFocus:ge,onBlur:q,ref:$}=oNe(),[j,te]=U.useState(!1);s&&j&&te(!1),U.useImperativeHandle(n,()=>({focusVisible:()=>{te(!0),K.current.focus()}}),[]);const[Q,ie]=U.useState(!1);U.useEffect(()=>{ie(!0)},[]);const he=Q&&!A&&!s;U.useEffect(()=>{j&&c&&!A&&Q&&F.current.pulsate()},[A,c,j,Q]);function ne(k,Ie,me=l){return Zd(Re=>(Ie&&Ie(Re),!me&&F.current&&F.current[k](Re),!0))}const be=ne("start",B),pe=ne("stop",m),ve=ne("stop",f),We=ne("stop",v),Be=ne("stop",k=>{j&&k.preventDefault(),G&&G(k)}),Je=ne("start",S),Pe=ne("stop",w),De=ne("stop",V),Qe=ne("stop",k=>{q(k),P.current===!1&&te(!1),d&&d(k)},!1),_e=Zd(k=>{K.current||(K.current=k.currentTarget),ge(k),P.current===!0&&(te(!0),p&&p(k)),b&&b(k)}),gt=()=>{const k=K.current;return a&&a!=="button"&&!(k.tagName==="A"&&k.href)},lt=U.useRef(!1),tt=Zd(k=>{c&&!lt.current&&j&&F.current&&k.key===" "&&(lt.current=!0,F.current.stop(k,()=>{F.current.start(k)})),k.target===k.currentTarget&>()&&k.key===" "&&k.preventDefault(),y&&y(k),k.target===k.currentTarget&>()&&k.key==="Enter"&&!s&&(k.preventDefault(),h&&h(k))}),Xe=Zd(k=>{c&&k.key===" "&&F.current&&j&&!k.defaultPrevented&&(lt.current=!1,F.current.stop(k,()=>{F.current.pulsate(k)})),Z&&Z(k),h&&k.target===k.currentTarget&>()&&k.key===" "&&!k.defaultPrevented&&h(k)});let ae=a;ae==="button"&&(Y.href||Y.to)&&(ae=u);const ye={};ae==="button"?(ye.type=H===void 0?"button":H,ye.disabled=s):(!Y.href&&!Y.to&&(ye.role="button"),s&&(ye["aria-disabled"]=s));const He=pn(I,$,K),x=Ke({},i,{centerRipple:C,component:a,disabled:s,disableRipple:A,disableTouchRipple:l,focusRipple:c,tabIndex:X,focusVisible:j}),T=Nfg(x);return Oe.jsxs(kfg,Ke({as:ae,className:ug(T.root,o),ownerState:x,onBlur:Qe,onClick:h,onContextMenu:pe,onFocus:_e,onKeyDown:tt,onKeyUp:Xe,onMouseDown:be,onMouseLeave:Be,onMouseUp:We,onDragLeave:ve,onTouchEnd:Pe,onTouchMove:De,onTouchStart:Je,ref:He,tabIndex:s?-1:X,type:H},ye,Y,{children:[r,he?Oe.jsx(Rfg,Ke({ref:J,center:C},W)):null]}))}),Kfg=Yfg,xfg=HI("MuiDivider",["root","absolute","fullWidth","inset","middle","flexItem","light","vertical","withChildren","withChildrenVertical","textAlignRight","textAlignLeft","wrapper","wrapperVertical"]),Due=xfg,Dfg=HI("MuiListItemIcon",["root","alignItemsFlexStart"]),Fue=Dfg,Ffg=HI("MuiListItemText",["root","multiline","dense","inset","primary","secondary"]),Eue=Ffg;function Efg(e){return li("MuiMenuItem",e)}const Mfg=HI("MuiMenuItem",["root","focusVisible","dense","disabled","divider","gutters","selected"]),WZ=Mfg,zfg=["autoFocus","component","dense","divider","disableGutters","focusVisibleClassName","role","tabIndex","className"],Pfg=(e,g)=>{const{ownerState:I}=e;return[g.root,I.dense&&g.dense,I.divider&&g.divider,!I.disableGutters&&g.gutters]},Jfg=e=>{const{disabled:g,dense:I,divider:i,disableGutters:n,selected:C,classes:r}=e,a=vi({root:["root",I&&"dense",g&&"disabled",!n&&"gutters",i&&"divider",C&&"selected"]},Efg,r);return Ke({},r,a)},Ofg=qt(Kfg,{shouldForwardProp:e=>va(e)||e==="classes",name:"MuiMenuItem",slot:"Root",overridesResolver:Pfg})(({theme:e,ownerState:g})=>Ke({},e.typography.body1,{display:"flex",justifyContent:"flex-start",alignItems:"center",position:"relative",textDecoration:"none",minHeight:48,paddingTop:6,paddingBottom:6,boxSizing:"border-box",whiteSpace:"nowrap"},!g.disableGutters&&{paddingLeft:16,paddingRight:16},g.divider&&{borderBottom:`1px solid ${(e.vars||e).palette.divider}`,backgroundClip:"padding-box"},{"&:hover":{textDecoration:"none",backgroundColor:(e.vars||e).palette.action.hover,"@media (hover: none)":{backgroundColor:"transparent"}},[`&.${WZ.selected}`]:{backgroundColor:e.vars?`rgba(${e.vars.palette.primary.mainChannel} / ${e.vars.palette.action.selectedOpacity})`:rA(e.palette.primary.main,e.palette.action.selectedOpacity),[`&.${WZ.focusVisible}`]:{backgroundColor:e.vars?`rgba(${e.vars.palette.primary.mainChannel} / calc(${e.vars.palette.action.selectedOpacity} + ${e.vars.palette.action.focusOpacity}))`:rA(e.palette.primary.main,e.palette.action.selectedOpacity+e.palette.action.focusOpacity)}},[`&.${WZ.selected}:hover`]:{backgroundColor:e.vars?`rgba(${e.vars.palette.primary.mainChannel} / calc(${e.vars.palette.action.selectedOpacity} + ${e.vars.palette.action.hoverOpacity}))`:rA(e.palette.primary.main,e.palette.action.selectedOpacity+e.palette.action.hoverOpacity),"@media (hover: none)":{backgroundColor:e.vars?`rgba(${e.vars.palette.primary.mainChannel} / ${e.vars.palette.action.selectedOpacity})`:rA(e.palette.primary.main,e.palette.action.selectedOpacity)}},[`&.${WZ.focusVisible}`]:{backgroundColor:(e.vars||e).palette.action.focus},[`&.${WZ.disabled}`]:{opacity:(e.vars||e).palette.action.disabledOpacity},[`& + .${Due.root}`]:{marginTop:e.spacing(1),marginBottom:e.spacing(1)},[`& + .${Due.inset}`]:{marginLeft:52},[`& .${Eue.root}`]:{marginTop:0,marginBottom:0},[`& .${Eue.inset}`]:{paddingLeft:36},[`& .${Fue.root}`]:{minWidth:36}},!g.dense&&{[e.breakpoints.up("sm")]:{minHeight:"auto"}},g.dense&&Ke({minHeight:32,paddingTop:4,paddingBottom:4},e.typography.body2,{[`& .${Fue.root} svg`]:{fontSize:"1.25rem"}}))),_fg=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiMenuItem"}),{autoFocus:n=!1,component:C="li",dense:r=!1,divider:o=!1,disableGutters:a=!1,focusVisibleClassName:s,role:A="menuitem",tabIndex:l,className:c}=i,u=Qt(i,zfg),d=U.useContext(E_),h=U.useMemo(()=>({dense:r||d.dense||!1,disableGutters:a}),[d.dense,r,a]),m=U.useRef(null);Ls(()=>{n&&m.current&&m.current.focus()},[n]);const f=Ke({},i,{dense:h.dense,divider:o,disableGutters:a}),b=Jfg(i),p=pn(m,I);let y;return i.disabled||(y=l!==void 0?l:-1),Oe.jsx(E_.Provider,{value:h,children:Oe.jsx(Ofg,Ke({ref:p,role:A,tabIndex:y,component:C,focusVisibleClassName:ug(b.focusVisible,s),className:ug(b.root,c)},u,{ownerState:f,classes:b}))})}),Lfg=_fg;function Ufg(){const e={"Bar chart":ldg,"Multiple Visual Encodings":cdg,"Multiple Visual Encoding Track 1 and 2":udg,"Multiple Visual Encoding Track 4":ddg,"Multiple Visual Encoding Track 4 Test":hdg,"Bar chart with lines":mdg,"Bar chart with points":fdg,"GIVE - CAO et al.":pdg},[g,I]=U.useState(Object.keys(e)[0]),i=()=>Oe.jsxs(wdg,{variant:"filled",sx:{m:1,minWidth:150},children:[Oe.jsx(Edg,{id:"example-options",children:"Select example"}),Oe.jsx(ffg,{"aria-labelledby":"example-options-radio-button",defaultValue:Object.keys(e)[0],value:g,name:"example-options-radio-button",onChange:n=>I(n.target.value),children:Object.keys(e).sort().map(n=>Oe.jsx(Lfg,{value:n,children:n}))})]});return Oe.jsx(Oe.Fragment,{children:Oe.jsxs(vd,{container:!0,spacing:1,children:[Oe.jsx(vd,{item:!0,"aria-label":"example checkbox",xs:12,children:Oe.jsx(i,{})}),Oe.jsx(vd,{item:!0,"aria-label":"alt-gosling component",xs:12,children:Oe.jsx(sdg,{spec:e[g]})})]})})}IE.createRoot(document.getElementById("root")).render(Oe.jsx(Ufg,{}));export{s5e as _,yI as c,jc as g}; +`),Yr.rippleVisible,wfg,z_,({theme:e})=>e.transitions.easing.easeInOut,Yr.ripplePulsate,({theme:e})=>e.transitions.duration.shorter,Yr.child,Yr.childLeaving,Vfg,z_,({theme:e})=>e.transitions.easing.easeInOut,Yr.childPulsate,Rfg,({theme:e})=>e.transitions.easing.easeInOut),Hfg=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiTouchRipple"}),{center:n=!1,classes:C={},className:r}=i,o=Qt(i,Bfg),[a,s]=U.useState([]),A=U.useRef(0),l=U.useRef(null);U.useEffect(()=>{l.current&&(l.current(),l.current=null)},[a]);const c=U.useRef(!1),u=U.useRef(0),d=U.useRef(null),h=U.useRef(null);U.useEffect(()=>()=>{u.current&&clearTimeout(u.current)},[]);const m=U.useCallback(y=>{const{pulsate:Z,rippleX:B,rippleY:G,rippleSize:v,cb:w}=y;s(V=>[...V,Oe.jsx(Xfg,{classes:{ripple:ug(C.ripple,Yr.ripple),rippleVisible:ug(C.rippleVisible,Yr.rippleVisible),ripplePulsate:ug(C.ripplePulsate,Yr.ripplePulsate),child:ug(C.child,Yr.child),childLeaving:ug(C.childLeaving,Yr.childLeaving),childPulsate:ug(C.childPulsate,Yr.childPulsate)},timeout:z_,pulsate:Z,rippleX:B,rippleY:G,rippleSize:v},A.current)]),A.current+=1,l.current=w},[C]),f=U.useCallback((y={},Z={},B=()=>{})=>{const{pulsate:G=!1,center:v=n||Z.pulsate,fakeElement:w=!1}=Z;if((y==null?void 0:y.type)==="mousedown"&&c.current){c.current=!1;return}(y==null?void 0:y.type)==="touchstart"&&(c.current=!0);const V=w?null:h.current,S=V?V.getBoundingClientRect():{width:0,height:0,left:0,top:0};let X,W,R;if(v||y===void 0||y.clientX===0&&y.clientY===0||!y.clientX&&!y.touches)X=Math.round(S.width/2),W=Math.round(S.height/2);else{const{clientX:H,clientY:Y}=y.touches&&y.touches.length>0?y.touches[0]:y;X=Math.round(H-S.left),W=Math.round(Y-S.top)}if(v)R=Math.sqrt((2*S.width**2+S.height**2)/3),R%2===0&&(R+=1);else{const H=Math.max(Math.abs((V?V.clientWidth:0)-X),X)*2+2,Y=Math.max(Math.abs((V?V.clientHeight:0)-W),W)*2+2;R=Math.sqrt(H**2+Y**2)}y!=null&&y.touches?d.current===null&&(d.current=()=>{m({pulsate:G,rippleX:X,rippleY:W,rippleSize:R,cb:B})},u.current=setTimeout(()=>{d.current&&(d.current(),d.current=null)},Sfg)):m({pulsate:G,rippleX:X,rippleY:W,rippleSize:R,cb:B})},[n,m]),b=U.useCallback(()=>{f({},{pulsate:!0})},[f]),p=U.useCallback((y,Z)=>{if(clearTimeout(u.current),(y==null?void 0:y.type)==="touchend"&&d.current){d.current(),d.current=null,u.current=setTimeout(()=>{p(y,Z)});return}d.current=null,s(B=>B.length>0?B.slice(1):B),l.current=Z},[]);return U.useImperativeHandle(I,()=>({pulsate:b,start:f,stop:p}),[b,f,p]),Oe.jsx(Wfg,Ke({className:ug(Yr.root,C.root,r),ref:h},o,{children:Oe.jsx(sug,{component:null,exit:!0,children:a})}))}),Tfg=Hfg;function Nfg(e){return li("MuiButtonBase",e)}const kfg=HI("MuiButtonBase",["root","disabled","focusVisible"]),Yfg=kfg,Kfg=["action","centerRipple","children","className","component","disabled","disableRipple","disableTouchRipple","focusRipple","focusVisibleClassName","LinkComponent","onBlur","onClick","onContextMenu","onDragLeave","onFocus","onFocusVisible","onKeyDown","onKeyUp","onMouseDown","onMouseLeave","onMouseUp","onTouchEnd","onTouchMove","onTouchStart","tabIndex","TouchRippleProps","touchRippleRef","type"],xfg=e=>{const{disabled:g,focusVisible:I,focusVisibleClassName:i,classes:n}=e,r=vi({root:["root",g&&"disabled",I&&"focusVisible"]},Nfg,n);return I&&i&&(r.root+=` ${i}`),r},Dfg=qt("button",{name:"MuiButtonBase",slot:"Root",overridesResolver:(e,g)=>g.root})({display:"inline-flex",alignItems:"center",justifyContent:"center",position:"relative",boxSizing:"border-box",WebkitTapHighlightColor:"transparent",backgroundColor:"transparent",outline:0,border:0,margin:0,borderRadius:0,padding:0,cursor:"pointer",userSelect:"none",verticalAlign:"middle",MozAppearance:"none",WebkitAppearance:"none",textDecoration:"none",color:"inherit","&::-moz-focus-inner":{borderStyle:"none"},[`&.${Yfg.disabled}`]:{pointerEvents:"none",cursor:"default"},"@media print":{colorAdjust:"exact"}}),Ffg=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiButtonBase"}),{action:n,centerRipple:C=!1,children:r,className:o,component:a="button",disabled:s=!1,disableRipple:A=!1,disableTouchRipple:l=!1,focusRipple:c=!1,LinkComponent:u="a",onBlur:d,onClick:h,onContextMenu:m,onDragLeave:f,onFocus:b,onFocusVisible:p,onKeyDown:y,onKeyUp:Z,onMouseDown:B,onMouseLeave:G,onMouseUp:v,onTouchEnd:w,onTouchMove:V,onTouchStart:S,tabIndex:X=0,TouchRippleProps:W,touchRippleRef:R,type:H}=i,Y=Qt(i,Kfg),K=U.useRef(null),F=U.useRef(null),J=pn(F,R),{isFocusVisibleRef:P,onFocus:ge,onBlur:q,ref:$}=oNe(),[j,te]=U.useState(!1);s&&j&&te(!1),U.useImperativeHandle(n,()=>({focusVisible:()=>{te(!0),K.current.focus()}}),[]);const[Q,ie]=U.useState(!1);U.useEffect(()=>{ie(!0)},[]);const he=Q&&!A&&!s;U.useEffect(()=>{j&&c&&!A&&Q&&F.current.pulsate()},[A,c,j,Q]);function ne(k,Ie,me=l){return Zd(Re=>(Ie&&Ie(Re),!me&&F.current&&F.current[k](Re),!0))}const be=ne("start",B),pe=ne("stop",m),ve=ne("stop",f),We=ne("stop",v),Be=ne("stop",k=>{j&&k.preventDefault(),G&&G(k)}),Je=ne("start",S),Pe=ne("stop",w),De=ne("stop",V),Qe=ne("stop",k=>{q(k),P.current===!1&&te(!1),d&&d(k)},!1),_e=Zd(k=>{K.current||(K.current=k.currentTarget),ge(k),P.current===!0&&(te(!0),p&&p(k)),b&&b(k)}),gt=()=>{const k=K.current;return a&&a!=="button"&&!(k.tagName==="A"&&k.href)},lt=U.useRef(!1),tt=Zd(k=>{c&&!lt.current&&j&&F.current&&k.key===" "&&(lt.current=!0,F.current.stop(k,()=>{F.current.start(k)})),k.target===k.currentTarget&>()&&k.key===" "&&k.preventDefault(),y&&y(k),k.target===k.currentTarget&>()&&k.key==="Enter"&&!s&&(k.preventDefault(),h&&h(k))}),Xe=Zd(k=>{c&&k.key===" "&&F.current&&j&&!k.defaultPrevented&&(lt.current=!1,F.current.stop(k,()=>{F.current.pulsate(k)})),Z&&Z(k),h&&k.target===k.currentTarget&>()&&k.key===" "&&!k.defaultPrevented&&h(k)});let ae=a;ae==="button"&&(Y.href||Y.to)&&(ae=u);const ye={};ae==="button"?(ye.type=H===void 0?"button":H,ye.disabled=s):(!Y.href&&!Y.to&&(ye.role="button"),s&&(ye["aria-disabled"]=s));const He=pn(I,$,K),x=Ke({},i,{centerRipple:C,component:a,disabled:s,disableRipple:A,disableTouchRipple:l,focusRipple:c,tabIndex:X,focusVisible:j}),T=xfg(x);return Oe.jsxs(Dfg,Ke({as:ae,className:ug(T.root,o),ownerState:x,onBlur:Qe,onClick:h,onContextMenu:pe,onFocus:_e,onKeyDown:tt,onKeyUp:Xe,onMouseDown:be,onMouseLeave:Be,onMouseUp:We,onDragLeave:ve,onTouchEnd:Pe,onTouchMove:De,onTouchStart:Je,ref:He,tabIndex:s?-1:X,type:H},ye,Y,{children:[r,he?Oe.jsx(Tfg,Ke({ref:J,center:C},W)):null]}))}),Efg=Ffg,Mfg=HI("MuiDivider",["root","absolute","fullWidth","inset","middle","flexItem","light","vertical","withChildren","withChildrenVertical","textAlignRight","textAlignLeft","wrapper","wrapperVertical"]),Due=Mfg,zfg=HI("MuiListItemIcon",["root","alignItemsFlexStart"]),Fue=zfg,Pfg=HI("MuiListItemText",["root","multiline","dense","inset","primary","secondary"]),Eue=Pfg;function Jfg(e){return li("MuiMenuItem",e)}const Ofg=HI("MuiMenuItem",["root","focusVisible","dense","disabled","divider","gutters","selected"]),WZ=Ofg,_fg=["autoFocus","component","dense","divider","disableGutters","focusVisibleClassName","role","tabIndex","className"],Lfg=(e,g)=>{const{ownerState:I}=e;return[g.root,I.dense&&g.dense,I.divider&&g.divider,!I.disableGutters&&g.gutters]},Ufg=e=>{const{disabled:g,dense:I,divider:i,disableGutters:n,selected:C,classes:r}=e,a=vi({root:["root",I&&"dense",g&&"disabled",!n&&"gutters",i&&"divider",C&&"selected"]},Jfg,r);return Ke({},r,a)},Qfg=qt(Efg,{shouldForwardProp:e=>va(e)||e==="classes",name:"MuiMenuItem",slot:"Root",overridesResolver:Lfg})(({theme:e,ownerState:g})=>Ke({},e.typography.body1,{display:"flex",justifyContent:"flex-start",alignItems:"center",position:"relative",textDecoration:"none",minHeight:48,paddingTop:6,paddingBottom:6,boxSizing:"border-box",whiteSpace:"nowrap"},!g.disableGutters&&{paddingLeft:16,paddingRight:16},g.divider&&{borderBottom:`1px solid ${(e.vars||e).palette.divider}`,backgroundClip:"padding-box"},{"&:hover":{textDecoration:"none",backgroundColor:(e.vars||e).palette.action.hover,"@media (hover: none)":{backgroundColor:"transparent"}},[`&.${WZ.selected}`]:{backgroundColor:e.vars?`rgba(${e.vars.palette.primary.mainChannel} / ${e.vars.palette.action.selectedOpacity})`:rA(e.palette.primary.main,e.palette.action.selectedOpacity),[`&.${WZ.focusVisible}`]:{backgroundColor:e.vars?`rgba(${e.vars.palette.primary.mainChannel} / calc(${e.vars.palette.action.selectedOpacity} + ${e.vars.palette.action.focusOpacity}))`:rA(e.palette.primary.main,e.palette.action.selectedOpacity+e.palette.action.focusOpacity)}},[`&.${WZ.selected}:hover`]:{backgroundColor:e.vars?`rgba(${e.vars.palette.primary.mainChannel} / calc(${e.vars.palette.action.selectedOpacity} + ${e.vars.palette.action.hoverOpacity}))`:rA(e.palette.primary.main,e.palette.action.selectedOpacity+e.palette.action.hoverOpacity),"@media (hover: none)":{backgroundColor:e.vars?`rgba(${e.vars.palette.primary.mainChannel} / ${e.vars.palette.action.selectedOpacity})`:rA(e.palette.primary.main,e.palette.action.selectedOpacity)}},[`&.${WZ.focusVisible}`]:{backgroundColor:(e.vars||e).palette.action.focus},[`&.${WZ.disabled}`]:{opacity:(e.vars||e).palette.action.disabledOpacity},[`& + .${Due.root}`]:{marginTop:e.spacing(1),marginBottom:e.spacing(1)},[`& + .${Due.inset}`]:{marginLeft:52},[`& .${Eue.root}`]:{marginTop:0,marginBottom:0},[`& .${Eue.inset}`]:{paddingLeft:36},[`& .${Fue.root}`]:{minWidth:36}},!g.dense&&{[e.breakpoints.up("sm")]:{minHeight:"auto"}},g.dense&&Ke({minHeight:32,paddingTop:4,paddingBottom:4},e.typography.body2,{[`& .${Fue.root} svg`]:{fontSize:"1.25rem"}}))),jfg=U.forwardRef(function(g,I){const i=gi({props:g,name:"MuiMenuItem"}),{autoFocus:n=!1,component:C="li",dense:r=!1,divider:o=!1,disableGutters:a=!1,focusVisibleClassName:s,role:A="menuitem",tabIndex:l,className:c}=i,u=Qt(i,_fg),d=U.useContext(E_),h=U.useMemo(()=>({dense:r||d.dense||!1,disableGutters:a}),[d.dense,r,a]),m=U.useRef(null);Ls(()=>{n&&m.current&&m.current.focus()},[n]);const f=Ke({},i,{dense:h.dense,divider:o,disableGutters:a}),b=Ufg(i),p=pn(m,I);let y;return i.disabled||(y=l!==void 0?l:-1),Oe.jsx(E_.Provider,{value:h,children:Oe.jsx(Qfg,Ke({ref:p,role:A,tabIndex:y,component:C,focusVisibleClassName:ug(b.focusVisible,s),className:ug(b.root,c)},u,{ownerState:f,classes:b}))})}),$fg=jfg;function qfg(){const e={"Bar chart":ldg,"Line chart":cdg,"Point chart":udg,Ideogram:ddg,"Multiple Visual Encodings":hdg,"Multiple Visual Encoding Track 1 and 2":mdg,"Multiple Visual Encoding Track 4":fdg,"Multiple Visual Encoding Track 4 Test":pdg,"Bar chart with lines":bdg,"Bar chart with points":ydg,"GIVE - CAO et al.":Zdg,"Gene annotations":Gdg},[g,I]=U.useState(Object.keys(e)[0]),i=()=>Oe.jsxs(Xdg,{variant:"filled",sx:{m:1,minWidth:150},children:[Oe.jsx(Jdg,{id:"example-options",children:"Select example"}),Oe.jsx(Zfg,{"aria-labelledby":"example-options-radio-button",defaultValue:Object.keys(e)[0],value:g,name:"example-options-radio-button",onChange:n=>I(n.target.value),children:Object.keys(e).sort().map(n=>Oe.jsx($fg,{value:n,children:n}))})]});return Oe.jsx(Oe.Fragment,{children:Oe.jsxs(vd,{container:!0,spacing:1,children:[Oe.jsx(vd,{item:!0,"aria-label":"example checkbox",xs:12,children:Oe.jsx(i,{})}),Oe.jsx(vd,{item:!0,"aria-label":"alt-gosling component",xs:12,children:Oe.jsx(sdg,{spec:e[g]})})]})})}IE.createRoot(document.getElementById("root")).render(Oe.jsx(qfg,{}));export{s5e as _,yI as c,jc as g}; diff --git a/index.html b/index.html index 5445cb2..f4a3f9e 100644 --- a/index.html +++ b/index.html @@ -6,7 +6,7 @@ AltGosling - +