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;
long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); }
int main() {
  string str, ans;
  int n, idx, a, b;
  cin >> str, n = str.size();
  if (n % 2 || str > (string(n >> 1, '7') + string(n >> 1, '4')))
    cout << string(n / 2 + 1, '4') + string(n / 2 + 1, '7') << endl;
  else {
    if (n & 1) n++, str += '0';
    ans = string(n >> 1, '4') + string(n >> 1, '7'), idx = a = b = n >> 1;
    for (long long i = 0; i < int(n); i++)
      if (str[i] == '4' || str[i] == '7')
        ans[i] = str[i];
      else if (str[i] < '4') {
        ans[i] = '4', idx = i + 1;
        for (long long j = 0; j < int(i + 1); j++) ans[j] == '4' ? a-- : b--;
        while (a) a--, ans[idx++] = '4';
        while (b) b--, ans[idx++] = '7';
        break;
      } else if (str[i] < '7') {
        ans[i] = '7', idx = i + 1;
        for (long long j = 0; j < int(i + 1); j++) ans[j] == '4' ? a-- : b--;
        while (a) a--, ans[idx++] = '4';
        while (b) b--, ans[idx++] = '7';
        break;
      } else {
        for (long long j = i - 1; j > -1; j--)
          if (ans[j] == '4') {
            ans[j] = '7';
            for (long long k = 0; k < int(j + 1); k++)
              ans[k] == '4' ? a-- : b--;
            for (long long k = j + 1; k < n; k++)
              if (a)
                ans[k] = '4', a--;
              else
                ans[k] = '7';
            break;
          }
        break;
      }
    a = b = 0;
    for (long long i = 0; i < int(n); i++) ans[i] == '4' ? a++ : b++;
    if (a != b)
      if (a < b) {
        int tmp = n / 2 - a + 1, now = 0;
        for (long long i = n - 1; i > -1; i--)
          if (ans[i] == '7')
            now++;
          else if (now >= tmp) {
            ans[i] = '7';
            for (long long j = i + 1; j < n; j++)
              if (ans[j] == '7' && tmp)
                tmp--, ans[j] = '4';
              else if (!tmp)
                break;
            break;
          }
      } else {
        int tmp = n / 2 - b;
        for (long long i = n - 1; i > -1; i--)
          if (ans[i] == '4' && tmp)
            tmp--, ans[i] = '7';
          else if (!tmp)
            break;
      }
  hell:
    cout << ans << endl;
  }
  return 0;
}