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 N = 2e5 + 7;
const int M = 2e5 + 7;
const int inf = 1e9 + 7;
const long long base = 1e18;
const double pi = acos(-1);
const double ep = 1e-9;
string s;
int last = 0;
int ans[N];
void solve() {
  cin >> s;
  if (s.size() % 2 == 1) {
    int t = (s.size() + 1) / 2;
    for (int i = 0; i < t; i++) printf("%d", 4);
    for (int i = 0; i < t; i++) printf("%d", 7);
    return;
  }
  bool bg = false;
  for (int i = 1; i < s.size() + 1; i++) {
    if (bg) {
      ans[i] = 4;
    } else {
      int c = s[i - 1] - '0';
      if (c <= 4) {
        ans[i] = 4;
        if (c < 4) bg = true;
      } else {
        if (c <= 7) {
          ans[i] = 7;
          if (c < 7) bg = true;
        } else {
          if (ans[last] == 0)
            ans[last] = 4;
          else
            ans[last] = 7;
          bg = true;
          for (int j = last + 1; j < i + 1; j++) ans[j] = 4;
        }
      }
    }
    if (!bg && ans[i] == 4) last = i;
  }
  int cnt4 = 0, cnt7 = 0;
  for (int i = 0; i < s.size() + 1; i++)
    if (ans[i] == 4)
      cnt4++;
    else if (ans[i] == 7)
      cnt7++;
  if ((cnt4 + cnt7) % 2 == 1 || cnt4 == 0) {
    int t = (cnt4 + cnt7 + 1) / 2;
    if (cnt4 == 0) t++;
    for (int i = 0; i < t; i++) printf("%d", 4);
    for (int i = 0; i < t; i++) printf("%d", 7);
    return;
  }
  for (int i = s.size(); i >= 0; i--) {
    if (cnt7 >= cnt4) {
      break;
    }
    if (ans[i] == 4) {
      ans[i] = 7;
      cnt7++;
      cnt4--;
    }
  }
  if (cnt4 < cnt7) {
    int j = -1;
    int dem = 0;
    for (int i = s.size(); i > -1; i--) {
      if (ans[i] == 7)
        dem++;
      else {
        if (ans[i] == 4 && cnt4 + dem - 1 >= cnt7 - dem + 1) {
          ans[i] = 7;
          j = i;
          cnt4--;
          cnt7++;
          break;
        }
      }
    }
    if (j == -1) {
      int t = (cnt4 + cnt7 + 2) / 2;
      for (int i = 0; i < t; i++) cout << 4;
      for (int i = 0; i < t; i++) cout << 7;
      return;
    }
    for (int i = j + 1; i < s.size() + 1; i++) {
      if (cnt4 == cnt7) break;
      if (ans[i] == 7) {
        ans[i] = 4;
        cnt4++;
        cnt7--;
      }
    }
  }
  for (int i = 0; i <= s.size(); i++)
    if (ans[i] != 0) printf("%d", ans[i]);
}
int main() { solve(); }