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;
string s;
vector<char> v;
int l, r;
void print(int l, int r) {
  for (int i = 0; i < (int)v.size(); ++i) cout << v[i];
  for (int i = 0; i < l; ++i) cout << '4';
  for (int i = 0; i < r; ++i) cout << '7';
  exit(0);
}
void flashback(int x) {
  --x;
  for (int i = x; i >= 0; --i) {
    if (v[i] == '7') {
      v.pop_back();
      ++r;
    } else if (r) {
      v.pop_back();
      v.push_back('7');
      --r;
      ++l;
      print(l, r);
    } else {
      v.pop_back();
      ++l;
    }
  }
  ++l;
  ++r;
  print(l, r);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  int len = s.size() / 2;
  l = r = len;
  if (s.size() % 2) {
    ++l;
    ++r;
    print(l, r);
  }
  if (s[0] <= '3') {
    print(l, r);
  }
  if (s[0] > '4' && s[0] < '7') {
    cout << '7';
    --r;
    print(l, r);
  }
  if (s[0] > '7') {
    ++l;
    ++r;
    print(l, r);
  }
  for (int i = 0; i < (int)s.size(); ++i) {
    if (s[i] < '4') {
      if (l) {
        --l;
        v.push_back('4');
      } else if (r) {
        --r;
        v.push_back('7');
      } else
        flashback(i);
      print(l, r);
    } else if (s[i] == '4') {
      if (l) {
        --l;
        v.push_back('4');
      } else if (r) {
        --r;
        v.push_back('7');
        print(l, r);
      } else
        flashback(i);
    } else if (s[i] < '7') {
      if (r) {
        --r;
        v.push_back('7');
        print(l, r);
      } else
        flashback(i);
    } else if (s[i] == '7') {
      if (r) {
        --r, v.push_back('7');
      } else
        flashback(i);
    } else
      flashback(i);
  }
  print(l, r);
}