Problem:
Score : 400 points

Problem Statement

Mountaineers Mr. Takahashi and Mr. Aoki recently trekked across a certain famous mountain range.
The mountain range consists of N mountains, extending from west to east in a straight line as Mt. 1, Mt. 2, ..., Mt. N.
Mr. Takahashi traversed the range from the west and Mr. Aoki from the east.

The height of Mt. i is h_i, but they have forgotten the value of each h_i.
Instead, for each i (1 ≤ i ≤ N), they recorded the maximum height of the mountains climbed up to the time they reached the peak of Mt. i (including Mt. i).
Mr. Takahashi's record is T_i and Mr. Aoki's record is A_i.

We know that the height of each mountain h_i is a positive integer.
Compute the number of the possible sequences of the mountains' heights, modulo 10^9 + 7.

Note that the records may be incorrect and thus there may be no possible sequence of the mountains' heights.
In such a case, output 0.

Constraints

1 ≤ N ≤ 10^5

1 ≤ T_i ≤ 10^9

1 ≤ A_i ≤ 10^9

T_i ≤ T_{i+1} (1 ≤ i ≤ N - 1)

A_i ≥ A_{i+1} (1 ≤ i ≤ N - 1)

Input

The input is given from Standard Input in the following format:

N
T_1 T_2 ... T_N
A_1 A_2 ... A_N

Output

Print the number of possible sequences of the mountains' heights, modulo 10^9 + 7.

Sample Input 1

5
1 3 3 3 3
3 3 2 2 2

Sample Output 1

4

The possible sequences of the mountains' heights are:

1, 3, 2, 2, 2

1, 3, 2, 1, 2

1, 3, 1, 2, 2

1, 3, 1, 1, 2

for a total of four sequences.

Sample Input 2

5
1 1 1 2 2
3 2 1 1 1

Sample Output 2

0

The records are contradictory, since Mr. Takahashi recorded 2 as the highest peak after climbing all the mountains but Mr. Aoki recorded 3.

Sample Input 3

10
1 3776 3776 8848 8848 8848 8848 8848 8848 8848
8848 8848 8848 8848 8848 8848 8848 8848 3776 5

Sample Output 3

884111967

Don't forget to compute the number modulo 10^9 + 7.

Sample Input 4

1
17
17

Sample Output 4

1

Some mountain ranges consist of only one mountain.

Solution in JavaScript (node.js v5.12) (judge verdict: Accepted)

module.exports=function(e){var r={};function n(t){if(r[t])return r[t].exports;var i=r[t]={i:t,l:!1,exports:{}};return e[t].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=r,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,r){if(1&r&&(e=n(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(n.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var i in e)n.d(t,i,function(r){return e[r]}.bind(null,i));return t},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},n.p="",n(n.s=0)}([function(e,r,n){"use strict";var t=n(1),i=new(n(2))(t.readFileSync("/dev/stdin","utf8").trim().split(/\s+/g));n(4)(i)},function(e,r){e.exports=require("fs")},function(e,r,n){"use strict";var t=n(3);e.exports=class{constructor(e){this.inp=new t(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(e,r,n){"use strict";e.exports=class{constructor(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=e.length,this.items=e,this.ind=0}enq(e){this.size+=1,this.items.push(e)}deq(){var e=this.items[this.ind];return this.size-=1,this.ind+=1,e}clear(){this.items=[],this.size=0,this.ind=0}}},function(e,r,n){"use strict";var t=n(5);e.exports=function(e){for(var r=e.in(),n=new Array(r),i=new Array(r),o=0;o<r;o++)if(n[o]=e.in(),o>0&&n[o]<n[o-1])return void console.log("0");for(var s=0;s<r;s++)if(i[s]=e.in(),s>0&&i[s]>i[s-1])return void console.log("0");for(var u=-1,f=-1,l=new Array(r).fill(-1),c=0;c<r;c++){var a=c,h=r-1-c;if(n[a]!=u){if(-1!=l[a]&&l[a]!=n[a])return void console.log("0");if(n[a]>i[a])return void console.log("0");l[a]=n[a],u=n[a]}if(i[h]!=f){if(-1!=l[h]&&l[h]!=i[h])return void console.log("0");if(i[h]>n[h])return void console.log("0");l[h]=i[h],f=i[h]}}for(var p=new t(1),g=0;g<r;g++)if(-1==l[g]){var d=Math.min(n[g],i[g]);p=p.times(d).mod(1000000007)}console.log(p.mod(1000000007).toString())}},function(e,r,n){var t;!function(i){"use strict";var o,s=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,u=Math.ceil,f=Math.floor,l="[BigNumber Error] ",c=l+"Number primitive has more than 15 significant digits: ",a=1e14,h=14,p=9007199254740991,g=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],d=1e7,w=1e9;function m(e){var r=0|e;return e>0||e===r?r:r-1}function v(e){for(var r,n,t=1,i=e.length,o=e[0]+"";t<i;){for(r=e[t++]+"",n=h-r.length;n--;r="0"+r);o+=r}for(i=o.length;48===o.charCodeAt(--i););return o.slice(0,i+1||1)}function y(e,r){var n,t,i=e.c,o=r.c,s=e.s,u=r.s,f=e.e,l=r.e;if(!s||!u)return null;if(n=i&&!i[0],t=o&&!o[0],n||t)return n?t?0:-u:s;if(s!=u)return s;if(n=s<0,t=f==l,!i||!o)return t?0:!i^n?1:-1;if(!t)return f>l^n?1:-1;for(u=(f=i.length)<(l=o.length)?f:l,s=0;s<u;s++)if(i[s]!=o[s])return i[s]>o[s]^n?1:-1;return f==l?0:f>l^n?1:-1}function b(e,r,n,t){if(e<r||e>n||e!==f(e))throw Error(l+(t||"Argument")+("number"==typeof e?e<r||e>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function O(e){var r=e.c.length-1;return m(e.e/h)==r&&e.c[r]%2!=0}function N(e,r){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(r<0?"e":"e+")+r}function E(e,r,n){var t,i;if(r<0){for(i=n+".";++r;i+=n);e=i+e}else if(++r>(t=e.length)){for(i=n,r-=t;--r;i+=n);e+=i}else r<t&&(e=e.slice(0,r)+"."+e.slice(r));return e}(o=function e(r){var n,t,i,o,A,S,x,_,P,R=k.prototype={constructor:k,toString:null,valueOf:null},D=new k(1),B=20,L=4,M=-7,I=21,T=-1e7,U=1e7,C=!1,j=1,q=0,G={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},F="0123456789abcdefghijklmnopqrstuvwxyz";function k(e,r){var n,o,u,l,a,g,d,w,m=this;if(!(m instanceof k))return new k(e,r);if(null==r){if(e&&!0===e._isBigNumber)return m.s=e.s,void(!e.c||e.e>U?m.c=m.e=null:e.e<T?m.c=[m.e=0]:(m.e=e.e,m.c=e.c.slice()));if((g="number"==typeof e)&&0*e==0){if(m.s=1/e<0?(e=-e,-1):1,e===~~e){for(l=0,a=e;a>=10;a/=10,l++);return void(l>U?m.c=m.e=null:(m.e=l,m.c=[e]))}w=String(e)}else{if(!s.test(w=String(e)))return i(m,w,g);m.s=45==w.charCodeAt(0)?(w=w.slice(1),-1):1}(l=w.indexOf("."))>-1&&(w=w.replace(".","")),(a=w.search(/e/i))>0?(l<0&&(l=a),l+=+w.slice(a+1),w=w.substring(0,a)):l<0&&(l=w.length)}else{if(b(r,2,F.length,"Base"),10==r)return V(m=new k(e),B+m.e+1,L);if(w=String(e),g="number"==typeof e){if(0*e!=0)return i(m,w,g,r);if(m.s=1/e<0?(w=w.slice(1),-1):1,k.DEBUG&&w.replace(/^0\.0*|\./,"").length>15)throw Error(c+e)}else m.s=45===w.charCodeAt(0)?(w=w.slice(1),-1):1;for(n=F.slice(0,r),l=a=0,d=w.length;a<d;a++)if(n.indexOf(o=w.charAt(a))<0){if("."==o){if(a>l){l=d;continue}}else if(!u&&(w==w.toUpperCase()&&(w=w.toLowerCase())||w==w.toLowerCase()&&(w=w.toUpperCase()))){u=!0,a=-1,l=0;continue}return i(m,String(e),g,r)}g=!1,(l=(w=t(w,r,10,m.s)).indexOf("."))>-1?w=w.replace(".",""):l=w.length}for(a=0;48===w.charCodeAt(a);a++);for(d=w.length;48===w.charCodeAt(--d););if(w=w.slice(a,++d)){if(d-=a,g&&k.DEBUG&&d>15&&(e>p||e!==f(e)))throw Error(c+m.s*e);if((l=l-a-1)>U)m.c=m.e=null;else if(l<T)m.c=[m.e=0];else{if(m.e=l,m.c=[],a=(l+1)%h,l<0&&(a+=h),a<d){for(a&&m.c.push(+w.slice(0,a)),d-=h;a<d;)m.c.push(+w.slice(a,a+=h));a=h-(w=w.slice(a)).length}else a-=d;for(;a--;w+="0");m.c.push(+w)}}else m.c=[m.e=0]}function z(e,r,n,t){var i,o,s,u,f;if(null==n?n=L:b(n,0,8),!e.c)return e.toString();if(i=e.c[0],s=e.e,null==r)f=v(e.c),f=1==t||2==t&&(s<=M||s>=I)?N(f,s):E(f,s,"0");else if(o=(e=V(new k(e),r,n)).e,u=(f=v(e.c)).length,1==t||2==t&&(r<=o||o<=M)){for(;u<r;f+="0",u++);f=N(f,o)}else if(r-=s,f=E(f,o,"0"),o+1>u){if(--r>0)for(f+=".";r--;f+="0");}else if((r+=o-u)>0)for(o+1==u&&(f+=".");r--;f+="0");return e.s<0&&i?"-"+f:f}function $(e,r){for(var n,t=1,i=new k(e[0]);t<e.length;t++){if(!(n=new k(e[t])).s){i=n;break}r.call(i,n)&&(i=n)}return i}function H(e,r,n){for(var t=1,i=r.length;!r[--i];r.pop());for(i=r[0];i>=10;i/=10,t++);return(n=t+n*h-1)>U?e.c=e.e=null:n<T?e.c=[e.e=0]:(e.e=n,e.c=r),e}function V(e,r,n,t){var i,o,s,l,c,p,d,w=e.c,m=g;if(w){e:{for(i=1,l=w[0];l>=10;l/=10,i++);if((o=r-i)<0)o+=h,s=r,d=(c=w[p=0])/m[i-s-1]%10|0;else if((p=u((o+1)/h))>=w.length){if(!t)break e;for(;w.length<=p;w.push(0));c=d=0,i=1,s=(o%=h)-h+1}else{for(c=l=w[p],i=1;l>=10;l/=10,i++);d=(s=(o%=h)-h+i)<0?0:c/m[i-s-1]%10|0}if(t=t||r<0||null!=w[p+1]||(s<0?c:c%m[i-s-1]),t=n<4?(d||t)&&(0==n||n==(e.s<0?3:2)):d>5||5==d&&(4==n||t||6==n&&(o>0?s>0?c/m[i-s]:0:w[p-1])%10&1||n==(e.s<0?8:7)),r<1||!w[0])return w.length=0,t?(r-=e.e+1,w[0]=m[(h-r%h)%h],e.e=-r||0):w[0]=e.e=0,e;if(0==o?(w.length=p,l=1,p--):(w.length=p+1,l=m[h-o],w[p]=s>0?f(c/m[i-s]%m[s])*l:0),t)for(;;){if(0==p){for(o=1,s=w[0];s>=10;s/=10,o++);for(s=w[0]+=l,l=1;s>=10;s/=10,l++);o!=l&&(e.e++,w[0]==a&&(w[0]=1));break}if(w[p]+=l,w[p]!=a)break;w[p--]=0,l=1}for(o=w.length;0===w[--o];w.pop());}e.e>U?e.c=e.e=null:e.e<T&&(e.c=[e.e=0])}return e}function W(e){var r,n=e.e;return null===n?e.toString():(r=v(e.c),r=n<=M||n>=I?N(r,n):E(r,n,"0"),e.s<0?"-"+r:r)}return k.clone=e,k.ROUND_UP=0,k.ROUND_DOWN=1,k.ROUND_CEIL=2,k.ROUND_FLOOR=3,k.ROUND_HALF_UP=4,k.ROUND_HALF_DOWN=5,k.ROUND_HALF_EVEN=6,k.ROUND_HALF_CEIL=7,k.ROUND_HALF_FLOOR=8,k.EUCLID=9,k.config=k.set=function(e){var r,n;if(null!=e){if("object"!=typeof e)throw Error(l+"Object expected: "+e);if(e.hasOwnProperty(r="DECIMAL_PLACES")&&(b(n=e[r],0,w,r),B=n),e.hasOwnProperty(r="ROUNDING_MODE")&&(b(n=e[r],0,8,r),L=n),e.hasOwnProperty(r="EXPONENTIAL_AT")&&((n=e[r])&&n.pop?(b(n[0],-w,0,r),b(n[1],0,w,r),M=n[0],I=n[1]):(b(n,-w,w,r),M=-(I=n<0?-n:n))),e.hasOwnProperty(r="RANGE"))if((n=e[r])&&n.pop)b(n[0],-w,-1,r),b(n[1],1,w,r),T=n[0],U=n[1];else{if(b(n,-w,w,r),!n)throw Error(l+r+" cannot be zero: "+n);T=-(U=n<0?-n:n)}if(e.hasOwnProperty(r="CRYPTO")){if((n=e[r])!==!!n)throw Error(l+r+" not true or false: "+n);if(n){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw C=!n,Error(l+"crypto unavailable");C=n}else C=n}if(e.hasOwnProperty(r="MODULO_MODE")&&(b(n=e[r],0,9,r),j=n),e.hasOwnProperty(r="POW_PRECISION")&&(b(n=e[r],0,w,r),q=n),e.hasOwnProperty(r="FORMAT")){if("object"!=typeof(n=e[r]))throw Error(l+r+" not an object: "+n);G=n}if(e.hasOwnProperty(r="ALPHABET")){if("string"!=typeof(n=e[r])||/^.$|[+-.\s]|(.).*\1/.test(n))throw Error(l+r+" invalid: "+n);F=n}}return{DECIMAL_PLACES:B,ROUNDING_MODE:L,EXPONENTIAL_AT:[M,I],RANGE:[T,U],CRYPTO:C,MODULO_MODE:j,POW_PRECISION:q,FORMAT:G,ALPHABET:F}},k.isBigNumber=function(e){if(!e||!0!==e._isBigNumber)return!1;if(!k.DEBUG)return!0;var r,n,t=e.c,i=e.e,o=e.s;e:if("[object Array]"=={}.toString.call(t)){if((1===o||-1===o)&&i>=-w&&i<=w&&i===f(i)){if(0===t[0]){if(0===i&&1===t.length)return!0;break e}if((r=(i+1)%h)<1&&(r+=h),String(t[0]).length==r){for(r=0;r<t.length;r++)if((n=t[r])<0||n>=a||n!==f(n))break e;if(0!==n)return!0}}}else if(null===t&&null===i&&(null===o||1===o||-1===o))return!0;throw Error(l+"Invalid BigNumber: "+e)},k.maximum=k.max=function(){return $(arguments,R.lt)},k.minimum=k.min=function(){return $(arguments,R.gt)},k.random=(o=9007199254740992*Math.random()&2097151?function(){return f(9007199254740992*Math.random())}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var r,n,t,i,s,c=0,a=[],p=new k(D);if(null==e?e=B:b(e,0,w),i=u(e/h),C)if(crypto.getRandomValues){for(r=crypto.getRandomValues(new Uint32Array(i*=2));c<i;)(s=131072*r[c]+(r[c+1]>>>11))>=9e15?(n=crypto.getRandomValues(new Uint32Array(2)),r[c]=n[0],r[c+1]=n[1]):(a.push(s%1e14),c+=2);c=i/2}else{if(!crypto.randomBytes)throw C=!1,Error(l+"crypto unavailable");for(r=crypto.randomBytes(i*=7);c<i;)(s=281474976710656*(31&r[c])+1099511627776*r[c+1]+4294967296*r[c+2]+16777216*r[c+3]+(r[c+4]<<16)+(r[c+5]<<8)+r[c+6])>=9e15?crypto.randomBytes(7).copy(r,c):(a.push(s%1e14),c+=7);c=i/7}if(!C)for(;c<i;)(s=o())<9e15&&(a[c++]=s%1e14);for(i=a[--c],e%=h,i&&e&&(s=g[h-e],a[c]=f(i/s)*s);0===a[c];a.pop(),c--);if(c<0)a=[t=0];else{for(t=-1;0===a[0];a.splice(0,1),t-=h);for(c=1,s=a[0];s>=10;s/=10,c++);c<h&&(t-=h-c)}return p.e=t,p.c=a,p}),k.sum=function(){for(var e=1,r=arguments,n=new k(r[0]);e<r.length;)n=n.plus(r[e++]);return n},t=function(){function e(e,r,n,t){for(var i,o,s=[0],u=0,f=e.length;u<f;){for(o=s.length;o--;s[o]*=r);for(s[0]+=t.indexOf(e.charAt(u++)),i=0;i<s.length;i++)s[i]>n-1&&(null==s[i+1]&&(s[i+1]=0),s[i+1]+=s[i]/n|0,s[i]%=n)}return s.reverse()}return function(r,t,i,o,s){var u,f,l,c,a,h,p,g,d=r.indexOf("."),w=B,m=L;for(d>=0&&(c=q,q=0,r=r.replace(".",""),h=(g=new k(t)).pow(r.length-d),q=c,g.c=e(E(v(h.c),h.e,"0"),10,i,"0123456789"),g.e=g.c.length),l=c=(p=e(r,t,i,s?(u=F,"0123456789"):(u="0123456789",F))).length;0==p[--c];p.pop());if(!p[0])return u.charAt(0);if(d<0?--l:(h.c=p,h.e=l,h.s=o,p=(h=n(h,g,w,m,i)).c,a=h.r,l=h.e),d=p[f=l+w+1],c=i/2,a=a||f<0||null!=p[f+1],a=m<4?(null!=d||a)&&(0==m||m==(h.s<0?3:2)):d>c||d==c&&(4==m||a||6==m&&1&p[f-1]||m==(h.s<0?8:7)),f<1||!p[0])r=a?E(u.charAt(1),-w,u.charAt(0)):u.charAt(0);else{if(p.length=f,a)for(--i;++p[--f]>i;)p[f]=0,f||(++l,p=[1].concat(p));for(c=p.length;!p[--c];);for(d=0,r="";d<=c;r+=u.charAt(p[d++]));r=E(r,l,u.charAt(0))}return r}}(),n=function(){function e(e,r,n){var t,i,o,s,u=0,f=e.length,l=r%d,c=r/d|0;for(e=e.slice();f--;)u=((i=l*(o=e[f]%d)+(t=c*o+(s=e[f]/d|0)*l)%d*d+u)/n|0)+(t/d|0)+c*s,e[f]=i%n;return u&&(e=[u].concat(e)),e}function r(e,r,n,t){var i,o;if(n!=t)o=n>t?1:-1;else for(i=o=0;i<n;i++)if(e[i]!=r[i]){o=e[i]>r[i]?1:-1;break}return o}function n(e,r,n,t){for(var i=0;n--;)e[n]-=i,i=e[n]<r[n]?1:0,e[n]=i*t+e[n]-r[n];for(;!e[0]&&e.length>1;e.splice(0,1));}return function(t,i,o,s,u){var l,c,p,g,d,w,v,y,b,O,N,E,A,S,x,_,P,R=t.s==i.s?1:-1,D=t.c,B=i.c;if(!(D&&D[0]&&B&&B[0]))return new k(t.s&&i.s&&(D?!B||D[0]!=B[0]:B)?D&&0==D[0]||!B?0*R:R/0:NaN);for(b=(y=new k(R)).c=[],R=o+(c=t.e-i.e)+1,u||(u=a,c=m(t.e/h)-m(i.e/h),R=R/h|0),p=0;B[p]==(D[p]||0);p++);if(B[p]>(D[p]||0)&&c--,R<0)b.push(1),g=!0;else{for(S=D.length,_=B.length,p=0,R+=2,(d=f(u/(B[0]+1)))>1&&(B=e(B,d,u),D=e(D,d,u),_=B.length,S=D.length),A=_,N=(O=D.slice(0,_)).length;N<_;O[N++]=0);P=B.slice(),P=[0].concat(P),x=B[0],B[1]>=u/2&&x++;do{if(d=0,(l=r(B,O,_,N))<0){if(E=O[0],_!=N&&(E=E*u+(O[1]||0)),(d=f(E/x))>1)for(d>=u&&(d=u-1),v=(w=e(B,d,u)).length,N=O.length;1==r(w,O,v,N);)d--,n(w,_<v?P:B,v,u),v=w.length,l=1;else 0==d&&(l=d=1),v=(w=B.slice()).length;if(v<N&&(w=[0].concat(w)),n(O,w,N,u),N=O.length,-1==l)for(;r(B,O,_,N)<1;)d++,n(O,_<N?P:B,N,u),N=O.length}else 0===l&&(d++,O=[0]);b[p++]=d,O[0]?O[N++]=D[A]||0:(O=[D[A]],N=1)}while((A++<S||null!=O[0])&&R--);g=null!=O[0],b[0]||b.splice(0,1)}if(u==a){for(p=1,R=b[0];R>=10;R/=10,p++);V(y,o+(y.e=p+c*h-1)+1,s,g)}else y.e=c,y.r=+g;return y}}(),A=/^(-?)0([xbo])(?=\w[\w.]*$)/i,S=/^([^.]+)\.$/,x=/^\.([^.]+)$/,_=/^-?(Infinity|NaN)$/,P=/^\s*\+(?=[\w.])|^\s+|\s+$/g,i=function(e,r,n,t){var i,o=n?r:r.replace(P,"");if(_.test(o))e.s=isNaN(o)?null:o<0?-1:1;else{if(!n&&(o=o.replace(A,function(e,r,n){return i="x"==(n=n.toLowerCase())?16:"b"==n?2:8,t&&t!=i?e:r}),t&&(i=t,o=o.replace(S,"$1").replace(x,"0.$1")),r!=o))return new k(o,i);if(k.DEBUG)throw Error(l+"Not a"+(t?" base "+t:"")+" number: "+r);e.s=null}e.c=e.e=null},R.absoluteValue=R.abs=function(){var e=new k(this);return e.s<0&&(e.s=1),e},R.comparedTo=function(e,r){return y(this,new k(e,r))},R.decimalPlaces=R.dp=function(e,r){var n,t,i,o=this;if(null!=e)return b(e,0,w),null==r?r=L:b(r,0,8),V(new k(o),e+o.e+1,r);if(!(n=o.c))return null;if(t=((i=n.length-1)-m(this.e/h))*h,i=n[i])for(;i%10==0;i/=10,t--);return t<0&&(t=0),t},R.dividedBy=R.div=function(e,r){return n(this,new k(e,r),B,L)},R.dividedToIntegerBy=R.idiv=function(e,r){return n(this,new k(e,r),0,1)},R.exponentiatedBy=R.pow=function(e,r){var n,t,i,o,s,c,a,p,g=this;if((e=new k(e)).c&&!e.isInteger())throw Error(l+"Exponent not an integer: "+W(e));if(null!=r&&(r=new k(r)),s=e.e>14,!g.c||!g.c[0]||1==g.c[0]&&!g.e&&1==g.c.length||!e.c||!e.c[0])return p=new k(Math.pow(+W(g),s?2-O(e):+W(e))),r?p.mod(r):p;if(c=e.s<0,r){if(r.c?!r.c[0]:!r.s)return new k(NaN);(t=!c&&g.isInteger()&&r.isInteger())&&(g=g.mod(r))}else{if(e.e>9&&(g.e>0||g.e<-1||(0==g.e?g.c[0]>1||s&&g.c[1]>=24e7:g.c[0]<8e13||s&&g.c[0]<=9999975e7)))return o=g.s<0&&O(e)?-0:0,g.e>-1&&(o=1/o),new k(c?1/o:o);q&&(o=u(q/h+2))}for(s?(n=new k(.5),c&&(e.s=1),a=O(e)):a=(i=Math.abs(+W(e)))%2,p=new k(D);;){if(a){if(!(p=p.times(g)).c)break;o?p.c.length>o&&(p.c.length=o):t&&(p=p.mod(r))}if(i){if(0===(i=f(i/2)))break;a=i%2}else if(V(e=e.times(n),e.e+1,1),e.e>14)a=O(e);else{if(0==(i=+W(e)))break;a=i%2}g=g.times(g),o?g.c&&g.c.length>o&&(g.c.length=o):t&&(g=g.mod(r))}return t?p:(c&&(p=D.div(p)),r?p.mod(r):o?V(p,q,L,void 0):p)},R.integerValue=function(e){var r=new k(this);return null==e?e=L:b(e,0,8),V(r,r.e+1,e)},R.isEqualTo=R.eq=function(e,r){return 0===y(this,new k(e,r))},R.isFinite=function(){return!!this.c},R.isGreaterThan=R.gt=function(e,r){return y(this,new k(e,r))>0},R.isGreaterThanOrEqualTo=R.gte=function(e,r){return 1===(r=y(this,new k(e,r)))||0===r},R.isInteger=function(){return!!this.c&&m(this.e/h)>this.c.length-2},R.isLessThan=R.lt=function(e,r){return y(this,new k(e,r))<0},R.isLessThanOrEqualTo=R.lte=function(e,r){return-1===(r=y(this,new k(e,r)))||0===r},R.isNaN=function(){return!this.s},R.isNegative=function(){return this.s<0},R.isPositive=function(){return this.s>0},R.isZero=function(){return!!this.c&&0==this.c[0]},R.minus=function(e,r){var n,t,i,o,s=this,u=s.s;if(r=(e=new k(e,r)).s,!u||!r)return new k(NaN);if(u!=r)return e.s=-r,s.plus(e);var f=s.e/h,l=e.e/h,c=s.c,p=e.c;if(!f||!l){if(!c||!p)return c?(e.s=-r,e):new k(p?s:NaN);if(!c[0]||!p[0])return p[0]?(e.s=-r,e):new k(c[0]?s:3==L?-0:0)}if(f=m(f),l=m(l),c=c.slice(),u=f-l){for((o=u<0)?(u=-u,i=c):(l=f,i=p),i.reverse(),r=u;r--;i.push(0));i.reverse()}else for(t=(o=(u=c.length)<(r=p.length))?u:r,u=r=0;r<t;r++)if(c[r]!=p[r]){o=c[r]<p[r];break}if(o&&(i=c,c=p,p=i,e.s=-e.s),(r=(t=p.length)-(n=c.length))>0)for(;r--;c[n++]=0);for(r=a-1;t>u;){if(c[--t]<p[t]){for(n=t;n&&!c[--n];c[n]=r);--c[n],c[t]+=a}c[t]-=p[t]}for(;0==c[0];c.splice(0,1),--l);return c[0]?H(e,c,l):(e.s=3==L?-1:1,e.c=[e.e=0],e)},R.modulo=R.mod=function(e,r){var t,i,o=this;return e=new k(e,r),!o.c||!e.s||e.c&&!e.c[0]?new k(NaN):!e.c||o.c&&!o.c[0]?new k(o):(9==j?(i=e.s,e.s=1,t=n(o,e,0,3),e.s=i,t.s*=i):t=n(o,e,0,j),(e=o.minus(t.times(e))).c[0]||1!=j||(e.s=o.s),e)},R.multipliedBy=R.times=function(e,r){var n,t,i,o,s,u,f,l,c,p,g,w,v,y,b,O=this,N=O.c,E=(e=new k(e,r)).c;if(!(N&&E&&N[0]&&E[0]))return!O.s||!e.s||N&&!N[0]&&!E||E&&!E[0]&&!N?e.c=e.e=e.s=null:(e.s*=O.s,N&&E?(e.c=[0],e.e=0):e.c=e.e=null),e;for(t=m(O.e/h)+m(e.e/h),e.s*=O.s,(f=N.length)<(p=E.length)&&(v=N,N=E,E=v,i=f,f=p,p=i),i=f+p,v=[];i--;v.push(0));for(y=a,b=d,i=p;--i>=0;){for(n=0,g=E[i]%b,w=E[i]/b|0,o=i+(s=f);o>i;)n=((l=g*(l=N[--s]%b)+(u=w*l+(c=N[s]/b|0)*g)%b*b+v[o]+n)/y|0)+(u/b|0)+w*c,v[o--]=l%y;v[o]=n}return n?++t:v.splice(0,1),H(e,v,t)},R.negated=function(){var e=new k(this);return e.s=-e.s||null,e},R.plus=function(e,r){var n,t=this,i=t.s;if(r=(e=new k(e,r)).s,!i||!r)return new k(NaN);if(i!=r)return e.s=-r,t.minus(e);var o=t.e/h,s=e.e/h,u=t.c,f=e.c;if(!o||!s){if(!u||!f)return new k(i/0);if(!u[0]||!f[0])return f[0]?e:new k(u[0]?t:0*i)}if(o=m(o),s=m(s),u=u.slice(),i=o-s){for(i>0?(s=o,n=f):(i=-i,n=u),n.reverse();i--;n.push(0));n.reverse()}for((i=u.length)-(r=f.length)<0&&(n=f,f=u,u=n,r=i),i=0;r;)i=(u[--r]=u[r]+f[r]+i)/a|0,u[r]=a===u[r]?0:u[r]%a;return i&&(u=[i].concat(u),++s),H(e,u,s)},R.precision=R.sd=function(e,r){var n,t,i,o=this;if(null!=e&&e!==!!e)return b(e,1,w),null==r?r=L:b(r,0,8),V(new k(o),e,r);if(!(n=o.c))return null;if(t=(i=n.length-1)*h+1,i=n[i]){for(;i%10==0;i/=10,t--);for(i=n[0];i>=10;i/=10,t++);}return e&&o.e+1>t&&(t=o.e+1),t},R.shiftedBy=function(e){return b(e,-p,p),this.times("1e"+e)},R.squareRoot=R.sqrt=function(){var e,r,t,i,o,s=this,u=s.c,f=s.s,l=s.e,c=B+4,a=new k("0.5");if(1!==f||!u||!u[0])return new k(!f||f<0&&(!u||u[0])?NaN:u?s:1/0);if(0==(f=Math.sqrt(+W(s)))||f==1/0?(((r=v(u)).length+l)%2==0&&(r+="0"),f=Math.sqrt(+r),l=m((l+1)/2)-(l<0||l%2),t=new k(r=f==1/0?"1e"+l:(r=f.toExponential()).slice(0,r.indexOf("e")+1)+l)):t=new k(f+""),t.c[0])for((f=(l=t.e)+c)<3&&(f=0);;)if(o=t,t=a.times(o.plus(n(s,o,c,1))),v(o.c).slice(0,f)===(r=v(t.c)).slice(0,f)){if(t.e<l&&--f,"9999"!=(r=r.slice(f-3,f+1))&&(i||"4999"!=r)){+r&&(+r.slice(1)||"5"!=r.charAt(0))||(V(t,t.e+B+2,1),e=!t.times(t).eq(s));break}if(!i&&(V(o,o.e+B+2,0),o.times(o).eq(s))){t=o;break}c+=4,f+=4,i=1}return V(t,t.e+B+1,L,e)},R.toExponential=function(e,r){return null!=e&&(b(e,0,w),e++),z(this,e,r,1)},R.toFixed=function(e,r){return null!=e&&(b(e,0,w),e=e+this.e+1),z(this,e,r)},R.toFormat=function(e,r,n){var t,i=this;if(null==n)null!=e&&r&&"object"==typeof r?(n=r,r=null):e&&"object"==typeof e?(n=e,e=r=null):n=G;else if("object"!=typeof n)throw Error(l+"Argument not an object: "+n);if(t=i.toFixed(e,r),i.c){var o,s=t.split("."),u=+n.groupSize,f=+n.secondaryGroupSize,c=n.groupSeparator||"",a=s[0],h=s[1],p=i.s<0,g=p?a.slice(1):a,d=g.length;if(f&&(o=u,u=f,f=o,d-=o),u>0&&d>0){for(o=d%u||u,a=g.substr(0,o);o<d;o+=u)a+=c+g.substr(o,u);f>0&&(a+=c+g.slice(o)),p&&(a="-"+a)}t=h?a+(n.decimalSeparator||"")+((f=+n.fractionGroupSize)?h.replace(new RegExp("\\d{"+f+"}\\B","g"),"$&"+(n.fractionGroupSeparator||"")):h):a}return(n.prefix||"")+t+(n.suffix||"")},R.toFraction=function(e){var r,t,i,o,s,u,f,c,a,p,d,w,m=this,y=m.c;if(null!=e&&(!(f=new k(e)).isInteger()&&(f.c||1!==f.s)||f.lt(D)))throw Error(l+"Argument "+(f.isInteger()?"out of range: ":"not an integer: ")+W(f));if(!y)return new k(m);for(r=new k(D),a=t=new k(D),i=c=new k(D),w=v(y),s=r.e=w.length-m.e-1,r.c[0]=g[(u=s%h)<0?h+u:u],e=!e||f.comparedTo(r)>0?s>0?r:a:f,u=U,U=1/0,f=new k(w),c.c[0]=0;p=n(f,r,0,1),1!=(o=t.plus(p.times(i))).comparedTo(e);)t=i,i=o,a=c.plus(p.times(o=a)),c=o,r=f.minus(p.times(o=r)),f=o;return o=n(e.minus(t),i,0,1),c=c.plus(o.times(a)),t=t.plus(o.times(i)),c.s=a.s=m.s,d=n(a,i,s*=2,L).minus(m).abs().comparedTo(n(c,t,s,L).minus(m).abs())<1?[a,i]:[c,t],U=u,d},R.toNumber=function(){return+W(this)},R.toPrecision=function(e,r){return null!=e&&b(e,1,w),z(this,e,r,2)},R.toString=function(e){var r,n=this,i=n.s,o=n.e;return null===o?i?(r="Infinity",i<0&&(r="-"+r)):r="NaN":(null==e?r=o<=M||o>=I?N(v(n.c),o):E(v(n.c),o,"0"):10===e?r=E(v((n=V(new k(n),B+o+1,L)).c),n.e,"0"):(b(e,2,F.length,"Base"),r=t(E(v(n.c),o,"0"),10,e,i,!0)),i<0&&n.c[0]&&(r="-"+r)),r},R.valueOf=R.toJSON=function(){return W(this)},R._isBigNumber=!0,null!=r&&k.set(r),k}()).default=o.BigNumber=o,void 0===(t=function(){return o}.call(r,n,r,e))||(e.exports=t)}()}]);