#include #include #include #include #include #define REP(i,n) for(int i=0;i -1) { str.replace(i, old_s.size(), new_s); } return str; } int count5126(string str, string a) { int i = 0, cnt = 0; if (a == "") { return -1; } while ((i = str.find(a, i)) > -1) { ++cnt; i += a.size(); } return cnt; } vector split5126(string str, string sep) { int s = 0, p = 0; vector v; if (sep == "") { v.push_back(str); return v; } while ((p = str.find(sep, s)) > -1) { v.push_back(str.substr(s, p - s)); s = p + sep.size(); } v.push_back(str.substr(s, str.size())); return v; } string slice5126(string str, int a, int b) { int s = a < 0 ? str.size() + a : a; int e = b < 0 ? str.size() + b : b; e = b == 0 ? str.size() : e; return str.substr(s, (s > e ? s : e) - s); } string strdel(string s, int t) { string r = ""; string ts = to_string(t); int c = 0; for (auto i : s) { if (c < 3 && i == ts[c]) { ++c; } else { r += i; } } return c < 3 ? "e" : r; } LLI solve(string s, LLI n) { LLI r = n; string a; if (s.size() < 3) { return r; } for (int x = 1; x < 10; ++x) { for (int y = 0; y < 10; ++y) { a = strdel(s, (x * 100 + y * 10 + y)); if (x != y && a != "e") { r = max(r, solve(a, n + (x * 100 + y * 10 + y))); } } } return r; } int main() { LLI n; cin >> n; cout << solve(to_string(n), 0) << endl; return 0; }