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 inp;
string str(int a, char b) {
  if (a < 0) {
    cout << inp << endl;
    exit(0);
  }
  return string(a, b);
}
bool av(string a) {
  int c1 = 0, c2 = 0;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] != '4' && a[i] != '7') return 0;
    if (a[i] == '4')
      c1++;
    else
      c2++;
  }
  return c1 == c2;
}
string first(int a) {
  string res;
  for (int i = 0; i < a / 2; i++) res += '4';
  for (int i = 0; i < a / 2; i++) res += '7';
  return res;
}
string last(int a) {
  string res;
  for (int i = 0; i < a / 2; i++) res += '7';
  for (int i = 0; i < a / 2; i++) res += '4';
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> inp;
  if (inp.size() % 2 == 1) {
    cout << first(inp.size() + 1) << endl;
    return 0;
  }
  if (inp > last(inp.size())) {
    cout << first(inp.size() + 2) << endl;
    return 0;
  }
  if (av(inp)) {
    cout << inp << endl;
    return 0;
  }
  int c1 = 0, c2 = 0;
  int t = inp.size() / 2;
  for (int i = 0; i < inp.size(); i++) {
    if (inp[i] != '4' && inp[i] != '7') {
      if (inp[i] < '4' && c1 < t) {
        cout << inp.substr(0, i) + str(t - c1, '4') + str(t - c2, '7') << endl;
        return 0;
      }
      if (inp[i] < '7' && c2 < t) {
        cout << inp.substr(0, i) + '7' + str(t - c1, '4') + str(t - c2 - 1, '7')
             << endl;
        return 0;
      }
      for (int j = i - 1; j >= 0; j--) {
        if (inp[j] == '4') {
          cout << inp.substr(0, j) + '7' + str(t - c1 + 1, '4') +
                      str(t - c2 - 1, '7')
               << endl;
          return 0;
        } else
          c2--;
      }
    }
    if (inp[i] == '4' && c1 == t) {
      cout << inp.substr(0, i) + str(t - c2, '7') << endl;
      return 0;
    }
    if (inp[i] == '7' && c2 == t) {
      for (int j = i - 1; j >= 0; j--) {
        if (inp[j] == '4' && c2 != t) {
          cout << inp.substr(0, j) + '7' + str(t - c1 + 1, '4') +
                      str(t - c2 - 1, '7')
               << endl;
          return 0;
        } else if (inp[j] == '7')
          c2--;
        else if (inp[j] == '4')
          c1--;
      }
    }
    if (inp[i] == '4')
      c1++;
    else
      c2++;
  }
  return 0;
}