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 MAXN = 100010;
const int MAXM = 300010;
const int INF = 0x7fffffff;
const int MOD = 1e9 + 7;
const double eps = 1e-6;
const long double pi = acos(-1.0);
char ans[100010], st[100010];
void fuck(int i, int j) {
  while (ans[j]) {
    swap(ans[j], ans[i]);
    i++;
    j++;
  }
}
int main() {
  scanf("%s", st);
  int n = strlen(st);
  if (n & 1 == 1) {
    for (int i = 0; i < n / 2 + 1; ++i) {
      printf("4");
    }
    for (int i = 0; i < n / 2 + 1; ++i) {
      printf("7");
    }
    printf("\n");
    return 0;
  }
  int m = n / 2;
  for (int i = 0; i < m; ++i) {
    ans[i] = '7';
  }
  for (int i = 0; i < m; ++i) {
    ans[m + i] = '4';
  }
  bool t = 0;
  for (int i = 0; i < n; ++i) {
    if (ans[i] > st[i]) break;
    if (ans[i] < st[i]) {
      t = 1;
      break;
    }
  }
  if (t) {
    for (int j = 0; j < n / 2 + 1; ++j) {
      printf("4");
    }
    for (int j = 0; j < n / 2 + 1; ++j) {
      printf("7");
    }
    printf("\n");
    return 0;
  }
  int nxt = 0;
  for (int i = 0; i < n; ++i) {
    if (ans[i] > st[i]) {
      nxt = i;
      break;
    }
  }
  ans[n] = 0;
  st[n] = -1;
  while (nxt < n) {
    for (int i = nxt; i <= n; ++i) {
      if (ans[i] > st[i]) {
        nxt = i;
        break;
      }
    }
    if (nxt == n || ans[nxt] == '4') break;
    if (st[nxt] < '4') {
      fuck(nxt, m);
      break;
    }
    if (st[nxt] == '4') {
      swap(ans[nxt], ans[m]);
      int i;
      for (i = nxt; i <= n; ++i) {
        if (ans[i] != st[i]) break;
      }
      if (ans[i] > st[i]) {
        m++;
        nxt = i;
        continue;
      }
      swap(ans[nxt], ans[m]);
      fuck(nxt + 1, m);
      break;
    }
    if (st[nxt] < '7') {
      fuck(nxt + 1, m);
      break;
    }
  }
  printf("%s\n", ans);
}