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;
char s[1000010];
string ans = "";
bool cal(int &a, int &b) {
  int x = -1;
  int y = -1;
  for (int j = ans.size() - 1; j >= 0; j--) {
    if (ans[j] == '7') {
      x = j;
      break;
    }
  }
  if (x == -1) {
    return false;
  }
  for (int j = x - 1; j >= 0; j--) {
    if (ans[j] == '4') {
      y = j;
      break;
    }
  }
  if (y == -1) {
    return false;
  }
  while (ans.size() - 1 != y) {
    if (ans[ans.size() - 1] == '4') {
      a++;
    } else if (ans[ans.size() - 1] == '7') {
      b++;
    }
    ans.pop_back();
  }
  a++;
  ans.pop_back();
  b--;
  ans += '7';
  while (a > 0) {
    a--;
    ans += '4';
  }
  while (b > 0) {
    b--;
    ans += '7';
  }
  return true;
}
int main() {
  scanf("%s", s);
  int n = strlen(s);
  if (n % 2 == 1) {
    n++;
    for (int i = 0; i < n / 2; i++) {
      printf("4");
    }
    for (int i = 0; i < n / 2; i++) {
      printf("7");
    }
    puts("");
  } else {
    int a = n / 2;
    int b = n / 2;
    bool ok = true;
    for (int i = 0; i < n && ok && (a + b) != 0; i++) {
      if (s[i] < '4') {
        while (a > 0) {
          a--;
          ans += '4';
        }
        while (b > 0) {
          b--;
          ans += '7';
        }
        break;
      } else if (s[i] == '4') {
        if (a != 0) {
          a--;
          ans += '4';
          continue;
        }
        while (b > 0) {
          b--;
          ans += '7';
        }
        break;
      } else if (s[i] < '7') {
        if (b == 0) {
          if (!cal(a, b)) {
            ok = false;
          }
          continue;
        }
        b--;
        ans += '7';
        while (a > 0) {
          a--;
          ans += '4';
        }
        while (b > 0) {
          b--;
          ans += '7';
        }
        break;
      } else if (s[i] == '7') {
        if (b == 0) {
          if (!cal(a, b)) {
            ok = false;
          }
          continue;
        }
        b--;
        ans += '7';
      } else {
        if (b == 0) {
          if (!cal(a, b)) {
            ok = false;
          }
          continue;
        }
        while (ans.size() > 0 && ans[ans.size() - 1] != '4') {
          b++;
          ans.pop_back();
        }
        if (ans.size() == 0) {
          ok = false;
          continue;
        }
        a++;
        ans.pop_back();
        b--;
        ans += '7';
        while (a > 0) {
          a--;
          ans += '4';
        }
        while (b > 0) {
          b--;
          ans += '7';
        }
      }
    }
    if (ok) {
      printf("%s\n", ans.c_str());
    } else {
      n += 2;
      for (int i = 0; i < n / 2; i++) {
        printf("4");
      }
      for (int i = 0; i < n / 2; i++) {
        printf("7");
      }
      puts("");
    }
  }
  return 0;
}