function div(a,b){return(a-a%b)/b}BigDecimal.prototype.div=div;function arraycopy(a,b,c,d,e){var h;if(d>b)for(h=e-1;0<=h;--h)c[h+d]=a[h+b];else for(h=0;h<e;++h)c[h+d]=a[h+b]}BigDecimal.prototype.arraycopy=arraycopy;function createArrayWithZeros(a){var b=Array(a),c;for(c=0;c<a;++c)b[c]=0;return b}BigDecimal.prototype.createArrayWithZeros=createArrayWithZeros;BigDecimal.prototype.abs=abs;BigDecimal.prototype.add=add;BigDecimal.prototype.compareTo=compareTo;BigDecimal.prototype.divide=divide;
BigDecimal.prototype.divideInteger=divideInteger;BigDecimal.prototype.max=max;BigDecimal.prototype.min=min;BigDecimal.prototype.multiply=multiply;BigDecimal.prototype.negate=negate;BigDecimal.prototype.plus=plus;BigDecimal.prototype.pow=pow;BigDecimal.prototype.remainder=remainder;BigDecimal.prototype.subtract=subtract;BigDecimal.prototype.equals=equals;BigDecimal.prototype.format=format;BigDecimal.prototype.intValueExact=intValueExact;BigDecimal.prototype.movePointLeft=movePointLeft;
BigDecimal.prototype.movePointRight=movePointRight;BigDecimal.prototype.scale=scale;BigDecimal.prototype.setScale=setScale;BigDecimal.prototype.signum=signum;BigDecimal.prototype.toString=toString;BigDecimal.prototype.layout=layout;BigDecimal.prototype.intcheck=intcheck;BigDecimal.prototype.dodivide=dodivide;BigDecimal.prototype.bad=bad;BigDecimal.prototype.badarg=badarg;BigDecimal.prototype.extend=extend;BigDecimal.prototype.byteaddsub=byteaddsub;BigDecimal.prototype.diginit=diginit;
BigDecimal.prototype.clone=clone;BigDecimal.prototype.checkdigits=checkdigits;BigDecimal.prototype.round=round;BigDecimal.prototype.allzero=allzero;BigDecimal.prototype.finish=finish;BigDecimal.prototype.isGreaterThan=isGreaterThan;BigDecimal.prototype.isLessThan=isLessThan;BigDecimal.prototype.isGreaterThanOrEqualTo=isGreaterThanOrEqualTo;BigDecimal.prototype.isLessThanOrEqualTo=isLessThanOrEqualTo;BigDecimal.prototype.isPositive=isPositive;BigDecimal.prototype.isNegative=isNegative;
BigDecimal.prototype.isZero=isZero;BigDecimal.ROUND_CEILING=BigDecimal.prototype.ROUND_CEILING=MathContext.prototype.ROUND_CEILING;BigDecimal.ROUND_DOWN=BigDecimal.prototype.ROUND_DOWN=MathContext.prototype.ROUND_DOWN;BigDecimal.ROUND_FLOOR=BigDecimal.prototype.ROUND_FLOOR=MathContext.prototype.ROUND_FLOOR;BigDecimal.ROUND_HALF_DOWN=BigDecimal.prototype.ROUND_HALF_DOWN=MathContext.prototype.ROUND_HALF_DOWN;BigDecimal.ROUND_HALF_EVEN=BigDecimal.prototype.ROUND_HALF_EVEN=MathContext.prototype.ROUND_HALF_EVEN;
BigDecimal.ROUND_HALF_UP=BigDecimal.prototype.ROUND_HALF_UP=MathContext.prototype.ROUND_HALF_UP;BigDecimal.ROUND_UNNECESSARY=BigDecimal.prototype.ROUND_UNNECESSARY=MathContext.prototype.ROUND_UNNECESSARY;BigDecimal.ROUND_UP=BigDecimal.prototype.ROUND_UP=MathContext.prototype.ROUND_UP;BigDecimal.prototype.ispos=1;BigDecimal.prototype.iszero=0;BigDecimal.prototype.isneg=-1;BigDecimal.prototype.MinExp=-999999999;BigDecimal.prototype.MaxExp=999999999;BigDecimal.prototype.MinArg=-999999999;
BigDecimal.prototype.MaxArg=999999999;BigDecimal.prototype.plainMC=new MathContext(0,MathContext.prototype.PLAIN);BigDecimal.prototype.bytecar=Array(190);BigDecimal.prototype.bytedig=diginit();BigDecimal.ZERO=BigDecimal.prototype.ZERO=new BigDecimal("0");BigDecimal.ONE=BigDecimal.prototype.ONE=new BigDecimal("1");BigDecimal.ONE_NEGATIVE=BigDecimal.prototype.ONE_NEGATIVE=new BigDecimal("-1");BigDecimal.TEN=BigDecimal.prototype.TEN=new BigDecimal("10");
BigDecimal.HUNDRED=BigDecimal.prototype.HUNDRED=new BigDecimal("100");
function BigDecimal(){this.ind=0;this.form=MathContext.prototype.PLAIN;this.mant=null;this.exp=0;if(0!=BigDecimal.arguments.length){var a,b,c;1==BigDecimal.arguments.length?(a=BigDecimal.arguments[0],b=0,c=a.length):(a=BigDecimal.arguments[0],b=BigDecimal.arguments[1],c=BigDecimal.arguments[2]);"string"==typeof a&&(a=a.split(""));var d,e,h,f,g,k=0,l=0;e=!1;var n=l=l=k=0,m=0;f=0;0>=c&&this.bad("BigDecimal(): ",a);this.ind=this.ispos;"-"==a[0]?(c--,0==c&&this.bad("BigDecimal(): ",a),this.ind=this.isneg,
b++):"+"==a[0]&&(c--,0==c&&this.bad("BigDecimal(): ",a),b++);e=d=!1;h=0;g=f=-1;n=c;k=b;a:for(;0<n;n--,k++){l=a[k];if("0"<=l&&"9">=l){g=k;h++;continue a}if("."==l){0<=f&&this.bad("BigDecimal(): ",a);f=k-b;continue a}if("e"!=l&&"E"!=l){("0">l||"9"<l)&&this.bad("BigDecimal(): ",a);d=!0;g=k;h++;continue a}k-b>c-2&&this.bad("BigDecimal(): ",a);e=!1;"-"==a[k+1]?(e=!0,k+=2):k="+"==a[k+1]?k+2:k+1;l=c-(k-b);(0==l||9<l)&&this.bad("BigDecimal(): ",a);c=l;l=k;for(;0<c;c--,l++)n=a[l],"0">n&&this.bad("BigDecimal(): ",
a),"9"<n?this.bad("BigDecimal(): ",a):m=n-0,this.exp=10*this.exp+m;e&&(this.exp=-this.exp);e=!0;break a}0==h&&this.bad("BigDecimal(): ",a);0<=f&&(this.exp=this.exp+f-h);m=g-1;k=b;a:for(;k<=m;k++)if(l=a[k],"0"==l)b++,f--,h--;else if("."==l)b++,f--;else break a;this.mant=Array(h);l=b;if(d)for(b=h,k=0;0<b;b--,k++)k==f&&l++,n=a[l],"9">=n?this.mant[k]=n-0:this.bad("BigDecimal(): ",a),l++;else for(b=h,k=0;0<b;b--,k++)k==f&&l++,this.mant[k]=a[l]-0,l++;0==this.mant[0]?(this.ind=this.iszero,0<this.exp&&(this.exp=
0),e&&(this.mant=this.ZERO.mant,this.exp=0)):e&&(this.form=MathContext.prototype.SCIENTIFIC,f=this.exp+this.mant.length-1,(f<this.MinExp||f>this.MaxExp)&&this.bad("BigDecimal(): ",a))}}function abs(){var a;if(1==abs.arguments.length)a=abs.arguments[0];else if(0==abs.arguments.length)a=this.plainMC;else throw"abs(): "+abs.arguments.length+" arguments given; expected 0 or 1";return this.ind==this.isneg?this.negate(a):this.plus(a)}
function add(){var a;if(2==add.arguments.length)a=add.arguments[1];else if(1==add.arguments.length)a=this.plainMC;else throw"add(): "+add.arguments.length+" arguments given; expected 1 or 2";var b=add.arguments[0],c,d,e,h,f,g,k,l=0;d=l=0;var l=null,n=l=0,m=0,q=0,r=0,p=0;a.lostDigits&&this.checkdigits(b,a.digits);c=this;if(0==c.ind&&a.form!=MathContext.prototype.PLAIN)return b.plus(a);if(0==b.ind&&a.form!=MathContext.prototype.PLAIN)return c.plus(a);d=a.digits;0<d&&(c.mant.length>d&&(c=this.clone(c).round(a)),
b.mant.length>d&&(b=this.clone(b).round(a)));e=new BigDecimal;h=c.mant;f=c.mant.length;g=b.mant;k=b.mant.length;if(c.exp==b.exp)e.exp=c.exp;else if(c.exp>b.exp){l=f+c.exp-b.exp;if(l>=k+d+1&&0<d)return e.mant=h,e.exp=c.exp,e.ind=c.ind,f<d&&(e.mant=this.extend(c.mant,d),e.exp-=d-f),e.finish(a,!1);e.exp=b.exp;l>d+1&&0<d&&(l=l-d-1,k-=l,e.exp+=l,l=d+1);l>f&&(f=l)}else{l=k+b.exp-c.exp;if(l>=f+d+1&&0<d)return e.mant=g,e.exp=b.exp,e.ind=b.ind,k<d&&(e.mant=this.extend(b.mant,d),e.exp-=d-k),e.finish(a,!1);
e.exp=c.exp;l>d+1&&0<d&&(l=l-d-1,f-=l,e.exp+=l,l=d+1);l>k&&(k=l)}e.ind=c.ind==this.iszero?this.ispos:c.ind;if((c.ind==this.isneg?1:0)==(b.ind==this.isneg?1:0))d=1;else{do{d=-1;do if(b.ind!=this.iszero)if(f<k||c.ind==this.iszero)l=h,h=g,g=l,l=f,f=k,k=l,e.ind=-e.ind;else if(!(f>k))c:for(n=l=0,m=h.length-1,q=g.length-1;;){if(l<=m)r=h[l];else{if(n>q){if(a.form!=MathContext.prototype.PLAIN)return this.ZERO;break c}r=0}p=n<=q?g[n]:0;if(r!=p){r<p&&(l=h,h=g,g=l,l=f,f=k,k=l,e.ind=-e.ind);break c}l++;n++}while(0)}while(0)
}e.mant=this.byteaddsub(h,f,g,k,d,!1);return e.finish(a,!1)}
function compareTo(){var a;if(2==compareTo.arguments.length)a=compareTo.arguments[1];else if(1==compareTo.arguments.length)a=this.plainMC;else throw"compareTo(): "+compareTo.arguments.length+" arguments given; expected 1 or 2";var b=compareTo.arguments[0],c=0,c=0;a.lostDigits&&this.checkdigits(b,a.digits);if(this.ind==b.ind&&this.exp==b.exp){c=this.mant.length;if(c<b.mant.length)return-this.ind;if(c>b.mant.length)return this.ind;if(c<=a.digits||0==a.digits){a=c;c=0;for(;0<a;a--,c++){if(this.mant[c]<
b.mant[c])return-this.ind;if(this.mant[c]>b.mant[c])return this.ind}return 0}}else{if(this.ind<b.ind)return-1;if(this.ind>b.ind)return 1}b=this.clone(b);b.ind=-b.ind;return this.add(b,a).ind}
function divide(){var a,b=-1;if(2==divide.arguments.length)a="number"==typeof divide.arguments[1]?new MathContext(0,MathContext.prototype.PLAIN,!1,divide.arguments[1]):divide.arguments[1];else if(3==divide.arguments.length){b=divide.arguments[1];if(0>b)throw"divide(): Negative scale: "+b;a=new MathContext(0,MathContext.prototype.PLAIN,!1,divide.arguments[2])}else if(1==divide.arguments.length)a=this.plainMC;else throw"divide(): "+divide.arguments.length+" arguments given; expected between 1 and 3";
return this.dodivide("D",divide.arguments[0],a,b)}function divideInteger(){var a;if(2==divideInteger.arguments.length)a=divideInteger.arguments[1];else if(1==divideInteger.arguments.length)a=this.plainMC;else throw"divideInteger(): "+divideInteger.arguments.length+" arguments given; expected 1 or 2";return this.dodivide("I",divideInteger.arguments[0],a,0)}
function max(){var a;if(2==max.arguments.length)a=max.arguments[1];else if(1==max.arguments.length)a=this.plainMC;else throw"max(): "+max.arguments.length+" arguments given; expected 1 or 2";var b=max.arguments[0];return 0<=this.compareTo(b,a)?this.plus(a):b.plus(a)}
function min(){var a;if(2==min.arguments.length)a=min.arguments[1];else if(1==min.arguments.length)a=this.plainMC;else throw"min(): "+min.arguments.length+" arguments given; expected 1 or 2";var b=min.arguments[0];return 0>=this.compareTo(b,a)?this.plus(a):b.plus(a)}
function multiply(){var a;if(2==multiply.arguments.length)a=multiply.arguments[1];else if(1==multiply.arguments.length)a=this.plainMC;else throw"multiply(): "+multiply.arguments.length+" arguments given; expected 1 or 2";var b=multiply.arguments[0],c,d,e,h=e=null,f,g=0,k,l=0,n=0;a.lostDigits&&this.checkdigits(b,a.digits);c=this;d=0;e=a.digits;0<e?(c.mant.length>e&&(c=this.clone(c).round(a)),b.mant.length>e&&(b=this.clone(b).round(a))):(0<c.exp&&(d+=c.exp),0<b.exp&&(d+=b.exp));c.mant.length<b.mant.length?
(e=c.mant,h=b.mant):(e=b.mant,h=c.mant);f=e.length+h.length-1;g=9<e[0]*h[0]?f+1:f;k=new BigDecimal;var g=this.createArrayWithZeros(g),m=e.length,l=0;for(;0<m;m--,l++)n=e[l],0!=n&&(g=this.byteaddsub(g,g.length,h,f,n,!0)),f--;k.ind=c.ind*b.ind;k.exp=c.exp+b.exp-d;k.mant=0==d?g:this.extend(g,g.length+d);return k.finish(a,!1)}
function negate(){var a;if(1==negate.arguments.length)a=negate.arguments[0];else if(0==negate.arguments.length)a=this.plainMC;else throw"negate(): "+negate.arguments.length+" arguments given; expected 0 or 1";var b;a.lostDigits&&this.checkdigits(null,a.digits);b=this.clone(this);b.ind=-b.ind;return b.finish(a,!1)}
function plus(){var a;if(1==plus.arguments.length)a=plus.arguments[0];else if(0==plus.arguments.length)a=this.plainMC;else throw"plus(): "+plus.arguments.length+" arguments given; expected 0 or 1";a.lostDigits&&this.checkdigits(null,a.digits);return a.form==MathContext.prototype.PLAIN&&this.form==MathContext.prototype.PLAIN&&(this.mant.length<=a.digits||0==a.digits)?this:this.clone(this).finish(a,!1)}
function pow(){var a;if(2==pow.arguments.length)a=pow.arguments[1];else if(1==pow.arguments.length)a=this.plainMC;else throw"pow(): "+pow.arguments.length+" arguments given; expected 1 or 2";var b=pow.arguments[0],c,d,e,h=e=0,f,g=0;a.lostDigits&&this.checkdigits(b,a.digits);c=b.intcheck(this.MinArg,this.MaxArg);d=this;e=a.digits;if(0==e){if(b.ind==this.isneg)throw"pow(): Negative power: "+b.toString();e=0}else{if(b.mant.length+b.exp>e)throw"pow(): Too many digits: "+b.toString();d.mant.length>e&&
(d=this.clone(d).round(a));h=b.mant.length+b.exp;e=e+h+1}e=new MathContext(e,a.form,!1,a.roundingMode);h=this.ONE;if(0==c)return h;0>c&&(c=-c);f=!1;g=1;a:for(;;g++){c<<=1;0>c&&(f=!0,h=h.multiply(d,e));if(31==g)break a;if(!f)continue a;h=h.multiply(h,e)}0>b.ind&&(h=this.ONE.divide(h,e));return h.finish(a,!0)}
function remainder(){var a;if(2==remainder.arguments.length)a=remainder.arguments[1];else if(1==remainder.arguments.length)a=this.plainMC;else throw"remainder(): "+remainder.arguments.length+" arguments given; expected 1 or 2";return this.dodivide("R",remainder.arguments[0],a,-1)}
function subtract(){var a;if(2==subtract.arguments.length)a=subtract.arguments[1];else if(1==subtract.arguments.length)a=this.plainMC;else throw"subtract(): "+subtract.arguments.length+" arguments given; expected 1 or 2";var b=subtract.arguments[0];a.lostDigits&&this.checkdigits(b,a.digits);b=this.clone(b);b.ind=-b.ind;return this.add(b,a)}
function equals(a){var b=0,c=null,d=null;if(null==a||!(a instanceof BigDecimal)||this.ind!=a.ind)return!1;if(this.mant.length==a.mant.length&&this.exp==a.exp&&this.form==a.form)for(c=this.mant.length,b=0;0<c;c--,b++){if(this.mant[b]!=a.mant[b])return!1}else{c=this.layout();d=a.layout();if(c.length!=d.length)return!1;a=c.length;b=0;for(;0<a;a--,b++)if(c[b]!=d[b])return!1}return!0}
function format(){var a,b,c,d;if(6==format.arguments.length)a=format.arguments[2],b=format.arguments[3],c=format.arguments[4],d=format.arguments[5];else if(2==format.arguments.length)b=a=-1,c=MathContext.prototype.SCIENTIFIC,d=this.ROUND_HALF_UP;else throw"format(): "+format.arguments.length+" arguments given; expected 2 or 6";var e=format.arguments[0],h=format.arguments[1],f,g=0,g=g=0,k=null,l=k=g=0;f=0;g=null;l=k=0;(-1>e||0==e)&&this.badarg("format",1,e);-1>h&&this.badarg("format",2,h);(-1>a||0==
a)&&this.badarg("format",3,a);-1>b&&this.badarg("format",4,b);c!=MathContext.prototype.SCIENTIFIC&&c!=MathContext.prototype.ENGINEERING&&(-1==c?c=MathContext.prototype.SCIENTIFIC:this.badarg("format",5,c));if(d!=this.ROUND_HALF_UP)try{-1==d?d=this.ROUND_HALF_UP:new MathContext(9,MathContext.prototype.SCIENTIFIC,!1,d)}catch(n){this.badarg("format",6,d)}f=this.clone(this);-1==b?f.form=MathContext.prototype.PLAIN:f.ind==this.iszero?f.form=MathContext.prototype.PLAIN:(g=f.exp+f.mant.length,f.form=g>b?
c:-5>g?c:MathContext.prototype.PLAIN);if(0<=h)a:for(;;){f.form==MathContext.prototype.PLAIN?g=-f.exp:f.form==MathContext.prototype.SCIENTIFIC?g=f.mant.length-1:(g=(f.exp+f.mant.length-1)%3,0>g&&(g=3+g),g++,g=g>=f.mant.length?0:f.mant.length-g);if(g==h)break a;if(g<h){k=this.extend(f.mant,f.mant.length+h-g);f.mant=k;f.exp-=h-g;if(f.exp<this.MinExp)throw"format(): Exponent Overflow: "+f.exp;break a}g-=h;if(g>f.mant.length){f.mant=this.ZERO.mant;f.ind=this.iszero;f.exp=0;continue a}k=f.mant.length-g;
l=f.exp;f.round(k,d);if(f.exp-l==g)break a}b=f.layout();if(0<e){c=b.length;f=0;a:for(;0<c;c--,f++){if("."==b[f])break a;if("E"==b[f])break a}f>e&&this.badarg("format",1,e);if(f<e){g=Array(b.length+e-f);e-=f;k=0;for(;0<e;e--,k++)g[k]=" ";this.arraycopy(b,0,g,k,b.length);b=g}}if(0<a){e=b.length-1;f=b.length-1;a:for(;0<e;e--,f--)if("E"==b[f])break a;if(0==f){g=Array(b.length+a+2);this.arraycopy(b,0,g,0,b.length);a+=2;k=b.length;for(;0<a;a--,k++)g[k]=" ";b=g}else if(l=b.length-f-2,l>a&&this.badarg("format",
3,a),l<a){g=Array(b.length+a-l);this.arraycopy(b,0,g,0,f+2);a-=l;k=f+2;for(;0<a;a--,k++)g[k]="0";this.arraycopy(b,f+2,g,k,l);b=g}}return b.join("")}
function intValueExact(){var a,b=0,c,d=0;a=0;if(this.ind==this.iszero)return 0;a=this.mant.length-1;if(0>this.exp){a+=this.exp;if(!this.allzero(this.mant,a+1))throw"intValueExact(): Decimal part non-zero: "+this.toString();if(0>a)return 0;b=0}else{if(9<this.exp+a)throw"intValueExact(): Conversion overflow: "+this.toString();b=this.exp}c=0;var e=a+b,d=0;for(;d<=e;d++)c*=10,d<=a&&(c+=this.mant[d]);if(9==a+b&&(a=div(c,1E9),a!=this.mant[0])){if(-2147483648==c&&this.ind==this.isneg&&2==this.mant[0])return c;
throw"intValueExact(): Conversion overflow: "+this.toString();}return this.ind==this.ispos?c:-c}function movePointLeft(a){var b;b=this.clone(this);b.exp-=a;return b.finish(this.plainMC,!1)}function movePointRight(a){var b;b=this.clone(this);b.exp+=a;return b.finish(this.plainMC,!1)}function scale(){return 0<=this.exp?0:-this.exp}
function setScale(){var a;if(2==setScale.arguments.length)a=setScale.arguments[1];else if(1==setScale.arguments.length)a=this.ROUND_UNNECESSARY;else throw"setScale(): "+setScale.arguments.length+" given; expected 1 or 2";var b=setScale.arguments[0],c,d;c=c=0;c=this.scale();if(c==b&&this.form==MathContext.prototype.PLAIN)return this;d=this.clone(this);if(c<=b)c=0==c?d.exp+b:b-c,d.mant=this.extend(d.mant,d.mant.length+c),d.exp=-b;else{if(0>b)throw"setScale(): Negative scale: "+b;c=d.mant.length-(c-
b);d=d.round(c,a);d.exp!=-b&&(d.mant=this.extend(d.mant,d.mant.length+1),d.exp-=1)}d.form=MathContext.prototype.PLAIN;return d}function signum(){return this.ind}function toString(){return this.layout().join("")}
function layout(){var a,b=0,b=null,c=0,d=0;a=0;var d=null,e,b=0;a=Array(this.mant.length);c=this.mant.length;b=0;for(;0<c;c--,b++)a[b]=this.mant[b]+"";if(this.form!=MathContext.prototype.PLAIN){b="";this.ind==this.isneg&&(b+="-");c=this.exp+a.length-1;if(this.form==MathContext.prototype.SCIENTIFIC)b+=a[0],1<a.length&&(b+="."),b+=a.slice(1).join("");else if(d=c%3,0>d&&(d=3+d),c-=d,d++,d>=a.length)for(b+=a.join(""),a=d-a.length;0<a;a--)b+="0";else b+=a.slice(0,d).join(""),b=b+"."+a.slice(d).join("");
0!=c&&(0>c?(a="-",c=-c):a="+",b+="E",b+=a,b+=c);return b.split("")}if(0==this.exp){if(0<=this.ind)return a;d=Array(a.length+1);d[0]="-";this.arraycopy(a,0,d,1,a.length);return d}c=this.ind==this.isneg?1:0;e=this.exp+a.length;if(1>e){b=c+2-this.exp;d=Array(b);0!=c&&(d[0]="-");d[c]="0";d[c+1]=".";var h=-e,b=c+2;for(;0<h;h--,b++)d[b]="0";this.arraycopy(a,0,d,c+2-e,a.length);return d}if(e>a.length){d=Array(c+e);0!=c&&(d[0]="-");this.arraycopy(a,0,d,c,a.length);e-=a.length;b=c+a.length;for(;0<e;e--,b++)d[b]=
"0";return d}b=c+1+a.length;d=Array(b);0!=c&&(d[0]="-");this.arraycopy(a,0,d,c,e);d[c+e]=".";this.arraycopy(a,e,d,c+e+1,a.length-e);return d}function intcheck(a,b){var c;c=this.intValueExact();if(c<a||c>b)throw"intcheck(): Conversion overflow: "+c;return c}
function dodivide(a,b,c,d){var e,h,f,g,k,l,n,m,q,r=0,p=0,s=0;h=h=p=p=p=0;e=null;e=e=0;e=null;c.lostDigits&&this.checkdigits(b,c.digits);e=this;if(0==b.ind)throw"dodivide(): Divide by 0";if(0==e.ind)return c.form!=MathContext.prototype.PLAIN?this.ZERO:-1==d?e:e.setScale(d);h=c.digits;0<h?(e.mant.length>h&&(e=this.clone(e).round(c)),b.mant.length>h&&(b=this.clone(b).round(c))):(-1==d&&(d=e.scale()),h=e.mant.length,d!=-e.exp&&(h=h+d+e.exp),h=h-(b.mant.length-1)-b.exp,h<e.mant.length&&(h=e.mant.length),
h<b.mant.length&&(h=b.mant.length));f=e.exp-b.exp+e.mant.length-b.mant.length;if(0>f&&"D"!=a)return"I"==a?this.ZERO:this.clone(e).finish(c,!1);g=new BigDecimal;g.ind=e.ind*b.ind;g.exp=f;g.mant=this.createArrayWithZeros(h+1);k=h+h+1;f=this.extend(e.mant,k);l=k;n=b.mant;m=k;q=10*n[0]+1;1<n.length&&(q+=n[1]);k=0;a:for(;;){r=0;b:for(;;){if(l<m)break b;if(l==m){c:do{var t=l,p=0;for(;0<t;t--,p++){s=p<n.length?n[p]:0;if(f[p]<s)break b;if(f[p]>s)break c}r++;g.mant[k]=r;k++;f[0]=0;break a}while(0);p=f[0]}else p=
10*f[0],1<l&&(p+=f[1]);p=div(10*p,q);0==p&&(p=1);r+=p;f=this.byteaddsub(f,l,n,m,-p,!0);if(0!=f[0])continue b;s=l-2;p=0;c:for(;p<=s;p++){if(0!=f[p])break c;l--}if(0==p)continue b;this.arraycopy(f,p,f,0,l)}if(0!=k||0!=r){g.mant[k]=r;k++;if(k==h+1)break a;if(0==f[0])break a}if(0<=d&&-g.exp>d)break a;if("D"!=a&&0>=g.exp)break a;g.exp-=1;m--}0==k&&(k=1);if("I"==a||"R"==a){if(k+g.exp>h)throw"dodivide(): Integer overflow";if("R"==a){do{if(0==g.mant[0])return this.clone(e).finish(c,!1);if(0==f[0])return this.ZERO;
g.ind=e.ind;h=h+h+1-e.mant.length;g.exp=g.exp-h+e.exp;h=l;p=h-1;b:for(;1<=p&&g.exp<e.exp&&g.exp<b.exp;p--){if(0!=f[p])break b;h--;g.exp+=1}h<f.length&&(e=Array(h),this.arraycopy(f,0,e,0,h),f=e);g.mant=f;return g.finish(c,!1)}while(0)}}else 0!=f[0]&&(e=g.mant[k-1],0==e%5&&(g.mant[k-1]=e+1));if(0<=d)return k!=g.mant.length&&(g.exp-=g.mant.length-k),e=g.mant.length-(-g.exp-d),g.round(e,c.roundingMode),g.exp!=-d&&(g.mant=this.extend(g.mant,g.mant.length+1),g.exp-=1),g.finish(c,!0);if(k==g.mant.length)g.round(c);
else{if(0==g.mant[0])return this.ZERO;e=Array(k);this.arraycopy(g.mant,0,e,0,k);g.mant=e}return g.finish(c,!0)}function bad(a,b){throw a+"Not a number: "+b;}function badarg(a,b,c){throw"Bad argument "+b+" to "+a+": "+c;}function extend(a,b){var c;if(a.length==b)return a;c=createArrayWithZeros(b);this.arraycopy(a,0,c,0,a.length);return c}
function byteaddsub(a,b,c,d,e,h){var f,g,k,l,n,m,q=0;f=m=0;f=a.length;g=c.length;b-=1;l=k=d-1;l<b&&(l=b);d=null;h&&l+1==f&&(d=a);null==d&&(d=this.createArrayWithZeros(l+1));n=!1;1==e?n=!0:-1==e&&(n=!0);m=0;q=l;a:for(;0<=q;q--){0<=b&&(b<f&&(m+=a[b]),b--);0<=k&&(k<g&&(m=n?0<e?m+c[k]:m-c[k]:m+c[k]*e),k--);if(10>m&&0<=m){do{d[q]=m;m=0;continue a}while(0)}m+=90;d[q]=this.bytedig[m];m=this.bytecar[m]}if(0==m)return d;c=null;h&&l+2==a.length&&(c=a);null==c&&(c=Array(l+2));c[0]=m;a=l+1;f=0;for(;0<a;a--,f++)c[f+
1]=d[f];return c}function diginit(){var a,b=0,c=0;a=Array(190);b=0;a:for(;189>=b;b++){c=b-90;if(0<=c){a[b]=c%10;BigDecimal.prototype.bytecar[b]=div(c,10);continue a}c+=100;a[b]=c%10;BigDecimal.prototype.bytecar[b]=div(c,10)-10}return a}function clone(a){var b;b=new BigDecimal;b.ind=a.ind;b.exp=a.exp;b.form=a.form;b.mant=a.mant;return b}
function checkdigits(a,b){if(0!=b){if(this.mant.length>b&&!this.allzero(this.mant,b))throw"Too many digits: "+this.toString();if(null!=a&&a.mant.length>b&&!this.allzero(a.mant,b))throw"Too many digits: "+a.toString();}}
function round(){var a,b;if(2==round.arguments.length)a=round.arguments[0],b=round.arguments[1];else if(1==round.arguments.length)b=round.arguments[0],a=b.digits,b=b.roundingMode;else throw"round(): "+round.arguments.length+" arguments given; expected 1 or 2";var c,d,e=!1,h=0,f;c=null;c=this.mant.length-a;if(0>=c)return this;this.exp+=c;c=this.ind;d=this.mant;0<a?(this.mant=Array(a),this.arraycopy(d,0,this.mant,0,a),e=!0,h=d[a]):(this.mant=this.ZERO.mant,this.ind=this.iszero,e=!1,h=0==a?d[0]:0);f=
0;if(b==this.ROUND_HALF_UP)5<=h&&(f=c);else if(b==this.ROUND_UNNECESSARY){if(!this.allzero(d,a))throw"round(): Rounding necessary";}else if(b==this.ROUND_HALF_DOWN)5<h?f=c:5==h&&(this.allzero(d,a+1)||(f=c));else if(b==this.ROUND_HALF_EVEN)5<h?f=c:5==h&&(this.allzero(d,a+1)?1==this.mant[this.mant.length-1]%2&&(f=c):f=c);else if(b!=this.ROUND_DOWN)if(b==this.ROUND_UP)this.allzero(d,a)||(f=c);else if(b==this.ROUND_CEILING)0<c&&(this.allzero(d,a)||(f=c));else if(b==this.ROUND_FLOOR)0>c&&(this.allzero(d,
a)||(f=c));else throw"round(): Bad round value: "+b;0!=f&&(this.ind==this.iszero?(this.mant=this.ONE.mant,this.ind=f):(this.ind==this.isneg&&(f=-f),c=this.byteaddsub(this.mant,this.mant.length,this.ONE.mant,1,f,e),c.length>this.mant.length?(this.exp++,this.arraycopy(c,0,this.mant,0,this.mant.length)):this.mant=c));if(this.exp>this.MaxExp)throw"round(): Exponent Overflow: "+this.exp;return this}
function allzero(a,b){var c=0;0>b&&(b=0);var d=a.length-1,c=b;for(;c<=d;c++)if(0!=a[c])return!1;return!0}
function finish(a,b){var c=0,d=0,e=null,c=d=0;0!=a.digits&&this.mant.length>a.digits&&this.round(a);if(b&&a.form!=MathContext.prototype.PLAIN){c=this.mant.length;d=c-1;a:for(;1<=d;d--){if(0!=this.mant[d])break a;c--;this.exp++}c<this.mant.length&&(e=Array(c),this.arraycopy(this.mant,0,e,0,c),this.mant=e)}this.form=MathContext.prototype.PLAIN;c=this.mant.length;d=0;for(;0<c;c--,d++)if(0!=this.mant[d]){0<d&&(e=Array(this.mant.length-d),this.arraycopy(this.mant,d,e,0,this.mant.length-d),this.mant=e);
d=this.exp+this.mant.length;if(0<d){if(d>a.digits&&0!=a.digits&&(this.form=a.form),d-1<=this.MaxExp)return this}else-5>d&&(this.form=a.form);d--;if(d<this.MinExp||d>this.MaxExp){b:do{if(this.form==MathContext.prototype.ENGINEERING&&(c=d%3,0>c&&(c=3+c),d-=c,d>=this.MinExp&&d<=this.MaxExp))break b;throw"finish(): Exponent Overflow: "+d;}while(0)}return this}this.ind=this.iszero;if(a.form!=MathContext.prototype.PLAIN)this.exp=0;else if(0<this.exp)this.exp=0;else if(this.exp<this.MinExp)throw"finish(): Exponent Overflow: "+
this.exp;this.mant=this.ZERO.mant;return this}function isGreaterThan(a){return 0<this.compareTo(a)}function isLessThan(a){return 0>this.compareTo(a)}function isGreaterThanOrEqualTo(a){return 0<=this.compareTo(a)}function isLessThanOrEqualTo(a){return 0>=this.compareTo(a)}function isPositive(){return 0<this.compareTo(BigDecimal.prototype.ZERO)}function isNegative(){return 0>this.compareTo(BigDecimal.prototype.ZERO)}function isZero(){return this.equals(BigDecimal.prototype.ZERO)};
