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 num;
int len;
string big, sma;
bool bigThan(string a, string b) {
  if (a.size() > b.size())
    return true;
  else if (a.size() < b.size())
    return false;
  else {
    for (int i = 0; i < a.size(); ++i)
      if (((int)a[i] - (int)b[i]) > 0)
        return true;
      else if (((int)a[i] < (int)b[i]))
        return false;
  }
  return false;
}
int main() {
  cin >> num;
  len = num.size() % 2 == 0 ? num.size() : num.size() + 1;
  for (int i = 0; i < len / 2; ++i) {
    big += '7';
    sma += '4';
  }
  for (int i = 0; i < len / 2; ++i) {
    big += '4';
    sma += '7';
  }
  if (bigThan(num, big)) {
    cout << '4' << sma << '7' << endl;
  } else if (bigThan(sma, num)) {
    cout << sma << endl;
  } else {
    int index = -1;
    char tar = '7';
    for (int i = 0; i < num.size(); ++i) {
      if (num[i] != '4' && num[i] != '7') {
        index = i;
        tar = num[i];
        break;
      }
    }
    if (tar == '7') {
    } else if (tar > '7') {
      for (int i = index - 1; i >= 0; --i) {
        if (num[i] == '7') {
          num[i] = '4';
        } else if (num[i] == '4') {
          num[i] = '7';
          break;
        }
      }
      for (int i = index; i < num.size(); ++i) {
        num[i] = '4';
      }
    } else if (tar > '4') {
      num[index] = '7';
      for (int i = index + 1; i < num.size(); ++i) num[i] = '4';
    } else {
      for (int i = index; i < num.size(); ++i) num[i] = '4';
    }
    int c7 = 0, c4 = 0;
    for (int i = 0; i < num.size(); ++i) {
      if (num[i] == '7')
        ++c7;
      else if (num[i] == '4')
        ++c4;
    }
    if (c4 < c7) {
      for (int i = num.size() - 1; i >= 0; --i) {
        if (num[i] != '4') {
          num[i] = '4';
          c4++;
          c7--;
          if (c4 == c7) break;
        }
      }
      for (int i = num.size() - 1; i >= 0; --i) {
        if (num[i] == '7' && num[i - 1] == '4') {
          num[i] = '4';
          num[i - 1] = '7';
          for (int j = i + 1; j < num.size(); ++j) {
            if (num[j] != '4') {
              num[j] = '4';
              c4++;
              c7--;
            }
          }
          break;
        }
      }
    }
    if (c4 > c7)
      for (int i = num.size() - 1; i >= 0; --i) {
        if (num[i] != '7') {
          num[i] = '7';
          c4--;
          c7++;
          if (c4 == c7) break;
        }
      }
    cout << num << endl;
  }
}