Problem: Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.

One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.

Input

The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.

Output

Output the least super lucky number that is more than or equal to n.

Examples

Input

4500


Output

4747


Input

47


Output

47

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int d2x[] = {1, -1, 0, 0, 1, -1, 1, -1};
int d2y[] = {0, 0, 1, -1, 1, -1, -1, 1};
int d3x[] = {1, -1, 0, 0, 0, 0};
int d3y[] = {0, 0, 1, -1, 0, 0};
int d3z[] = {0, 0, 0, 0, 1, -1};
struct edge {
  int from, to, w;
  edge(int from, int to, int w) : from(from), to(to), w(w) {}
  bool operator<(const edge& e) const { return w > e.w; }
};
const double EPS = (1e-9);
string n, res;
bool m = false;
int cnt = 0;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> n;
  if (n.size() % 2 == 1) {
    for (int i = 0; i < ((int)((n).size())) / 2 + 1; i++) cout << "4";
    for (int i = 0; i < ((int)((n).size())) / 2 + 1; i++) cout << "7";
  } else {
    for (int i = 0; i < ((int)((n).size())) / 2; i++) {
      if (n[i] < '7') break;
      if (n[i] > '7') {
        m = true;
        break;
      } else if (n[i] == '7')
        ++cnt;
    }
    if (!m && cnt == ((int)((n).size())) / 2) {
      for (int i = 0; i < ((int)((n).size())) / 2; i++) {
        if (n[i + ((int)((n).size())) / 2] < '4') break;
        if (n[i + ((int)((n).size())) / 2] > '4') {
          m = true;
          break;
        }
      }
    }
    if (m) {
      for (int i = 0; i < ((int)((n).size())) / 2 + 1; i++) cout << "4";
      for (int i = 0; i < ((int)((n).size())) / 2 + 1; i++) cout << "7";
    } else {
      int sCount = ((int)((n).size())) / 2;
      int fCount = ((int)((n).size())) / 2;
      for (int i = 0; i < ((int)((n).size())); i++) {
        if (n[i] <= '4' && fCount) {
          if (n[i] < '4') {
            while (res.size() < ((int)((n).size()))) {
              if (fCount) {
                res += "4";
                --fCount;
              } else {
                res += "7";
              }
            }
            break;
          } else {
            res += "4";
            --fCount;
          }
        } else if (n[i] <= '4' && fCount == 0) {
          while (res.size() < ((int)((n).size()))) res += "7";
          break;
        } else if (n[i] > '4' && n[i] <= '7' && sCount) {
          res += "7";
          --sCount;
          if (n[i] < '7') {
            while (res.size() < ((int)((n).size()))) {
              if (fCount) {
                res += "4";
                --fCount;
              } else {
                res += "7";
              }
            }
            break;
          }
        } else if (n[i] > '4') {
          bool flag = false;
          for (int j = ((int)((res).size())) - 1; j >= 0; --j) {
            if (res[j] == '7')
              flag = true;
            else if (res[j] == '4' && sCount) {
              res[j] = '7';
              --sCount;
              ++fCount;
              for (int k = j + 1; k < i; ++k) {
                if (fCount) {
                  if (res[k] == '7') {
                    res[k] = '4';
                    ++sCount;
                    --fCount;
                  }
                } else {
                  break;
                }
              }
              break;
            } else if (res[j] == '4' && flag) {
              res[j] = '7';
              --sCount;
              ++fCount;
              for (int e = j + 1; e < i; ++e) {
                if (res[e] == '7' && fCount) {
                  --fCount;
                  res[e] = '4';
                }
              }
              break;
            } else {
              if (res[j] == '4')
                ++fCount;
              else
                ++sCount;
              res.resize(res.size() - 1);
            }
          }
          while (res.size() < ((int)((n).size()))) {
            if (fCount) {
              res += "4";
              --fCount;
            } else {
              res += "7";
            }
          }
          break;
        }
      }
      cout << res;
    }
  }
  return 0;
}