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];
char s2[100010];
char r[100010];
int n;
inline bool menor(char *s1, char *s2) {
  for (int i = 0; s1[i] != '\0'; i++)
    if (s1[i] < s2[i])
      return true;
    else if (s1[i] > s2[i])
      return false;
  return false;
}
bool vai(int u, int saldo, bool ve) {
  if (u == n) return saldo == 0;
  if ((saldo >= 0 ? saldo : -(saldo)) > (n - u)) return false;
  bool pode4 = true;
  if (ve) {
    if ('4' < s[u]) pode4 = false;
  }
  if (pode4) {
    r[u] = '4';
    if (vai(u + 1, saldo - 1, (ve && s[u] == '4') ? true : false)) return true;
  }
  bool pode7 = true;
  if (ve) {
    if ('7' < s[u]) pode7 = false;
  }
  if (pode7) {
    r[u] = '7';
    if (vai(u + 1, saldo + 1, (ve && s[u] == '7') ? true : false)) return true;
  }
  return false;
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  if ((n % 2) == 1) {
    n++;
    for (int i = 0; i < n / 2; i++) printf("4");
    for (int i = 0; i < n / 2; i++) printf("7");
    printf("\n");
    return 0;
  }
  for (int i = 0; i < n / 2; i++) s2[i] = '4';
  for (int i = n / 2; i < n; i++) s2[i] = '7';
  s2[n] = '\0';
  if (!menor(s2, s)) {
    for (int i = 0; i < n / 2; i++) printf("4");
    for (int i = 0; i < n / 2; i++) printf("7");
    printf("\n");
    return 0;
  }
  for (int i = 0; i < n / 2; i++) s2[i] = '7';
  for (int i = n / 2; i < n; i++) s2[i] = '4';
  s2[n] = '\0';
  if (menor(s2, s)) {
    n += 2;
    for (int i = 0; i < n / 2; i++) printf("4");
    for (int i = 0; i < n / 2; i++) printf("7");
    printf("\n");
    return 0;
  }
  vai(0, 0, true);
  for (int i = 0; i < n; i++) printf("%c", r[i]);
  printf("\n");
  return 0;
}