#include using namespace std; bool check1(const string &s) { return count(s.begin(), s.end(), '3') > 0; } bool check2(const string &s) { int x = 0; for(char c : s) x = (x + c - '0'); return x % 3 == 0; } int main() { string s; cin >> s; while(check1(s) or check2(s)) { if(check1(s)) { for(int i = 0; i < s.size(); i ++) { if(s[i] == '3') { s[i] = '2'; for(int j = i + 1; j < s.size(); j ++) s[j] = '9'; break; } } }else{ for(int i = s.size() - 1; i >= 0; i --) { if(s[i] > '0') { s[i] --; break; } s[i] = '9'; } } } cout << s << "\n"; return 0; }