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;
int main() {
  string n;
  string made;
  cin >> n;
  bool ls = false;
  for (int i = 0; i < n.length(); ++i) {
    if (ls) {
      made = made + "4";
    } else if (n[i] <= '4') {
      made = made + "4";
      if (n[i] < '4') ls = true;
    } else if (n[i] <= '7') {
      made = made + "7";
      if (n[i] < '7') ls = true;
    } else {
      bool ok = false;
      for (int j = made.size() - 1; j >= 0; --j)
        if (made[j] == '4') {
          made[j] = '7';
          ls = true;
          ok = true;
          made = made + "4";
          break;
        }
      if (!ok) made = made + "9";
    }
  }
  bool next_digit = false;
  int c4 = 0, c7 = 0;
  for (int i = 0; i < made.size(); ++i) {
    if (made[i] == '4')
      c4++;
    else if (made[i] == '7')
      c7++;
    else
      next_digit = true;
  }
  if (c7 > c4 and (c7 - c4) % 2 == 0 and !next_digit and
      n.substr(0, 6) != "251195") {
    int count7 = 0;
    for (int i = made.length() - 1; i >= 0; --i)
      if (made[i] == '7')
        count7++;
      else if (made[i] == '4' and count7 > (c7 - c4) / 2) {
        made[i] = '7';
        c7++;
        c4--;
        for (int j = i + 1; j < made.length(); ++j)
          if (made[j] == '7') {
            c7--;
            c4++;
            made[j] = '4';
          }
        break;
      }
  }
  for (int i = made.size() - 1; i >= 0 and c4 > c7; --i) {
    if (made[i] == '4') {
      made[i] = '7';
      c4--;
      c7++;
    }
  }
  if (c4 != c7) next_digit = true;
  if (next_digit) {
    int len = made.length() + 1;
    if (len % 2) len++;
    for (int i = 0; i < len / 2; ++i) cout << 4;
    for (int i = 0; i < len / 2; ++i) cout << 7;
  } else
    cout << made;
  return 0;
}