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 INF = 1000000100;
const int MAXN = 1000100;
string s;
int gr[] = {0, 4, 5, 7, 8, 10};
int last[10], n;
int ost[MAXN][5];
int czy_mniejsze_od_7(int p, int k) {
  int mini = INF;
  for (int i = 0; i < 3; i++) {
    mini = min(mini, ost[p][i]);
  }
  if (mini > k && ost[p][4] > k) {
    return 0;
  }
  if (mini > ost[p][4]) {
    return -1;
  }
  return 1;
}
int czy_mniejsze_od_4(int p, int k) {
  int mini = INF;
  for (int i = 2; i < 5; i++) {
    mini = min(mini, ost[p][i]);
  }
  if (mini > k && ost[p][0] > k) {
    return 0;
  }
  if (mini < ost[p][0]) {
    return -1;
  }
  return 1;
}
bool da_sie(int suf, int pula4, int pula7) {
  int ost7 = suf + pula7 - 1;
  int x = czy_mniejsze_od_7(suf, ost7);
  if (x == -1) {
    return false;
  }
  if (x == 1) {
    return true;
  }
  x = czy_mniejsze_od_4(ost7 + 1, n - 1);
  if (x == -1) {
    return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> s;
  n = s.size();
  if (n % 2 == 1) {
    n++;
  res:
    for (int i = 0; i < n / 2; i++) {
      cout << 4;
    }
    for (int i = 0; i < n / 2; i++) {
      cout << 7;
    }
    cout << endl;
    return 0;
  }
  for (int i = 0; i < 10; i++) {
    last[i] = INF;
  }
  for (int i = n - 1; i >= 0; i--) {
    last[s[i] - '0'] = i;
    ost[i][0] = ost[i][1] = ost[i][2] = ost[i][3] = ost[i][4] = INF;
    for (int j = 0; j < 5; j++) {
      ost[i][j] = INF;
      for (int k = gr[j]; k < gr[j + 1]; k++) {
        ost[i][j] = min(ost[i][j], last[k]);
      }
    }
  }
  int ok = 0;
  for (int i = 0; i < n / 2; i++) {
    if (s[i] < '7') {
      ok = 1;
      break;
    } else if (s[i] > '7') {
      ok = -1;
      break;
    }
  }
  if (ok == -1) {
    n += 2;
    goto res;
  }
  if (ok == 0) {
    for (int i = n / 2; i < n; i++) {
      if (s[i] < '4') {
        ok = 1;
        break;
      } else if (s[i] > '4') {
        ok = -1;
        break;
      }
    }
    if (ok == -1) {
      n += 2;
      goto res;
    }
  }
  bool row = true;
  int pula4 = n / 2, pula7 = n / 2;
  for (int i = 0; i < s.size(); i++) {
    if (pula4 == 0) {
      cout << 7;
      pula7--;
    } else if (pula7 == 0) {
      cout << 4;
      pula4--;
    } else {
      int x = da_sie(i + 1, pula4 - 1, pula7);
      int wyp;
      if (row && s[i] < '4') {
        cout << 4;
        pula4--;
        row = false;
      } else if (row && s[i] > '4') {
        if (s[i] != '7') {
          row = false;
        }
        cout << 7;
        pula7--;
      } else if (x || !row) {
        cout << 4;
        if (4 != s[i] - '0') {
          row = false;
        }
        pula4--;
      } else {
        cout << 7;
        if (s[i] - '0' != 7) {
          row = false;
        }
        pula7--;
      }
    }
  }
  cout << endl;
}