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[1000010];
int dp[1000010];
int num4[1000010];
int num7[1000010];
int ps4 = 0;
bool is = 1;
int cao = 0;
int hehe = 0;
int main() {
  gets(num);
  int len = strlen(num);
  for (int i = len; i >= 1; i--) num[i] = num[i - 1];
  if (len % 2) {
    len++;
    len /= 2;
    for (int i = 1; i <= len; i++) printf("%d", 4);
    for (int i = 1; i <= len; i++) printf("%d", 7);
  } else {
    int max4 = len / 2;
    int max7 = max4;
    for (int i = 1; i <= len; i++) {
      num4[i] = num4[i - 1];
      num7[i] = num7[i - 1];
      if (hehe) {
        num7[i]++;
        dp[i] = 7;
        is = 0;
        hehe = 0;
        continue;
      }
      if (!is || num[i] < '4') {
        if (num4[i] < max4) {
          dp[i] = 4;
          num4[i]++;
          if (num7[i] < max7) ps4 = i;
        } else {
          dp[i] = 7;
          num7[i]++;
        }
        is = 0;
      } else {
        if (num[i] == '4') {
          if (num4[i] < max4) {
            dp[i] = 4;
            num4[i]++;
            if (num7[i] < max7) ps4 = i;
          } else {
            dp[i] = 7;
            num7[i]++;
            is = 0;
          }
        } else if (num[i] < '7') {
          if (num7[i] < max7) {
            dp[i] = 7;
            num7[i]++;
            is = 0;
          } else {
            if (ps4 == 0) {
              cao = 1;
              break;
            } else {
              num4[ps4]--;
              i = ps4 - 1;
              hehe = 1;
            }
          }
        } else if (num[i] == '7') {
          if (num7[i] < max7) {
            dp[i] = 7;
            num7[i]++;
          } else {
            if (ps4 == 0) {
              cao = 1;
              break;
            } else {
              num4[ps4]--;
              i = ps4 - 1;
              hehe = 1;
            }
          }
        } else {
          if (ps4 == 0) {
            cao = 1;
            break;
          } else {
            num4[ps4]--;
            i = ps4 - 1;
            hehe = 1;
          }
        }
      }
    }
    if (cao) {
      len /= 2;
      len++;
      for (int i = 1; i <= len; i++) printf("4");
      for (int i = 1; i <= len; i++) printf("7");
    } else
      for (int i = 1; i <= len; i++) printf("%d", dp[i]);
  }
  return 0;
}