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;
int s4[100002], s7[100002];
int o4[100002], o7[100002];
void print(int n) {
  string ans = "";
  for (int i = 0; i < n / 2; i++) {
    ans += '4';
  }
  for (int i = 0; i < n / 2; i++) {
    ans += '7';
  }
  cout << ans << "\n";
}
int poss(string s) {
  int n = s.size();
  string te = "";
  for (int i = 0; i < n / 2; i++) {
    te += '7';
  }
  for (int i = 0; i < n / 2; i++) {
    te += '4';
  }
  for (int i = 0; i < n; i++) {
    if (te[i] > s[i]) {
      return 1;
    } else if (te[i] < s[i]) {
      return 0;
    }
  }
  return 1;
}
int main() {
  string s;
  cin >> s;
  int n = s.size();
  if (n % 2 != 0) {
    print(n + 1);
    return 0;
  }
  if (poss(s) == 0) {
    print(n + 2);
    return 0;
  }
  if (s[0] == '4') {
    s4[0] = 1;
  } else if (s[0] == '7') {
    s7[0] = 1;
  }
  for (int i = 1; i < n; i++) {
    if (s[i] == '4') {
      s4[i] = s4[i - 1] + 1;
    } else {
      s4[i] = s4[i - 1];
    }
    if (s[i] == '7') {
      s7[i] = s7[i - 1] + 1;
    } else {
      s7[i] = s7[i - 1];
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '4') {
      o4[i] = o4[i + 1];
    } else if (s[i] < '4') {
      o4[i] = 1;
    } else {
      o4[i] = 0;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '7') {
      o7[i] = o7[i + 1];
    } else if (s[i] < '7') {
      o7[i] = 1;
    } else {
      o7[i] = 0;
    }
  }
  string ans = "";
  int ok = 0, rem4, rem7;
  rem4 = rem7 = n / 2;
  for (int i = 0; i < n; i++) {
    if (ok == 1) {
      if (rem4 != 0) {
        ans += '4';
        rem4--;
      } else if (rem7 != 0) {
        ans += '7';
        rem7--;
      }
    } else {
      if (s[i] < '4') {
        ok = 1;
        ans += '4';
        rem4--;
      } else if (s[i] > '4' && s[i] < '7') {
        ans += '7';
        rem7--;
        ok = 1;
      } else if (s[i] == '7') {
        ans += '7';
        rem7--;
      } else {
        char ch = '7';
        if (s7[i + rem7] - s7[i] == rem7) {
          if (s4[n - 1] - s4[i + rem7] == rem4 - 1) {
            ch = '4';
          } else if (o4[i + rem7 + 1] == 1) {
            ch = '4';
          }
        } else if (o7[i + 1] == 1) {
          ch = '4';
        }
        if (ch == '7') {
          rem7--;
          ok = 1;
        } else {
          rem4--;
        }
        ans += ch;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}