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;
static const double EPS = 1e-9;
string make_least_47(int n) {
  string ret;
  for (int i = 0; i < (int)(n); i++) {
    ret += '4';
  }
  for (int i = 0; i < (int)(n); i++) {
    ret += '7';
  }
  return ret;
}
string make_least_47_2(int r4, int r7) {
  string ret;
  for (int i = 0; i < (int)(r4); i++) {
    ret += '4';
  }
  for (int i = 0; i < (int)(r7); i++) {
    ret += '7';
  }
  return ret;
}
int main(void) {
  string ns;
  cin >> ns;
  int N = ns.length();
  string ret;
  if (N & 1) {
    ret = make_least_47((N + 1) / 2);
    cout << ret << endl;
    return 0;
  }
  int c4 = 0;
  int c7 = 0;
  int last4 = -1;
  int last7 = -1;
  for (int i = 0; i < (int)(N); i++) {
    if (ns[i] == '4') {
      if (c4 == N / 2) {
        ret += make_least_47_2(N / 2 - c4, N / 2 - c7);
        break;
      }
      c4++;
      last4 = i;
      ret += ns[i];
    } else if (ns[i] == '7') {
      if (c7 == N / 2) {
        if (c4 == 0) {
          ret = make_least_47((N + 2) / 2);
        } else {
          c4 = c7 = 0;
          ret = "";
          if (last4 > last7) {
            last4 = last7;
            while (ns[last4] == '7') last4--;
          }
          for (int j = 0; j < (int)(last4); j++) {
            if (ns[j] == '4')
              c4++;
            else
              c7++;
            ret += ns[j];
          }
          ret += '7';
          c7++;
          ret += make_least_47_2(N / 2 - c4, N / 2 - c7);
        }
        break;
      }
      c7++;
      last7 = i;
      ret += ns[i];
    } else {
      if (ns[i] > '7') {
        if (c4 == 0 || (c7 == (N / 2) && last7 == (N / 2 - 1))) {
          ret = make_least_47((N + 2) / 2);
        } else {
          c4 = c7 = 0;
          ret = "";
          if (c7 == N / 2 && last4 > last7) {
            last4 = last7;
            while (ns[last4] == '7') last4--;
          }
          for (int j = 0; j < (int)(last4); j++) {
            if (ns[j] == '4')
              c4++;
            else
              c7++;
            ret += ns[j];
          }
          ret += '7';
          c7++;
          ret += make_least_47_2(N / 2 - c4, N / 2 - c7);
        }
      } else if (ns[i] < '4') {
        ret += make_least_47_2(N / 2 - c4, N / 2 - c7);
      } else {
        if (last7 == (N / 2 - 1)) {
          ret = make_least_47((N + 2) / 2);
        } else if (c7 == N / 2) {
          c4 = c7 = 0;
          ret = "";
          if (last4 > last7) {
            last4 = last7;
            while (ns[last4] == '7') last4--;
          }
          for (int j = 0; j < (int)(last4); j++) {
            if (ns[j] == '4')
              c4++;
            else
              c7++;
            ret += ns[j];
          }
          ret += '7';
          c7++;
          ret += make_least_47_2(N / 2 - c4, N / 2 - c7);
        } else {
          ret += '7';
          c7++;
          ret += make_least_47_2(N / 2 - c4, N / 2 - c7);
        }
      }
      break;
    }
  }
  cout << ret << endl;
  return 0;
}