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 str1[1000000];
char ans[1000000];
int n;
bool chek() {
  int c1, c2;
  c1 = 0;
  c2 = 0;
  for (int i = 0; i < n; i++) {
    if (str1[i] == '4')
      c1++;
    else if (str1[i] == '7')
      c2++;
    else
      return false;
  }
  return (c1 == c2);
}
bool banano(int pos, int c1, int c2, int l) {
  if (pos == n) {
    if (c1 == c2 && c1 == 0 && l == 1) return true;
    return false;
  }
  if (l == 1) {
    int i = pos;
    while (c1--) ans[i] = '4', i++;
    while (c2--) ans[i] = '7', i++;
    ans[i] = 0;
    return true;
  }
  if (str1[pos] < '4') {
    if (c1 > 0) {
      ans[pos] = '4';
      if (banano(pos + 1, c1 - 1, c2, 1)) return true;
      return false;
    }
    if (c2 > 0) {
      ans[pos] = '7';
      if (banano(pos + 1, c1, c2 - 1, 1)) return true;
      return false;
    }
  } else if (str1[pos] == '4') {
    if (c1 > 0) {
      ans[pos] = '4';
      if (banano(pos + 1, c1 - 1, c2, 0)) return true;
    }
    if (c2 > 0) {
      ans[pos] = '7';
      if (banano(pos + 1, c1, c2 - 1, 1)) return true;
      return false;
    }
  } else if (str1[pos] < '7') {
    if (c2 > 0) {
      ans[pos] = '7';
      if (banano(pos + 1, c1, c2 - 1, 1)) return true;
      return false;
    }
    return false;
  } else if (str1[pos] == '7') {
    if (c2 > 0) {
      ans[pos] = '7';
      if (banano(pos + 1, c1, c2 - 1, 0)) return true;
      return false;
    }
  }
  return false;
}
int main() {
  scanf("%s", &str1);
  n = strlen(str1);
  if (n % 2 == 1) {
    for (int i = 1; i <= (n + 1) / 2; i++) printf("4");
    for (int i = 1; i <= (n + 1) / 2; i++) printf("7");
    printf("\n");
    return 0;
  }
  if (chek()) {
    printf("%s\n", str1);
    return 0;
  }
  if (banano(0, n / 2, n / 2, 0)) {
    printf("%s\n", ans);
    return 0;
  }
  for (int i = 1; i <= (n / 2) + 1; i++) printf("4");
  for (int i = 1; i <= (n / 2) + 1; i++) printf("7");
  printf("\n");
  return 0;
}