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 n, s;
long long ok, a, b;
int main() {
  cin >> n;
  if (n.size() & 1) n = string(n.size() + 1, '4');
  for (int i = n.size() - 1; i >= 0; i--) {
    if (n[i] < '4') {
      a = s.size() + 1;
      s.clear();
      s = string(a, '4');
      b = 0;
      ok = 0;
    } else if (n[i] == '4') {
      if (ok == 0) {
        s += '4';
        a++;
      } else {
        a = s.size();
        s.clear();
        s = string(a, '4');
        s += '7';
        ok = 0;
        b = 1;
      }
    } else if (n[i] < '7') {
      a = s.size();
      s.clear();
      s = string(a, '4');
      s += '7';
      ok = 0;
      b = 1;
    } else if (n[i] == '7') {
      if (ok == 0) {
        s += '7';
        b++;
      } else {
        a = s.size() + 1;
        s.clear();
        s = string(a, '4');
        ok = 3;
        b = 0;
      }
    } else {
      s += '4';
      a++;
      ok = 3;
    }
  }
  if (ok != 0) {
    s = string(n.size() + 2, '4');
    a = n.size() + 2;
    b = 0;
  }
  if (a < b) {
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '4') {
        s[i] = '7';
        a--;
        b++;
        for (int j = i - 1; j >= 0; j--) {
          if (s[j] == '7') {
            b--;
            a++;
            s[j] = '4';
          }
        }
      }
      if (a >= b) break;
    }
    if (b > a) {
      a = s.size() + 2;
      s.clear();
      s = string(a, '4');
      b = 0;
    }
  }
  reverse(s.begin(), s.end());
  long long dif = abs(a - b);
  for (int i = s.size() - 1; i >= 0; i--) {
    if (dif == 0) break;
    if (s[i] == '4') s[i] = '7', dif -= 2;
  }
  cout << s;
}