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;
struct _ {
  _() { ios_base::sync_with_stdio(0); }
} _;
template <class A, class B>
ostream &operator<<(ostream &o, pair<A, B> t) {
  o << "(" << t.first << ", " << t.second << ")";
  return o;
}
template <class T>
void PV(T a, T b, int n = 0) {
  int c = 0;
  while (a < b) {
    cout << *a++;
    if (a < b && (n == 0 || ++c % n))
      cout << " ";
    else
      cout << endl;
  }
}
template <class T>
inline bool chmin(T &a, T b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
inline bool chmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
string tostring(T first, int len = 0) {
  stringstream ss;
  ss << first;
  string r = ss.str();
  if (r.length() < len) r = string(len - r.length(), '0') + r;
  return r;
}
template <class T>
void convert(string first, T &r) {
  stringstream ss(first);
  ss >> r;
}
const long long linf = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int mod = int(1e9) + 7;
const int N = 111111;
vector<int> n;
int m;
vector<string> vs;
int path[N];
bool dfs(int n4, int n7, int e) {
  if (n4 > n.size() / 2 || n7 > n.size() / 2) return 0;
  if (n4 + n7 == n.size()) {
    if (n4 != n7) {
      return 0;
    } else {
      if (n4 == n7) {
        string s;
        for (int i = 0; i < n4 + n7; i++) s += path[i] + '0';
        vs.push_back(s);
        return 1;
      }
    }
  }
  if (e == 0) {
    int rn4 = n.size() / 2 - n4;
    int rn7 = n.size() / 2 - n7;
    string s;
    for (int i = 0; i < n4 + n7; i++) s += path[i] + '0';
    s += string(rn4, '4') + string(rn7, '7');
    vs.push_back(s);
    return 1;
  } else {
    if (n[n4 + n7] > 7) {
      return 0;
    } else if (n[n4 + n7] > 4) {
      path[n4 + n7] = 7;
      if (dfs(n4, n7 + 1, n[n4 + n7] == 7)) return 1;
    } else {
      path[n4 + n7] = 4;
      if (dfs(n4 + 1, n7, n[n4 + n7] == 4)) return 1;
      path[n4 + n7] = 7;
      if (dfs(n4, n7 + 1, n[n4 + n7] == 7)) return 1;
    }
  }
  return 0;
}
int main() {
  string s;
  cin >> s;
  for (auto i : s) n.push_back(i - '0');
  if (n.size() % 2 == 0) dfs(0, 0, 1);
  reverse((n).begin(), (n).end());
  n.push_back(0);
  reverse((n).begin(), (n).end());
  if (n.size() % 2 == 0) dfs(0, 0, 1);
  reverse((n).begin(), (n).end());
  n.push_back(0);
  reverse((n).begin(), (n).end());
  if (n.size() % 2 == 0) dfs(0, 0, 1);
  string best = vs[0];
  for (int i = 1; i < vs.size(); i++) {
    if (best.length() > vs[i].length())
      best = vs[i];
    else if (best.length() == vs[i].length())
      chmin(best, vs[i]);
  }
  cout << best << endl;
  return 0;
}