SRM 748 DIV II 500


class Yllion {
vector<string> getString(string input) {
vector<string> ans;
stringstream s(input);
string str;
while(s >> str) ans.push_back(str);
return ans;
}
public:
string getPower(string a, string b) {
unordered_map<string, int> s2i;
s2i["one"] = 0; s2i["ten"] = 1;
s2i["hundred"] = 2;
s2i["myriad"] = 4; s2i["myllion"] = 8;
s2i["byllion"] = 16; s2i["tryllion"] = 32;
s2i["quadryllion"] = 64; s2i["quintyllion"] = 128;
s2i["sextyllion"] = 256; s2i["septyllion"] = 512;
s2i["octyllion"] = 1024; s2i["nonyllion"] = 2048;
s2i["decyllion"] = 4096;
unordered_map<int, string> i2s;
i2s[0] = "one"; i2s[1] = "ten";
i2s[2] = "hundred";
i2s[4] = "myriad"; i2s[8] = "myllion";
i2s[16] = "byllion"; i2s[32] = "tryllion";
i2s[64] = "quadryllion"; i2s[128] = "quintyllion";
i2s[256] = "sextyllion"; i2s[512] = "septyllion";
i2s[1024] = "octyllion"; i2s[2048] = "nonyllion";
i2s[4096] = "decyllion";

auto va = getString(a), vb = getString(b);
int c = 0;
for (auto s : va) {
c += s2i[s];
}
for (auto s : vb) {
c += s2i[s];
}

vector<string> ans;
for (int i = 12; i >= 0; --i) {
int base = pow(2, i);
if (c < base) continue;
ans.push_back(i2s[base]);
if (base == 1) break;
c = c % base;
}

if (!c) ans.push_back("one");

reverse(ans.begin(), ans.end());
string ret;
for (int i = 0; i < ans.size(); ++i) {
ret += ans[i];
if (i != ans.size() - 1) ret += " ";
}

return ret;
}
}