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;
int mod = 1e8 + 7;
int main() {
  char c[100005];
  while (scanf("%s", c + 1) != EOF) {
    char ans[100005];
    memset(ans, 0, sizeof(ans));
    for (int i = 1; c[i] != 0; i++) {
      if (c[i] > '7') {
        for (int j = i - 1; j >= 0; j--) {
          if (ans[j] == '4') {
            ans[j] = '7';
            break;
          } else {
            ans[j] = '4';
          }
        }
        for (int j = i; c[j] != 0; j++) ans[j] = '4';
        break;
      } else if (c[i] > '4') {
        ans[i] = '7';
        if (c[i] != '7') {
          for (int j = i + 1; c[j] != 0; j++) ans[j] = '4';
          break;
        }
      } else {
        ans[i] = '4';
        if (c[i] != '4') {
          for (int j = i + 1; c[j] != 0; j++) ans[j] = '4';
          break;
        }
      }
    }
    int f = 0, s = 0;
    for (int i = 0; ans[i] != 0 || i == 0; i++) {
      if (ans[i] == '4')
        f++;
      else if (ans[i] == '7')
        s++;
    }
    if ((f + s) % 2 != 0) {
      int num = (f + s) / 2 + 1;
      for (int i = 0; i < num; i++) printf("4");
      for (int i = 0; i < num; i++) printf("7");
      continue;
    } else if (f < s) {
      int num = (f + s) / 2 + 1;
      int ok = 0;
      for (int i = strlen(ans + 1); i >= 0; i--) {
        if (ans[i] == '7') {
          f++;
          s--;
        } else if (ans[i] == '4' && f - s >= 2) {
          ans[i] = '7';
          f--;
          s++;
          for (int j = i + 1; ans[j] != 0; j++) ans[j] = '4';
          for (int j = strlen(ans + 1); f != s; j--) {
            ans[j] = '7';
            f--;
            s++;
          }
          ok = 1;
          break;
        }
      }
      if (!ok) {
        for (int i = 0; i < num; i++) printf("4");
        for (int i = 0; i < num; i++) printf("7");
        continue;
      }
    }
    {
      for (int i = strlen(ans + 1); f > s; i--)
        if (ans[i] == '4') {
          ans[i] = '7';
          f--;
          s++;
        }
      if (ans[0])
        printf("%s", ans);
      else
        printf("%s", ans + 1);
    }
  }
}