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;
const int nmax = 100100;
char s[nmax];
char t[nmax];
int n;
void madeTemplate(int pos, int c4, int c7) {
  if (pos < 0) {
    while (true)
      ;
  }
  t[pos + c4 + c7] = 0;
  while (c4) {
    t[pos] = '4';
    ++pos;
    --c4;
  }
  while (c7) {
    t[pos] = '7';
    ++pos;
    --c7;
  }
}
void sevOver(int i, int c4, int c7) {
  for (int j = i - 1; j >= 0; --j) {
    if (t[j] == '7') {
      ++c7;
    }
    if (t[j] == '4') {
      if (c7) {
        t[j] = '7';
        c4 = c7 = n / 2;
        for (int k = 0; k <= j; ++k) {
          if (t[k] == '4') --c4;
          if (t[k] == '7') --c7;
        }
        madeTemplate(j + 1, c4, c7);
        return;
      }
    }
  }
}
void hcase() {
  madeTemplate(0, n / 2, n / 2);
  if (strcmp(s, t) <= 0) {
    return;
  }
  reverse(t, t + n);
  if (strcmp(s, t) > 0) {
    n += 2;
    madeTemplate(0, n / 2, n / 2);
    return;
  }
  int c4 = n / 2;
  int c7 = n / 2;
  for (int i = 0; i < n; ++i) {
    t[i] = s[i];
    if (s[i] < '4') {
      if (c4) {
        t[i] = '4';
        --c4;
      } else {
        t[i] = '7';
        --c7;
      }
      madeTemplate(i + 1, c4, c7);
      break;
    }
    if (s[i] == '4') {
      if (c4) {
        --c4;
        continue;
      } else {
        t[i] = '7';
        --c7;
        madeTemplate(i + 1, c4, c7);
        break;
      }
    }
    if (s[i] < '7') {
      t[i] = '7';
      if (c7) {
        --c7;
        madeTemplate(i + 1, c4, c7);
      } else {
        sevOver(i, c4, c7);
      }
      break;
    }
    if (s[i] == '7') {
      if (c7) {
        --c7;
        continue;
      } else {
        sevOver(i, c4, c7);
        return;
      }
    }
    if (s[i] > '7') {
      sevOver(i, c4, c7);
      return;
    }
  }
}
int main() {
  gets(s);
  n = (int)strlen(s);
  if (n > nmax) {
    while (true)
      ;
  }
  if (n & 1) {
    madeTemplate(0, (n + 1) / 2, (n + 1) / 2);
  } else {
    hcase();
  }
  puts(t);
  return 0;
}