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 s;
int n;
void printMin(int sz) {
  for (int i = 0; i < sz / 2; i++) {
    cout << 4;
  }
  for (int i = sz / 2; i < sz; i++) {
    cout << 7;
  }
  cout << endl;
}
inline bool ok() {
  for (int i = 0; i < n / 2; i++) {
    if (s[i] == '4') return true;
  }
  return false;
}
inline void balance(int bal) {
  if (!ok()) {
    printMin(n + 2);
    return;
  }
  int mark = 0;
  int fours = 0;
  for (int i = n - 1; i >= 0; i--) {
    fours++;
    if (s[i] == '7') {
      s[i] = '4';
      bal -= 2;
      mark = i;
    }
    if (bal == -2) break;
  }
  if (bal != -2) {
    printMin(n + 2);
    return;
  }
  int i = mark - 1;
  for (; i >= 0; i--) {
    if (s[i] == '4') {
      s[i] = '7';
      bal += 2;
      break;
    }
  }
  i++;
  for (int count = 0; count < fours; count++) {
    s[i] = '4';
    i++;
  }
  for (; i < n; i++) {
    s[i] = '7';
  }
  if (bal == 0) {
    cout << s << endl;
  } else {
    printMin(n + 2);
  }
}
int main(void) {
  cin >> s;
  n = s.size();
  if (n % 2 == 1) {
    printMin(n + 1);
    return 0;
  }
  int bal = 0, idx = 0, mark;
  bool flag = false;
  for (; idx < n; idx++) {
    if (s[idx] == '4') {
      continue;
    } else if (s[idx] == '7') {
      continue;
    } else if (s[idx] < '4') {
      s[idx] = '4';
      mark = idx + 1;
      break;
    } else if (s[idx] < '7') {
      s[idx] = '7';
      mark = idx + 1;
      break;
    } else {
      flag = true;
      mark = idx - 1;
      idx--;
      break;
    }
  }
  if (flag) {
    for (; mark >= 0; mark--) {
      if (s[mark] == '4') {
        s[mark] = '7';
        flag = false;
        mark++;
        break;
      }
    }
  }
  if (flag) {
    printMin(n + 2);
    return 0;
  }
  for (; mark < n; mark++) {
    s[mark] = '4';
  }
  bal = 0;
  for (int index = 0; index < n; index++) {
    if (s[index] == '4') {
      bal--;
    } else if (s[index] == '7') {
      bal++;
    }
  }
  if (bal == 0) {
    cout << s << endl;
    return 0;
  } else if (bal < 0) {
    for (int i = n - 1; i >= 0; i--) {
      if (s[i] == '4') {
        s[i] = '7';
        bal += 2;
      }
      if (bal == 0) break;
    }
    cout << s << endl;
  } else {
    balance(bal);
  }
  return 0;
}