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 maxlen = 200000;
char s[maxlen];
int len;
vector<int> v;
vector<int> res;
inline void print(vector<int> &tt) {
  for (int i = 0; i < (int)tt.size(); i++) {
    cout << tt[i];
  }
}
inline bool lss(vector<int> &a, vector<int> &b) {
  for (int i = 0; i < (int)a.size(); i++) {
    if (a[i] != b[i]) return a[i] < b[i];
  }
  return false;
}
int main() {
  scanf("%s", s);
  len = strlen(s);
  v.resize(len);
  for (int i = 0; i < len; i++) {
    v[i] = s[i] - '0';
  }
  int ct4 = 0, ct7 = 0;
  for (int i = 0; i < len; i++) {
    ct4 += (v[i] == 4);
    ct7 += (v[i] == 7);
  }
  if (ct4 + ct7 == len && ct4 == ct7) {
    print(v);
    return 0;
  } else {
    if (v.size() % 2 == 1) {
      len = v.size() + 1;
      for (int i = 1; i <= len; i++) {
        if (i <= len / 2)
          cout << 4;
        else
          cout << 7;
      }
      return 0;
    }
    vector<int> mx(v.size()), mn(v.size());
    for (int i = 1; i <= (int)v.size(); i++) {
      if (i <= len / 2) {
        mn[i - 1] = 4;
        mx[i - 1] = 7;
      } else {
        mn[i - 1] = 7;
        mx[i - 1] = 4;
      }
    }
    if (lss(mx, v)) {
      len = v.size() + 2;
      for (int i = 1; i <= len; i++) {
        if (i <= len / 2)
          cout << 4;
        else
          cout << 7;
      }
      return 0;
    }
    if (lss(v, mn)) {
      print(mn);
      return 0;
    }
    res = v;
    int pos = 0;
    while (pos < (int)res.size() && (res[pos] == 4 || res[pos] == 7)) pos++;
    if (pos < (int)res.size()) {
      if (res[pos] >= 0 && res[pos] < 4) {
        res[pos] = 4;
        for (int i = pos + 1; i < (int)res.size(); i++) res[i] = 4;
      } else if (res[pos] > 4 && res[pos] < 7) {
        res[pos] = 7;
        for (int i = pos + 1; i < (int)res.size(); i++) res[i] = 4;
      } else if (res[pos] > 7) {
        while (pos >= 0 && res[pos] >= 7) pos--;
        res[pos] = 7;
        for (int i = pos + 1; i < (int)res.size(); i++) res[i] = 4;
      }
    }
    ct4 = 0, ct7 = 0;
    for (int i = 0; i < (int)res.size(); i++) {
      ct4 += (res[i] == 4);
      ct7 += (res[i] == 7);
    }
    if (ct4 == ct7) {
      print(res);
      return 0;
    }
    if (ct4 > ct7) {
      int pos = res.size() - 1;
      while (ct4 != ct7) {
        while (res[pos] == 7) pos--;
        res[pos] = 7;
        ct4--;
        ct7++;
      }
      print(res);
      return 0;
    }
    if (ct7 > ct4) {
      int buf = ct4;
      int pos = res.size() - 1;
      while (1) {
        while (res[pos] == 7) pos--;
        if (buf - 1 + res.size() - 1 - pos >= res.size() / 2) {
          res[pos] = 7;
          pos++;
          while (pos < (int)res.size()) {
            res[pos] = 4;
            pos++;
          }
          break;
        } else {
          res[pos] = 7;
          buf--;
        }
      }
    }
    ct4 = 0, ct7 = 0;
    for (int i = 0; i < (int)res.size(); i++) {
      ct4 += (res[i] == 4);
      ct7 += (res[i] == 7);
    }
    if (ct4 == ct7) {
      print(res);
      return 0;
    }
    if (ct4 > ct7) {
      int pos = res.size() - 1;
      while (ct4 != ct7) {
        while (res[pos] == 7) pos--;
        res[pos] = 7;
        ct4--;
        ct7++;
      }
      print(res);
      return 0;
    }
  }
}