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;
vector<int> next_p(vector<int> s) {
  vector<int> ss = s;
  int I = -1, J = -1;
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == 7) {
      I = i;
      break;
    }
  }
  for (int j = I - 1; j >= 0; j--) {
    if (s[j] == 4) {
      J = j;
      break;
    }
  }
  if (I == -1 || J == -1)
    return s;
  else {
    int tmp = ss[I];
    ss[I] = ss[J];
    ss[J] = tmp;
    sort(ss.begin() + J + 1, ss.end());
  }
  return ss;
}
int grt(string s, string t) {
  if (s.size() > t.size())
    return 1;
  else if (s.size() < t.size())
    return 2;
  for (int i = (int)0; i < (int)s.size(); ++i) {
    if (s[i] - '0' > t[i] - '0')
      return 1;
    else if (s[i] - '0' < t[i] - '0')
      return 2;
  }
  return 2;
}
string smallest_given(int n, int fours, int sevens) {
  string s("");
  for (int i = (int)0; i < (int)(n / 2) - fours; ++i) s += '4';
  for (int i = (int)0; i < (int)(n / 2) - sevens; ++i) s += '7';
  return s;
}
string smallest(int n) {
  string s("");
  for (int i = (int)0; i < (int)n / 2; ++i) s += '4';
  for (int i = (int)0; i < (int)n / 2; ++i) s += '7';
  return s;
}
string next(string s) {
  int fr = 0;
  int sv = 0;
  vector<int> vv, nn;
  for (int i = (int)0; i < (int)s.size(); ++i) {
    if (s[i] == '4') {
      fr++;
      vv.push_back(4);
    } else if (s[i] == '7') {
      sv++;
      vv.push_back(7);
    }
  }
  if (fr == sv)
    return s;
  else {
    nn = next_p(vv);
    int fg = 0;
    if (vv == nn) {
      if (vv[0] == 4) {
        return smallest(vv.size());
      } else {
        return smallest(vv.size() + 2);
      }
    } else {
      if (fr > sv) {
        int j = 0;
        for (int i = vv.size() - 1; i >= 0; i--) {
          if (vv[i] == 4) {
            vv[i] = 7;
            fr--;
            sv++;
          }
          if (fr == sv) break;
        }
      } else {
        for (int i = vv.size() - 1; i >= 0; i--) {
          if (vv[i] == 7) {
            vv[i] = 4;
            fr++;
            sv--;
          }
          if (fr == sv) break;
        }
        vv = next_p(vv);
      }
      string t;
      for (int i = (int)0; i < (int)vv.size(); ++i) {
        if (vv[i] == 4)
          t += '4';
        else if (vv[i] == 7)
          t += '7';
      }
      return t;
    }
  }
}
int main() {
  string s;
  cin >> s;
  vector<int> v, v_next;
  if (s.size() % 2 == 0) {
    string sofar("");
    int fours = 0;
    int sevens = 0;
    if (s[0] - '0' > 7) {
      sofar += smallest(s.size() + 2);
    } else {
      for (int i = (int)0; i < (int)s.size(); ++i) {
        if ((s[i] - '0') < 4) {
          sofar += smallest_given(s.size(), fours, sevens);
          break;
        } else if (s[i] == '4') {
          sofar += '4';
          v.push_back(4);
          fours++;
        } else if (s[i] == '5' || s[i] == '6') {
          sofar += '7';
          sevens++;
          sofar += smallest_given(s.size(), fours, sevens);
          break;
        } else if (s[i] == '7') {
          sofar += '7';
          sevens++;
          v.push_back(7);
        } else if (s[i] - '0' > 7) {
          v_next = next_p(v);
          int fg = 0;
          if (v == v_next) {
            if (v[0] == 4) {
              v[v.size() - 1] = 7;
              fours--;
              sevens++;
            } else {
              fg = 1;
              v.clear();
              for (int i = (int)0; i < (int)v_next.size() + 1; ++i)
                v.push_back(4);
              fours = v_next.size() + 1;
              sevens = 0;
            }
          } else {
          }
          sofar = "";
          for (int i = (int)0; i < (int)v.size(); ++i) {
            if (v[i] == 4)
              sofar += '4';
            else
              sofar += '7';
          }
          if (fg == 1) {
            sofar = smallest_given(s.size() + 2, 0, 0);
          } else {
            sofar += smallest_given(s.size(), fours, sevens);
            if (grt(sofar, s) == 2) {
              v.clear();
              for (int i = (int)0; i < (int)sofar.size(); ++i) {
                v.push_back(sofar[i] - '0');
              }
              v = next_p(v);
              sofar = "";
              for (int i = (int)0; i < (int)v.size(); ++i) {
                if (v[i] == 4)
                  sofar += '4';
                else
                  sofar += '7';
              }
            }
          }
          break;
        }
      }
    }
    cout << next(sofar) << endl;
  } else {
    cout << smallest(s.size() + 1) << endl;
  }
  return 0;
}