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;
const int MAX = 100001;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u,
      v, w, x, y, z;
  string ss, st;
  cin >> ss;
  st = ss;
  stringstream qq;
  qq << st;
  qq >> b;
  long long int four = 0, seven = 0;
  bool ans = false;
  for (i = 0; i < ss.size(); i++) {
    if (ss[i] == '4')
      four++;
    else if (ss[i] == '7')
      seven++;
    else {
      ans = true;
      break;
    }
  }
  if (four == seven && four > 0 && seven > 0 && !ans)
    cout << ss << endl;
  else if (ans || four != seven) {
    if (ss.size() % 2 != 0) {
      d = ss.size() + 1;
      e = d / 2;
      for (i = 1; i <= e; i++) cout << "4";
      for (i = 1; i <= e; i++) cout << "7";
      cout << endl;
    } else if (ss[0] > '7') {
      d = ss.size();
      e = (d / 2) + 1;
      for (i = 1; i <= e; i++) cout << "4";
      for (i = 1; i <= e; i++) cout << "7";
      cout << endl;
    } else if ((four == ss.size() || seven == ss.size())) {
      d = ss.size() + 2;
      e = d / 2;
      for (i = 1; i <= e; i++) cout << "4";
      for (i = 1; i <= e; i++) cout << "7";
      cout << endl;
    } else {
      four = seven = 0;
      for (i = 0; i < ss.size(); i++) {
        if (ss[i] < '4')
          ss[i] = '4';
        else if (ss[i] > '4')
          ss[i] = '7';
        if (ss[i] == '4')
          four++;
        else
          seven++;
      }
      d = ss.size() / 2;
      if (four > seven) {
        e = four - d;
        c = 0;
        for (i = ss.size() - 1; i >= 0; i--) {
          if (ss[i] == '4') {
            ss[i] = '7';
            c++;
            if (c == e) break;
          }
        }
      } else if (seven > four) {
        e = seven - d;
        c = 0;
        for (i = ss.size() - 1; i >= 0; i--) {
          if (ss[i] == '7') {
            ss[i] = '4';
            c++;
            if (e == c) break;
          }
        }
      }
      stringstream pp;
      pp << ss;
      pp >> d;
      if (d > b) {
        a = d;
        a--;
        t = 0;
        for (i = 1; i <= MAX; i++) {
          n = a;
          four = seven = 0;
          if (n > 0) {
            bool ans2 = false;
            while (n) {
              e = n % 10;
              n /= 10;
              if (e == 4)
                four++;
              else if (e == 7)
                seven++;
              else {
                ans2 = true;
                break;
              }
            }
            if (four == seven && !ans2 && four > 0 && seven > 0 && a > b) {
              d = a;
            } else if (a < b) {
              t = 1;
            }
          } else
            break;
          if (t == 1) break;
          a--;
        }
        cout << d << endl;
        return 0;
      } else if (d < b) {
        for (i = d + 1;; i++) {
          four = seven = 0;
          a = i;
          bool ans3 = false;
          while (a) {
            e = a % 10;
            a /= 10;
            if (e == 4)
              four++;
            else if (e == 7)
              seven++;
            else {
              ans3 = true;
              break;
            }
          }
          if (four == seven && !ans3 && four > 0 && seven > 0) {
            cout << i << endl;
            return 0;
          }
        }
      }
    }
  }
  return 0;
}