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;
char s[100010];
int n;
bool v[100010];
char a[100010];
int t = 0;
void tle() {
  while (1)
    ;
}
bool ff() {
  for (int i = 0; i < t / 2; i++)
    if (a[i] < '7') return 1;
  for (int i = t / 2; i < t; i++)
    if (a[i] > '4') return 0;
  return 1;
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (int i = n - 1; i >= 0; i--)
    if (s[i] > '7')
      v[i] = 1;
    else if (s[i] < '7')
      v[i] = 0;
    else if (v[i + 1])
      v[i] = 1;
  if (v[0]) {
    for (int i = 0; i <= n; i++) a[t++] = '4';
  } else {
    bool F = 0;
    for (int i = 0; i < n; i++)
      if (F)
        a[t++] = '4';
      else if (s[i] < '4') {
        a[t++] = '4';
        F = 1;
      } else if (s[i] == '4') {
        if (v[i + 1])
          a[t++] = '7', F = 1;
        else
          a[t++] = '4';
      } else if (s[i] < '7') {
        a[t++] = '7';
        F = 1;
      } else if (s[i] == '7') {
        if (v[i + 1])
          tle();
        else
          a[t++] = '7';
      } else
        tle();
  }
  if (t & 1) {
    t++;
    for (int i = 0; i < t / 2; i++) a[i] = '4';
    for (int i = t / 2; i < t; i++) a[i] = '7';
    printf("%s\n", a);
    return 0;
  }
  if (!ff()) {
    t++;
    for (int i = 0; i < t; i++) a[i] = '4';
  }
  if (t & 1) {
    t++;
    for (int i = 0; i < t / 2; i++) a[i] = '4';
    for (int i = t / 2; i < t; i++) a[i] = '7';
    printf("%s\n", a);
    return 0;
  }
  int z = 0;
  for (int i = 0; i < t; i++)
    if (a[i] == '4')
      z++;
    else
      z--;
  if (z == 0) {
    printf("%s\n", a);
    return 0;
  }
  for (int i = t - 1; i >= 0;) {
    if (z == 0) break;
    if (z > 0) {
      if (a[i] == '4') a[i] = '7', z -= 2;
      i--;
    } else if (z < 0) {
      if (a[i] == '7') {
        int j = i;
        while (a[j] == '7') a[j] = '4', z += 2, j--;
        a[j] = '7', z -= 2;
        if (z < 0) i = j;
        if (z > 0) i = t;
      } else
        i--;
    }
  }
  printf("%s\n", a);
  return 0;
}