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 getNextLucky(string s) {
  int n = s.size();
  if (s[0] > '7') {
    string ret = "";
    for (int i = 0; i <= n; i++) {
      ret += '4';
    }
    return ret;
  }
  bool flg = false;
  for (int i = 0; i < n; i++) {
    if (s[i] == '4' || s[i] == '7') continue;
    if (s[i] > '7') {
      for (int j = i; j < n; j++) {
        s[j] = '7';
      }
      flg = true;
      break;
    } else if (s[i] < '4') {
      for (int j = i; j < n; j++) {
        s[j] = '4';
      }
      return s;
      exit(0);
    } else if (s[i] < '7') {
      for (int j = i + 1; j < n; j++) {
        s[j] = '4';
      }
      s[i] = '7';
      return s;
      exit(0);
    }
  }
  if (!flg) return s;
  reverse(s.begin(), s.end());
  int carry = 1;
  for (int i = 0; i < n; i++) {
    if (s[i] == '4') {
      s[i] = '7';
      carry = 0;
      break;
    } else {
      s[i] = '4';
    }
  }
  if (carry) s += '4';
  reverse(s.begin(), s.end());
  return s;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(32);
  string s;
  cin >> s;
  s = getNextLucky(s);
  int n = s.size();
  if (n & 1) {
    int k = (n + 1) / 2;
    for (int i = 0; i < k; i++) {
      cout << 4;
    }
    for (int i = 0; i < k; i++) {
      cout << 7;
    }
  } else {
    int k = n / 2;
    int cnt4 = 0, cnt7 = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == '4')
        cnt4++;
      else
        cnt7++;
    }
    if (cnt4 == cnt7) {
      cout << s << endl;
      exit(0);
    }
    if (cnt4 > cnt7) {
      int req = (cnt4 - cnt7) / 2;
      for (int i = n - 1; i >= 0; i--) {
        if (s[i] == '4') {
          s[i] = '7';
          req--;
        }
        if (req == 0) break;
      }
      cout << s << endl;
      exit(0);
    }
    if (cnt4 == 0) {
      for (int i = 0; i <= k; i++) {
        cout << 4;
      }
      for (int i = 0; i <= k; i++) {
        cout << 7;
      }
      exit(0);
    }
    if (cnt7 > cnt4) {
      for (int i = n - 1; i >= 0; i--) {
        if (s[i] == '4') cnt4--;
        if (s[i] == '7') cnt7--;
        if (s[i] == '4') {
          int t7 = cnt7 + 1;
          int t4 = cnt4 + (n - i - 1);
          if (t4 >= t7) {
            for (int j = i + 1; j < n; j++) {
              s[j] = '4';
            }
            s[i] = '7';
            break;
          }
        }
      }
    }
    cnt4 = cnt7 = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == '4')
        cnt4++;
      else
        cnt7++;
    }
    if (cnt4 == cnt7) {
      cout << s << endl;
      exit(0);
    }
    if (cnt4 > cnt7) {
      int req = (cnt4 - cnt7) / 2;
      for (int i = n - 1; i >= 0; i--) {
        if (s[i] == '4') {
          s[i] = '7';
          req--;
        }
        if (req == 0) break;
      }
      cout << s << endl;
      exit(0);
    }
    for (int i = 0; i <= k; i++) {
      cout << 4;
    }
    for (int i = 0; i <= k; i++) {
      cout << 7;
    }
    exit(0);
  }
  return 0;
}