#include <iostream>
#include <string>
using namespace std;
class bigint{
public:
int num[501],size,sign;
bigint() {
memset(num,0,sizeof(num));
size=sign=0;
}
int cmp(const bigint& r) {
int i,c=(size>r.size)-(size<r.size);
if (c) return c;
for (i=size;i;i--) {
c=(num[i]>r.num[i])-(num[i]<r.num[i]);
if (c) return c;
}
return 0;
}
bigint& cul1(const bigint& r) {
int i,c;
size=max(size,r.size);
c=0;
for (i=1;i<=size+1;i++) {
num[i]+=r.num[i]+c;
if (num[i]/10) {
c=1;
num[i]%=10;
}
else c=0;
}
if (num[size+1]) size++;
return *this;
}
bigint& cul2(const bigint& r) {
int i,c;
c=min(size,r.size);
for (i=1;i<=c;i++) {
num[i]-=r.num[i];
if (num[i]<0) num[i+1]--,num[i]+=10;
}
while (!num[size]&&size) size--;
if (!size) size=1,sign=0;
return *this;
}
bigint& cul3(const bigint& r) {
bigint s;
int i,j;
if (!(sign*r.sign)) {
s.size=1;
return *this=s;
}
for (i=1;i<=size;i++) {
for (j=1;j<=r.size;j++) {
int c,k=i+j-1;
s.num[k]+=num[i]*r.num[j];
for (c=s.num[i+j-1]/10,k++;c;c/=10) s.num[k]+=c%10;
s.num[i+j-1]%=10;
}
}
s.size=size+r.size-1;
while (s.num[s.size+1]) s.size++;
s.sign=sign;
return *this=s;
}
bigint& cul4(const bigint& r) {
bigint s;
int i,j;
if (!sign||cmp(r)==-1) {
s.size=1;
return *this=s;
}
s.size=size-r.size+1;
s.sign=sign;
for (i=size;i>=r.size;i--) {
for (j=1;j<=9;j++) {
int c;
s.num[i-r.size+1]=j;
c=cmp(s*r);
if (c==-1) {
s.num[i-r.size+1]--;
break;
}
else if (!c) {
i=r.size;
break;
}
}
}
while (!s.num[s.size]) s.size--;
return *this=s;
}
bigint& operator += (bigint r) {
if (!(sign*r.sign)) return ((sign) ? *this:*this=r);
else if (sign*r.sign>0) return (*this).cul1(r);
else {
int c=cmp(r);
sign*=c;
return ((c>0) ? (*this).cul2(r):*this=r.cul2(*this));
}
}
bigint operator + (bigint r) {
return r+=*this;
}
bigint& operator -= (bigint r) {
r.sign=-r.sign;
return *this+=r;
}
bigint operator - (bigint r) {
r.sign=-r.sign;
return r+=(*this);
}
bigint& operator *= (bigint r) {
sign*=r.sign;
return (*this).cul3(r);
}
bigint operator * (bigint r) {
return r*=(*this);
}
bigint& operator /= (bigint r) {
sign*=r.sign;
return (*this).cul4(r);
}
bigint operator / (bigint r) {
bigint c=*this;
return c/=r;
}
bigint& operator %= (bigint r) {
return *this-=(*this/r)*r;
}
bigint operator % (bigint r) {
bigint c=*this;
return c%=r;
}
friend istream& operator >> (istream& is,bigint& r) {
string s;
r=bigint();
cin>>s;
r.sign=((s[0]=='-') ? -1:1);
for (int i=s.size();i;i--) {
if (isdigit(s[i-1])) {
r.size++;
r.num[r.size]=s[i-1]-'0';
}
}
if (r.size==1&&!r.num[1]) r.sign=0;
return is;
}
friend ostream& operator << (ostream& os,const bigint& r) {
string s="";
if (r.sign==-1) s+='-';
for (int i=r.size;i;i--) s+=(char) r.num[i]+'0';
cout<<s;
return os;
}
};