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;
const int mod = (int)1e6 + 3;
const int inf = (int)1e9;
const int base = 10;
int main() {
  string s;
  getline(cin, s);
  int n = (int)s.size();
  if (n % 2 == 1)
    cout << string((n + 1) / 2, '4') + string((n + 1) / 2, '7');
  else if (string(n / 2, '7') + string(n / 2, '4') < s) {
    cout << string((n + 2) / 2, '4') + string((n + 2) / 2, '7');
  } else {
    string ans = "";
    bool f = true;
    for (int i = 0; i < n && f; ++i) {
      if (s[i] < '4') {
        f = false;
        ans += '4';
      } else if (s[i] != '4' && s[i] < '7') {
        f = false;
        ans += '7';
      } else if (s[i] != '4' && s[i] != '7' && s[i] > '7') {
        ans += '4';
        bool ost = true;
        for (int j = (int)ans.size() - 2; j >= 0 && ost; --j) {
          if (ans[j] == '4') {
            ost = false;
            ans[j] = '7';
          }
        }
      } else
        ans += s[i];
    }
    int a = 0;
    int b = 0;
    for (int i = 0; i < (int)ans.size(); i++)
      if (ans[i] == '4')
        a++;
      else
        b++;
    a = (n / 2) - a;
    b = (n / 2) - b;
    if (a < 0 || b < 0) {
      if (a < 0) {
        b += a;
        for (int i = (int)ans.size() - 1; i >= 0 && a < 0; --i) {
          if (ans[i] == '4') {
            ans[i] = '7';
            a++;
          }
        }
        cout << ans + string(b, '7');
      } else {
        int j = (int)ans.size() - 1;
        while (j >= 0 && (ans[j] != '4' || b <= 0)) {
          if (ans[j] == '7') b++;
          j--;
        }
        if (j < 0) {
          n += 2;
          cout << string(n / 2, '4') + string(n / 2, '7');
        } else {
          ans[j] = '7';
          string cur = "";
          int a = 0;
          int b = 0;
          for (int i = 0; i < j + 1; i++) {
            cur += ans[i];
            if (ans[i] == '4')
              a++;
            else
              b++;
          }
          a = (n / 2) - a;
          b = (n / 2) - b;
          cout << cur + string(a, '4') + string(b, '7');
        }
      }
    } else
      cout << ans + string(a, '4') + string(b, '7');
  }
  return 0;
}