#include <iostream>
#include <cmath>
#include <string.h>
using namespace std;
#define maxlen 10000
class HI
{
public:
friend ostream& operator<<(ostream &cout,const HI& x);
public:
HI() {(*this)=0;}
HI(int inte) {(*this)=inte;}
HI(const char* str) {(*this)=str;}
HI operator=(int inte);
HI operator=(const char* str);
HI operator+(const HI&b);
HI operator-(const HI&b);
HI operator*(const HI&b);
HI operator/(const HI&b);
HI operator%(const HI&b);
int CP(const HI&b);
int len;
int s[maxlen];
};
ostream& operator<<(ostream& cout,const HI& x){
for(int i=x.len;i>=1;i--)
cout<<x.s[i];
return cout;
}
HI HI::operator=(int inte){
if(inte==0){
len=1;
s[len]=0;
return (*this);
}
else{
for(len=0;inte>0;){
s[++len]=inte%10;
inte/=10;
}
return *this;
}
}
HI HI::operator=(const char* str){
len=strlen(str);
for(int i=1;i<=len;i++){
s[i]=str[len-i]-'0';
}
return (*this);
}
HI HI::operator*(const HI&x){
HI temp;
temp.len=len+x.len;
int i,j;
for(i=1;i<=temp.len;i++)
temp.s[i]=0;
for(i=1;i<=x.len;i++)
for(j=1;j<=len;j++){
temp.s[i+j-1]+=x.s[i]*s[j];
}
for(i=1;i<temp.len;i++){
temp.s[i+1]+=temp.s[i]/10;
temp.s[i]%=10;
}
while(i>1&&!temp.s[i]){
i--;
}
temp.len=i;
return temp;
}
HI HI::operator+(const HI&x){
HI temp;
int i=1;
for(i=1;i<=x.len;i++)
temp.s[i] += x.s[i];
for(i=1;i<=len;i++)
temp.s[i] += s[i];
for(i=1;i<=len-1||i<=x.len-1;i++){
temp.s[i+1]+=temp.s[i]/10;
temp.s[i]%=10;
temp.len=i+1;
}
if(temp.s[i]>=10){
temp.len++;
temp.s[i+1]=1;
temp.s[i]/=10;
}
return temp;
}
int HI::CP(const HI&x){
if(len>x.len)
return 1;
else if(len<x.len)
return -1;
else{
for(int i=len;i>=1;i++){
if(s[i]==x.s[i])
continue;
else
return s[i]>x.s[i]? 1:-1;
}
return 0;
}
}
HI HI::operator-(const HI&x){
int i,j=0;
HI temp(0);
for(i=1;i<=len;i++){
temp.s[i]=s[i]-j;
if(i<=x.len)
temp.s[i]-=x.s[i];
if(temp.s[i]<0){
temp.s[i]+=10;
j=1;
}
else
j=0;
}
temp.len=len;
while(temp.len>1&&!temp.s[temp.len]){
temp.len--;
}
return temp;
}
HI HI::operator/(const HI&x){
int i,j;
HI temp(0),c(0);
for(i=len;i>0;i--){
if(!(temp.len==1&&temp.s[1]==0)){
for(j=temp.len;j>0;j--){
temp.s[j+1]=temp.s[j];
}
temp.len++;
}
temp.s[1]=s[i];
c.s[i]=0;
while((j=temp.CP(x))>=0){
c.s[i]++;
temp=temp-x;
if(j==0)
break;
}
}
c.len=len;
while((c.len>1)&&!(c.s[c.len])){
c.len--;
}
return c;
}
HI HI::operator%(const HI&x){
HI c(0),b(0);
c=(*this)/x;
b=(*this)-c*x;
return b;
}
#include <iostream>
#include <cmath>
#include <string.h>
using namespace std;
#include "HugeInteger.cpp"
class HPF{
public:
friend ostream& operator<<(ostream &cout,const HPF&x);
public:
HPF(){(*this)=0;};
HPF(int x){(*this)=x;}
HPF(char *s){(*this)=s;}
HPF operator=(int x);
HPF operator=(char *s);
HPF operator+(HPF& x);
HPF operator-(HPF& x);
HPF operator*(HPF& x);
HPF operator/(HPF& x);
int fp,sign;
HI num;
};
ostream& operator<<(ostream &cout,const HPF&x){
if(x.sign<0) cout<<'-';
int i;
int gap=x.fp-x.num.len;
int k=0;
if(gap>=0){
cout<<"0.";
for(k=0;k<gap;k++) cout<<0;
cout<<x.num;
}
for(i=x.num.len;i>x.fp;i--) cout<<x.num.s[i];
cout<<'.';
for(i=x.fp;i>0;i--) cout<<x.num.s[i];
cout<<endl;
return cout;
}
HPF HPF::operator=(int x){
fp=0;
if(x<0){
sign=-1;
num=-x;
}
else{
sign =1;
num=x;
}
return (*this);
}
HPF HPF::operator=(char *s){
if(s[0]=='-') sign =-1;
else sign=1;
fp=0;
int i,j,l;
l=strlen(s);
for(i=1;i<l;i++){
if(s[i]=='.') fp=l-1-i;
}
int k=1;
for(j=l-1;j>=0;j--){
if(s[j]=='-'){
continue;
}
if(s[j]!='.'){
num.s[k++]=s[j]-'0';
num.len++;
}
}
while(num.len>1&&!(num.s[num.len])) num.len--;
return (*this);
}
void left(HPF& x,int n){
x.fp+=n;
x.num.len+=n;
int i=0;
for(i=x.num.len;i>n;i--){
x.num.s[i]=x.num.s[i-n];
}
while(i>0){
x.num.s[i]=0;
i--;
}
}
void right(HPF& x,int n){
x.fp-=n;
x.num.len-=n;
int i;
for(i=1;i<=x.num.len;i++){
x.num.s[i]=x.num.s[i+n];
}
}
HPF HPF::operator+(HPF& x){
HPF temp;
if(fp>x.fp){
left(x,fp-x.fp);
}
else{
left((*this),x.fp-fp);
}
if(sign==x.sign){
temp.sign=sign;
temp.num=x.num+num;
temp.fp=fp;
}
else{
temp.fp=fp;
if(num.CP(x.num)>0){
temp.sign=sign;
temp.num=num-x.num;
}
else if(num.CP(x.num)<0){
temp.sign=x.sign;
temp.num=x.num-num;
}
else{
temp.fp=0;
temp.num=0;
temp.sign=1;
}
}
return temp;
}
HPF HPF::operator-(HPF& x){
x.sign=-x.sign;
HPF temp =(*this)+x;
x.sign*=-1;
return temp;
}
HPF HPF::operator*(HPF& x){
HPF temp;
temp.sign=x.sign*sign;
temp.fp=fp+x.fp;
temp.num=num*x.num;
if(temp.num.CP(0)==0){
temp.fp=0;
temp.num=0;
temp.sign=1;
}
return temp;
}
HPF HPF::operator/(HPF& x){
HPF temp;
HPF t=(*this);
temp.sign=x.sign*sign;
left(t,100+x.fp);
temp.num=t.num/x.num;
temp.fp=100;
return temp;
}