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;
inline int in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
char ch[4000010];
inline string get() {
  scanf("%s", ch);
  return string(ch);
}
inline void read(int *a, int n) {
  for (int i = 0; i < n; i++) a[i] = in();
}
template <class blank>
inline void out(blank x) {
  cout << x << "\n";
  exit(0);
}
template <class blank, class blank2>
inline void smin(blank &a, blank2 b) {
  a = a <= b ? a : b;
}
template <class blank, class blank2>
inline void smax(blank &a, blank2 b) {
  a = a >= b ? a : b;
}
const int maxn = 4e3 + 10;
const int maxm = 4e6 + 10;
const int maxlg = 22;
const int base = 29;
const int mod = 1e9 + 7;
const long long inf = 1e9 + 10;
const double eps = 1e-4;
const int SQ = 317;
inline bool ok(string &s) {
  int cnt[] = {0, 0};
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != '4' && s[i] != '7') return false;
    cnt[(s[i] - '0') / 5]++;
  }
  return cnt[0] == cnt[1];
}
int pref[maxn][2];
int32_t main() {
  string s = get();
  int n = (int)s.size();
  if (n % 2) {
    for (int j = 0; j <= n; j++) cout << (j <= n / 2 ? 4 : 7);
    return 0;
  }
  if (ok(s)) out(s);
  for (int i = 0; i < n; i++) {
    if (i)
      for (int j = 0; j < 2; j++) pref[i][j] = pref[i - 1][j];
    if (s[i] == '4')
      pref[i][0]++;
    else if (s[i] == '7')
      pref[i][1]++;
  }
  for (int i = n - 1; i >= 0; i--) {
    if (i == 0 || pref[i - 1][0] + pref[i - 1][1] == i) {
      if (s[i] < '4') {
        int four = (i ? pref[i - 1][0] : 0) + 1;
        int seven = (i ? pref[i - 1][1] : 0);
        int fourRight = n / 2 - four;
        int sevenRight = n - i - 1 - fourRight;
        if (fourRight >= 0 && sevenRight >= 0) {
          cout << s.substr(0, i) << '4';
          while (fourRight--) cout << 4;
          while (sevenRight--) cout << 7;
          return 0;
        }
      }
      if (s[i] < '7') {
        int four = (i ? pref[i - 1][0] : 0);
        int seven = (i ? pref[i - 1][1] : 0) + 1;
        int fourRight = n / 2 - four;
        int sevenRight = n - i - 1 - fourRight;
        if (fourRight >= 0 && sevenRight >= 0) {
          cout << s.substr(0, i) << '7';
          while (fourRight--) cout << 4;
          while (sevenRight--) cout << 7;
          return 0;
        }
      }
    }
  }
  n += 2;
  for (int i = 1; i <= n; i++) cout << (i <= n / 2 ? 4 : 7);
}