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 M = 100050;
char s[M], tmp[M];
int pos[M], ct[M], cnt1, cnt2;
int main() {
  scanf("%s", s);
  int len = strlen(s);
  bool flag = 0;
  if (len & 1) {
    for (int i = 0; i < (len + 1) >> 1; i++) printf("4");
    for (int i = 0; i < (len + 1) >> 1; i++) printf("7");
    return 0;
  }
  int i, ll = len >> 1;
  for (i = 0; i < len; i++) {
    if (s[i] <= '4') {
      cnt1++;
      if (cnt1 > ll) {
        tmp[i] = '7';
        cnt1--, cnt2++;
        break;
      } else {
        tmp[i] = '4';
        if (s[i] < '4') break;
        pos[cnt1] = i;
        ct[cnt1] = cnt2;
      }
    } else if (s[i] <= '7') {
      cnt2++;
      if (cnt2 > ll) {
        while (cnt1 && ct[cnt1] >= ll) cnt1--;
        if (cnt1 == 0) {
          flag = 1;
          break;
        }
        tmp[i = pos[cnt1]] = '7';
        cnt2 = ct[cnt1--] + 1;
        break;
      } else {
        tmp[i] = '7';
        if (s[i] < '7') break;
      }
    } else {
      while (cnt1 && ct[cnt1] >= ll) cnt1--;
      if (cnt1 == 0) {
        flag = 1;
        break;
      }
      tmp[i = pos[cnt1]] = '7';
      cnt2 = ct[cnt1--] + 1;
      break;
    }
  }
  if (flag) {
    i = ll + 1;
    while (i--) printf("4");
    i = ll + 1;
    while (i--) printf("7");
  } else {
    if (i == len) i--;
    for (int j = 0; j <= i; j++) printf("%c", tmp[j]);
    i = ll - cnt1;
    while (i--) printf("4");
    i = ll - cnt2;
    while (i--) printf("7");
  }
}