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 st;
long n, s[200000][3], ap, av;
bool nice(string st) {
  long s1, s2;
  s1 = s2 = 0;
  for (int i = 0; i < st.size(); i++)
    if (st[i] == '4')
      ++s1;
    else if (st[i] == '7')
      ++s2;
  if (s1 == s2 && s1 + s2 == st.size()) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> st;
  if (nice(st))
    cout << st << endl;
  else if (st.size() % 2) {
    n = st.size() + 1;
    n /= 2;
    for (int i = 0; i < n; i++) cout << 4;
    for (int i = 0; i < n; i++) cout << 7;
    cout << endl;
  } else {
    ap = av = -1;
    for (int i = 1; i <= st.size(); i++) {
      s[i][0] = s[i - 1][0];
      s[i][1] = s[i - 1][1];
      if (st[i - 1] == '4') s[i][0]++;
      if (st[i - 1] == '7') s[i][1]++;
    }
    for (int i = st.size() - 1; i >= 0; --i) {
      if (s[i][0] + s[i][1] != i) continue;
      if (st[i] < '4' && abs(s[i][0] + 1 - s[i][1]) < st.size() - i) {
        ap = i;
        av = 4;
        break;
      }
      if (st[i] < '7' && abs(s[i][0] - s[i][1] - 1) < st.size() - i) {
        ap = i;
        av = 7;
        break;
      }
    }
    if (ap == -1) {
      n = st.size() / 2;
      for (int i = 0; i <= n; i++) cout << 4;
      for (int i = 0; i <= n; i++) cout << 7;
      cout << endl;
    } else {
      long need4 = st.size() / 2;
      for (int i = 0; i < ap; i++) {
        cout << st[i];
        if (st[i] == '4') --need4;
      }
      cout << av;
      if (av == 4) --need4;
      for (int i = ap + 1; i < st.size(); i++) {
        if (need4) {
          cout << 4;
          --need4;
        } else
          cout << 7;
      }
      cout << endl;
    }
  }
  cin.get();
  cin.get();
  return 0;
}