#include #include #define chmin(x,y) (x) = min((x),(y)) #define chmax(x,y) (x) = max((x),(y)) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define vec vector #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define eb emplace_back using namespace std; using namespace atcoder; using ll = long long; using ld = long double; const ll mod = 998244353; using mint = modint998244353; const vector dx = {1,0,-1,0}, dy = {0,1,0,-1}; // using Graph = vector>>; using Graph = vector>; int main(){ // input string S; cin >> S; int N = S.size(); vector ans(N); bool can_greedy = 0; // solve rep(i,N){ if(can_greedy){ ans[i] = 5; continue; } int x = S[i] - '0'; if(x >= 5){ ans[i] = 5; if(x > 5) can_greedy = 1; } else if(x == 4){ ans[i] = 4; } else{ ans[i] = 5; int pos = i-1; while(true){ if(pos == -1){ ans[pos+1] = 0; break; } else if(ans[pos] == 4){ ans[pos] = 5; pos--; } else if(ans[pos] == 5){ ans[pos] = 4; break; } else assert(false); } can_greedy = 1; } } // output rep(i,N) if(ans[i] != 0) // 頭のゼロは出さない cout << ans[i]; cout << endl; }