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[1000005];
int dp[1000005];
int main() {
  int a, b;
  while (~scanf("%s", s)) {
    int fl = 1;
    int k = strlen(s);
    if (k % 2 == 1) {
      fl = 0;
      for (int i = 0; i <= k / 2; i++) printf("4");
      for (int i = 0; i <= k / 2; i++) printf("7");
    } else {
      if (s[0] > '7') {
        fl = 0;
        for (int i = 0; i <= k / 2; i++) printf("4");
        for (int i = 0; i <= k / 2; i++) printf("7");
      } else if (s[0] == '7') {
        int flag = 0;
        int t = 0;
        while (s[t++] == '7') {
          if (t == k / 2 && s[t] > '4') {
            flag = 1;
            break;
          }
          if (s[t] > '7') {
            flag = 1;
          }
          if (s[t] < '7') break;
        }
        if (t == k / 2 && s[t] >= '4') {
          for (int i = k / 2; i < k; i++)
            if (s[i] > '4') {
              flag = 1;
              break;
            }
        }
        if (flag) {
          fl = 0;
          for (int i = 0; i <= k / 2; i++) printf("4");
          for (int i = 0; i <= k / 2; i++) printf("7");
        }
      }
      if (fl == 1) {
        a = 0;
        b = 0;
        for (int i = 0; i < k; i++) {
          if (s[i] < '4') {
            if (a < k / 2) {
              dp[i] = 4;
              a++;
            } else {
              dp[i] = 7;
              b++;
            }
            fl = 0;
            int x = 0;
            int y = 0;
            for (int j = 0; j <= i; j++) {
              if (dp[j] == 4) x++;
              if (dp[j] == 7) y++;
              printf("%d", dp[j]);
            }
            for (int j = 0; j < k / 2 - x; j++) printf("4");
            for (int j = 0; j < k / 2 - y; j++) printf("7");
            break;
          } else if (s[i] == '4') {
            if (a < k / 2) {
              dp[i] = 4;
              a++;
            } else {
              dp[i] = 7;
              b++;
              fl = 0;
              int x = 0;
              int y = 0;
              for (int j = 0; j <= i; j++) {
                if (dp[j] == 4) x++;
                if (dp[j] == 7) y++;
                printf("%d", dp[j]);
              }
              for (int j = 0; j < k / 2 - x; j++) printf("4");
              for (int j = 0; j < k / 2 - y; j++) printf("7");
              break;
            }
          } else if (s[i] < '7') {
            dp[i] = 7;
            b++;
            int t = i;
            if (b > k / 2) {
              dp[i] = 4;
              a++;
              while (1) {
                t--;
                if (dp[t] == 7) {
                  b--;
                  a++;
                  dp[t] = 4;
                  ;
                } else if (dp[t] == 4) {
                  if (b > k / 2) {
                    b--;
                    dp[t] = 4;
                    a++;
                    continue;
                  }
                  a--;
                  b++;
                  dp[t] = 7;
                  break;
                }
              }
            }
            fl = 0;
            int x = 0;
            int y = 0;
            for (int j = 0; j <= t; j++) {
              if (dp[j] == 4) x++;
              if (dp[j] == 7) y++;
              printf("%d", dp[j]);
            }
            for (int j = 0; j < k / 2 - x; j++) printf("4");
            for (int j = 0; j < k / 2 - y; j++) printf("7");
            break;
          } else if (s[i] == '7') {
            dp[i] = 7;
            b++;
            if (b > k / 2) {
              b--;
              dp[i] = 4;
              a++;
              int t = i;
              while (1) {
                t--;
                if (dp[t] == 7) {
                  b--;
                  a++;
                  dp[t] = 4;
                  ;
                } else if (dp[t] == 4) {
                  a--;
                  b++;
                  dp[t] = 7;
                  if (b > k / 2) {
                    b--;
                    dp[t] = 4;
                    a++;
                    continue;
                  }
                  break;
                }
              }
              fl = 0;
              int x = 0;
              int y = 0;
              for (int j = 0; j <= t; j++) {
                if (dp[j] == 4) x++;
                if (dp[j] == 7) y++;
                printf("%d", dp[j]);
              }
              for (int j = 0; j < k / 2 - x; j++) printf("4");
              for (int j = 0; j < k / 2 - y; j++) printf("7");
              break;
            }
          } else if (s[i] > '7') {
            dp[i] = 4;
            a++;
            int t = i;
            while (1) {
              t--;
              if (dp[t] == 7) {
                b--;
                a++;
                dp[t] = 4;
                ;
              } else if (dp[t] == 4) {
                a--;
                b++;
                dp[t] = 7;
                break;
              }
            }
            fl = 0;
            int x = 0;
            int y = 0;
            for (int j = 0; j <= t; j++) {
              if (dp[j] == 4) x++;
              if (dp[j] == 7) y++;
              printf("%d", dp[j]);
            }
            for (int j = 0; j < k / 2 - x; j++) printf("4");
            for (int j = 0; j < k / 2 - y; j++) printf("7");
            break;
          }
        }
      }
    }
    if (fl)
      for (int j = 0; j < k; j++) {
        printf("%d", dp[j]);
      }
    printf("\n");
  }
  return 0;
}