#include #include #include using namespace std; string maxs(string s) { for(auto& x: s) if(x == '8') x = 'B'; for(auto& x: s) if(x == '0') x = 'D'; return s; } string mins(string s) { for(auto& x: s) if(x == 'B') x = '8'; for(auto& x: s) if(x == 'D') x = '0'; if(s[0] == '0' && s.size() > 1) s[0] = 'D'; return s; } int64_t parse(string s) { int64_t res = 0; for(auto& x: s) { res *= 16; if(x >= '0' && x <= '9') res += (x - '0'); else if(x >= 'A' && x <= 'F') res += (x - 'A' + 10); else assert(false); } return res; } string gen(int64_t x) { if(x == 0) return "0"; string res; while(x) { int t = x % 16; if(t < 10) res += (char)(t + '0'); else res += (char)(t - 10 + 'A'); x /= 16; } reverse(res.begin(), res.end()); return res; } int main() { int q; cin >> q; int64_t lhs = 0, rhs = 0; while(q--) { string s; cin >> s; lhs += parse(mins(s)); rhs += parse(maxs(s)); } cout << gen(rhs) << " " << gen(lhs) << "\n"; }