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 num[100010];
int cnt[100010], four[100010], seven[100010];
int main() {
  scanf("%s", num + 1);
  int len = strlen(num + 1), dl = len;
  if (dl & 1)
    dl++;
  else {
    for (int i = 1; i <= dl; i++) {
      int digit = (i <= dl / 2 ? 7 : 4);
      if (digit < num[i] - '0') {
        dl += 2;
        break;
      } else if (digit > num[i] - '0') {
        break;
      }
    }
  }
  if (dl > len) {
    for (int i = 1; i <= dl; i++) {
      int digit = (i <= dl / 2 ? 4 : 7);
      printf("%d", digit);
    }
  } else {
    int pos = -1, digit;
    for (int i = 1; i <= dl; i++) {
      four[i] = four[i - 1];
      seven[i] = seven[i - 1];
      cnt[i] = cnt[i - 1];
      if (num[i] == '4')
        four[i]++;
      else if (num[i] == '7')
        seven[i]++;
      else
        cnt[i]++;
    }
    if (four[dl] == dl / 2 && four[dl] == seven[dl])
      puts(num + 1);
    else {
      for (int i = dl; i >= 1; i--) {
        if (num[i] < '7' && cnt[i - 1] == 0 && seven[i - 1] + 1 <= dl / 2 &&
            four[i - 1] <= dl / 2) {
          pos = i;
          digit = 7;
        }
        if (num[i] < '4' && cnt[i - 1] == 0 && seven[i - 1] <= dl / 2 &&
            four[i - 1] + 1 <= dl / 2) {
          pos = i;
          digit = 4;
        }
        if (pos != -1) break;
      }
      int a = dl / 2, b = dl / 2;
      for (int i = 1; i <= dl; i++) {
        if (i < pos) {
          putchar(num[i]);
          if (num[i] == '4')
            a--;
          else
            b--;
        } else if (i == pos) {
          printf("%d", digit);
          if (digit == 4)
            a--;
          else
            b--;
        } else {
          if (a > 0)
            printf("4"), a--;
          else
            printf("7"), b--;
        }
      }
      puts("");
    }
  }
  return 0;
}