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 a;
string out;
int main() {
  cin >> a;
  if (a.size() % 2 == 1) {
    int k = a.size() + 1;
    for (int i = 0; i < k / 2; i++) cout << 4;
    for (int i = 0; i < k / 2; i++) cout << 7;
    cout << endl;
    return 0;
  }
  for (int i = 0; i < a.size() / 2; i++) {
    out += '7';
  }
  for (int i = 0; i < a.size() / 2; i++) {
    out += '4';
  }
  if (out < a) {
    int k = a.size() + 2;
    for (int i = 0; i < k / 2; i++) cout << 4;
    for (int i = 0; i < k / 2; i++) cout << 7;
    cout << endl;
    return 0;
  }
  int si = a.size() / 2;
  int qi = a.size() / 2;
  int zong = si + qi;
  int jishu4 = 0, jishu7 = 0;
  int ji = 0, ji2 = 0, jiq = 0;
  string shu;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] < '4') {
      for (int j = 0; j < si + qi; j++) shu += '4', jishu4++;
      break;
    } else if (a[i] == '4') {
      shu += '4';
      jishu4++;
      si--;
      ji = i;
    } else if (a[i] > '4' && a[i] < '7') {
      shu += '7';
      jishu7++;
      jiq = i;
      qi--;
      for (int j = 0; j < si + qi; j++) shu += '4', jishu4++;
      break;
    } else if (a[i] == '7') {
      shu += '7';
      jishu7++;
      jiq = i;
      qi--;
    } else if (a[i] > '7') {
      shu[ji] = '7';
      jishu7++;
      jishu4--;
      qi--;
      si++;
      for (int j = ji + 1; j < shu.size(); j++) {
        if (shu[j] == '7') {
          jishu7--;
          jishu4++;
        }
        shu[j] = '4';
      }
      for (int j = 0; j < si + qi; j++) shu += '4', jishu4++;
      break;
    }
  }
  if (jishu4 == jishu7) {
    cout << shu << endl;
    return 0;
  } else if (jishu4 > jishu7) {
    for (int i = shu.size() - 1; i >= 0; i--) {
      if (jishu4 == jishu7) {
        cout << shu << endl;
        return 0;
      }
      if (shu[i] == '4') {
        shu[i] = '7';
        jishu7++;
        jishu4--;
      }
      if (jishu4 == jishu7) {
        cout << shu << endl;
        return 0;
      }
    }
  } else if (jishu4 < jishu7) {
    for (int i = shu.size() - 1; i >= 0; i--) {
      int p = 0;
      if (shu[i] == '4') {
        for (int j = 0; j < i; j++) {
          if (shu[j] == '4') p++;
        }
        if (p + (shu.size() - i - 1) >= shu.size() / 2) {
          shu[i] = '7';
          jishu7++;
          jishu4--;
          int shu4 = 0, shu7 = 0;
          for (int j = i + 1; j < shu.size(); j++) {
            if (jishu4 == jishu7) {
              for (int k = i + 1; k <= i + shu4 + 1; k++) {
                shu[k] = '4';
              }
              for (int k = i + shu4 + 2; k < shu.size(); k++) {
                shu[k] = '7';
              }
              cout << shu << endl;
              return 0;
            }
            if (shu[j] == '7') {
              shu[j] = '4';
              jishu7--;
              jishu4++;
            }
            if (shu[j] == '4') shu4++;
            if (shu[j] == '7') shu7++;
            if (jishu4 == jishu7) {
              cout << shu << endl;
              return 0;
            }
          }
        }
      }
    }
  }
  return 0;
}