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 N = 100005;
char str[N];
char ans[N];
int main() {
  scanf("%s", str);
  int len = strlen(str);
  if (len % 2) {
    len++;
    for (int i = 0; i < len / 2; i++) str[i] = '4';
    for (int i = len / 2; i < len; i++) str[i] = '7';
    str[len] = 0;
    cout << str << endl;
  } else {
    int pre4 = -1;
    int num4 = len / 2, num7 = len / 2;
    bool flag = false;
    int i;
    for (i = 0; i < len; i++) {
      if (flag) {
        if (num4 > 0)
          ans[i] = '4', num4--;
        else
          ans[i] = '7', num7--;
      } else {
        if (str[i] > '4' && num7 > 0 || num4 == 0) {
          num7--;
          ans[i] = '7';
        } else {
          num4--;
          ans[i] = '4';
          if (ans[i] >= str[i]) pre4 = i;
        }
        if (ans[i] > str[i]) {
          flag = true;
        } else if (ans[i] < str[i]) {
          if (pre4 != -1) {
            flag = true;
            int pre7 = i;
            while (ans[pre7] != '7' && pre7 >= 0) pre7--;
            while (pre7 > 0 && !(ans[pre7 - 1] == '4' && ans[pre7] == '7'))
              pre7--;
            if (pre7 == 0) {
              flag = false;
              break;
            }
            swap(ans[pre7 - 1], ans[pre7]);
            int num44 = len / 2, num77 = len / 2;
            for (int j = 0; j <= pre7; j++)
              if (ans[j] == '4')
                num44--;
              else
                num77--;
            for (int j = pre7 + 1; j < len; j++)
              if (num44 > 0)
                ans[j] = '4', num44--;
              else
                ans[j] = '7';
            break;
          } else {
            flag = false;
            break;
          }
        }
      }
    }
    if (!flag && i < len) {
      len += 2;
      for (int j = 0; j < len / 2; j++) ans[j] = '4';
      for (int j = len / 2; j < len; j++) ans[j] = '7';
    }
    ans[len] = 0;
    cout << ans << endl;
  }
}