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;
void pt(long long int n) {
  long long int d = n / 2;
  long long int t = 4;
  for (int i = 1; i <= n; ++i) {
    cout << t;
    if (i == d) t = 7;
  }
}
int main() {
  string s;
  cin >> s;
  if (s.length() % 2 == 1) {
    pt(s.length() + 1);
    return 0;
  }
  long long int n = s.length();
  long long int fo = 0, se = 0;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] != '4' && s[i] != '7') {
      if (s[i] < '4') {
        char b = '4';
        for (int j = i, k = fo; j < s.length(); ++j, ++k) {
          if (k == n / 2) b = '7';
          s[j] = b;
        }
        cout << s;
        return 0;
      } else if (s[i] < '7') {
        if (se == n / 2) {
          long long int f = 0;
          for (int j = i - 2; j >= 0; --j)
            if (s[j] == '4' && s[j + 1] == '7') {
              f = 1;
              s[j] = '7';
              long long int fo = 0;
              long long int se = 0;
              for (int k = 0; k <= j; ++k) {
                if (s[k] == '4')
                  ++fo;
                else
                  ++se;
              }
              char b = '4';
              for (int k = j + 1, l = fo; k < s.length(); ++k, ++l) {
                if (l == n / 2) b = '7';
                s[k] = b;
              }
              cout << s;
              return 0;
            }
          if (f == 0) {
            pt(s.length() + 2);
            return 0;
          }
        }
        se++;
        s[i] = '7';
        char b = '4';
        for (int j = i + 1, k = fo; j < s.length(); ++j, ++k) {
          if (k == n / 2) b = '7';
          s[j] = b;
        }
        cout << s;
        return 0;
      } else {
        if (se == n / 2) {
          long long int f = 0;
          for (int j = i - 2; j >= 0; --j)
            if (s[j] == '4' && s[j + 1] == '7') {
              f = 1;
              s[j] = '7';
              long long int fo = 0;
              long long int se = 0;
              for (int k = 0; k <= j; ++k) {
                if (s[k] == '4')
                  ++fo;
                else
                  ++se;
              }
              char b = '4';
              for (int k = j + 1, l = fo; k < s.length(); ++k, ++l) {
                if (l == n / 2) b = '7';
                s[k] = b;
              }
              cout << s;
              return 0;
            }
          if (f == 0) {
            pt(s.length() + 2);
            return 0;
          }
        }
        long long int f = 0;
        for (int j = i - 1; j >= 0; --j)
          if (s[j] == '4') {
            f = 1;
            s[j] = '7';
            long long int fo = 0;
            long long int se = 0;
            for (int k = 0; k <= j; ++k) {
              if (s[k] == '4')
                ++fo;
              else
                ++se;
            }
            char b = '4';
            for (int k = j + 1, l = fo; k < s.length(); ++k, ++l) {
              if (l == n / 2) b = '7';
              s[k] = b;
            }
            cout << s;
            return 0;
          }
        if (f == 0) {
          pt(s.length() + 2);
          return 0;
        }
      }
    } else if (s[i] == '4')
      ++fo;
    else
      ++se;
    if (fo == n / 2 + 1) {
      for (int j = i; j < s.length(); ++j) s[j] = '7';
      cout << s;
      return 0;
    } else if (se == n / 2 + 1) {
      long long int f = 0;
      for (int j = i - 2; j >= 0; --j)
        if (s[j] == '4' && s[j + 1] == '7') {
          f = 1;
          s[j] = '7';
          long long int fo = 0;
          long long int se = 0;
          for (int k = 0; k <= j; ++k) {
            if (s[k] == '4')
              ++fo;
            else
              ++se;
          }
          char b = '4';
          for (int k = j + 1, l = fo; k < s.length(); ++k, ++l) {
            if (l == n / 2) b = '7';
            s[k] = b;
          }
          cout << s;
          return 0;
        }
      if (f == 0) {
        pt(s.length() + 2);
        return 0;
      }
    }
  }
  cout << s;
}