/* -*- coding: utf-8 -*- * * 3658.cc: No.3658 Darumaka Number 2 - yukicoder */ #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; /* typedef */ /* global variables */ char s[MAX_N + 4], t[MAX_N + 4]; /* subroutines */ /* main */ int main() { scanf("%s", s); int n = strlen(s); bool lf = false; int ofst = 0; for (int i = 0; i < n; i++) { if (lf) t[i] = '5'; else { if (s[i] < '4') { lf = true; t[i] = '5'; int co = 1; for (int j = i - 1; co > 0 && j >= 0; j--) { if (t[j] == '5') t[j] = '4', co = 0; else t[j] = '5'; } if (co > 0) ofst = 1; } else if (s[i] == '4' || s[i] == '5') { t[i] = s[i]; } else { lf = true; t[i] = '5'; } } } t[n] = '\0'; puts(t + ofst); return 0; }