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 a[100002], c[100002];
int main() {
  int i, j, k1 = 0, k2 = 0, n;
  a[0] = 0;
  string s;
  cin >> s;
  n = s.length();
  if (n % 2 == 1) {
    for (i = 1; i <= (n + 1) / 2; i++) cout << 4;
    for (i = 1; i <= (n + 1) / 2; i++) cout << 7;
  } else {
    for (i = 1; i <= n; i++) {
      a[i] = (int)(s[i - 1] - 48);
      c[i] = a[i];
    }
    for (i = n; i >= 1; i--)
      if (a[i] > 7) {
        a[i] = 4;
        a[i - 1]++;
      } else if (a[i] > 4) {
        a[i] = 7;
      } else
        a[i] = 4;
    for (i = 1; i <= n; i++)
      if (a[i] > c[i]) {
        for (j = i + 1; j <= n; j++) a[j] = 4;
        break;
      }
    if (a[0] > 0) {
      for (i = 1; i <= (n + 2) / 2; i++) cout << 4;
      for (i = 1; i <= (n + 2) / 2; i++) cout << 7;
    } else {
      for (i = 1; i <= n; i++)
        if (a[i] == 4)
          k1++;
        else
          k2++;
      if (k1 > k2) {
        i = n;
        while (k1 > k2) {
          if (a[i] == 4) {
            a[i] = 7;
            k1--;
            k2++;
          }
          i--;
        }
        for (i = 1; i <= n; i++) cout << a[i];
      } else if (k1 == k2)
        for (i = 1; i <= n; i++) cout << a[i];
      else {
        int p = 0, p1 = 0, m = k2 - k1 + 2;
        for (i = n; i >= 1; i--) {
          if (m <= 0) {
            break;
          } else if (a[i] == 7)
            m -= 2;
        }
        for (j = i; j >= 1; j--)
          if (a[j] == 4) {
            a[j] = 7;
            for (i = j + 1; i <= n; i++) a[i] = 4;
            break;
          }
        if (j != 0) {
          k1 = 0;
          k2 = 0;
          for (i = 1; i <= n; i++)
            if (a[i] == 4)
              k1++;
            else
              k2++;
          i = n;
          while (k1 > k2) {
            if (a[i] == 4) {
              a[i] = 7;
              k1--;
              k2++;
            }
            i--;
          }
          for (i = 1; i <= n; i++) cout << a[i];
        } else {
          for (i = 1; i <= (n + 2) / 2; i++) cout << 4;
          for (i = 1; i <= (n + 2) / 2; i++) cout << 7;
        }
      }
    }
  }
  return 0;
}