#include<cstdio> #include<string> using namespace std; string add; string sub; string mul; void ADD(string s1, string s2) { int len1 = s1.size(); int len2 = s2.size(); int carry = 0; if (len1 == len2) { add.insert(0, len1, '0'); for (int i = len1 - 1 ; i >= 0 ; --i) { int a = s1[i] - '0'; int b = s2[i] - '0'; if ( (a + b + carry) > 9 ) { add[i] = (a + b - 10 + carry) + '0'; carry = 1; } else if ((a + b + carry) <= 9 && (a + b + carry) >= 0) { add[i] = (a + b + carry) + '0'; carry = 0; } if (i == 0 && (a + b + carry) > 9 ) { add[i] = (a + b - 10 + carry) + '0'; add.insert(0,1,'1'); } } } else if (len1 > len2) { int c = len1 - len2; s2.insert(len2, c, '0'); for (int i = len1 - 1 ; i >= c ; --i) { s2[i] = s2[i - c]; } for (int i = 0 ; i < c ; ++i ) { s2[i] = '0'; } ADD(s1, s2); } else if (len1 < len2) { int c = len2 - len1; s1.insert(len1, c, '0'); for (int i = len2 - 1 ; i >= c ; --i) { s1[i] = s1[i - c]; } for (int i = 0 ; i < c ; ++i ) { s1[i] = '0'; } ADD(s1, s2); } } void SUB(string s1, string s2) { bool ISbig; int len1 = s1.size(); int len2 = s2.size(); int jie = 0; if (len1 == len2) { sub.insert(0, len1, '0'); int len3 = sub.size(); for (int i = 0 ; i < len3 ; ++i) { if ((s1[i] - '0') < (s2[i] - '0')) { ISbig = false; break; } else if ((s1[i] - '0') > (s2[i] - '0')) { ISbig = true; break; } else if ((s1[i] - '0') == (s2[i] - '0')) { continue; } } if (ISbig == true) { for (int i = len1 - 1 ; i >= 0 ; --i) { int a = s1[i] - '0' - jie; int b = s2[i] - '0'; if ((a - b) >= 0 ) { sub[i] = (a - b) + '0'; jie = 0 ; } else if ((a - b) < 0) { sub[i] = (a + 10 - b) + '0'; jie = 1; } } } else { sub.clear(); SUB(s2, s1); sub.insert(0, 1, '-'); } } else if (len1 > len2) { int c = len1 - len2; s2.insert(len2, c, '0'); for (int i = len1 - 1 ; i >= c ; --i) { s2[i] = s2[i - c]; } for (int i = 0 ; i < c ; ++i ) { s2[i] = '0'; } SUB(s1, s2); } else if (len1 < len2) { SUB(s2, s1); sub.insert(0, 1, '-'); } } void MUL(string s1, string s2) { int a[405], b[405]; for (int i = 0 ; i < 405; ++i) { a[i] = 0; b[i] = 0; } int len1 = s1.size(); int len2 = s2.size(); for (int i = 0 ; i < len1 ; ++i) { a[i] = s1[len1 - 1 - i] - '0'; } for (int i = 0 ; i < len2 ; ++i) { b[i] = s2[len2 - 1 - i] - '0'; } int ans[810]; for (int i = 0 ; i < 805 ; ++i) { ans[i] = 0; } for (int i = 0 ; i < len1 ; ++i) { for (int j = 0 ; j < len2; ++j) { ans[i + j] += a[i] * b[j]; } } int len; for (int i = 0 ; i < len1 + len2 ; ++i) { if (ans[i] >= 10) { ans[i + 1] += ans[i] / 10; ans[i] = ans[i] % 10; } } for (int i = 804; i >= 0; i--) { if (ans[i] != 0) { len = i; break; } } for (int i = len ; i >= 0; i--) { mul += ('0' + ans[i]); } } int main() { char a[100]; char b[100]; fgets(a, 100, stdin); fgets(b, 100, stdin); string s1 = a; s1.pop_back(); string s2 = b; s2.pop_back(); ADD(s1, s2); SUB(s1, s2); int len = sub.size(); if (sub[0] == '0') { for (int i = 0; i < len; ++i) { sub[i] = sub[i + 1]; } sub.erase(len, 1); } if (sub[0] == '-' && sub[1] == '0') { for (int i = 1; i <= len; ++i) { sub[i] = sub[i + 1]; } sub.erase(len, 1); } MUL(s1, s2); printf("%s\n", add.c_str()); printf("%s\n", sub.c_str()); printf("%s\n", mul.c_str()); }