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>
char s[100010];
int main() {
  int i, j, k, l, m, n, p, q, y, z;
  scanf("%s", s);
  m = strlen(s);
  if (m % 2 == 1) {
    for (i = 0; i < (m + 1) / 2; i++) printf("4");
    for (i = 0; i < (m + 1) / 2; i++) printf("7");
    printf("\n");
    return 0;
  }
  if (s[0] == '1' || s[0] == '2' || s[0] == '3') {
    for (i = 0; i < m / 2; i++) printf("4");
    for (i = 0; i < m / 2; i++) printf("7");
    printf("\n");
    return 0;
  }
  if (s[0] == '8' || s[0] == '9') {
    for (i = 0; i <= m / 2; i++) printf("4");
    for (i = 0; i <= m / 2; i++) printf("7");
    printf("\n");
    return 0;
  }
  if (s[0] == '5' || s[0] == '6') {
    printf("7");
    for (i = 0; i < m / 2; i++) printf("4");
    for (i = 0; i < m / 2 - 1; i++) printf("7");
    printf("\n");
    return 0;
  }
  if (s[0] == '4') {
    j = 0;
    k = 0;
    l = 0, p = 0, q = 0;
    for (i = 0; i < m; i++) {
      if (s[i] == '4')
        k++;
      else if (s[i] == '7')
        l++;
      else if (s[i] == '0' || s[i] == '1' || s[i] == '2' || s[i] == '3') {
        j = 1;
        p = i;
        break;
      } else if (s[i] == '5' || s[i] == '6') {
        j = 2;
        p = i;
        break;
      } else {
        j = 3;
        p = i;
        break;
      }
      if (k == m / 2 || l == m / 2) {
        p = i;
        break;
      }
    }
    if (j == 1) {
      for (i = 0; i < p; i++) printf("%c", s[i]);
      for (i = 0; i < m / 2 - k; i++) printf("4");
      for (i = 0; i < m / 2 - l; i++) printf("7");
      printf("\n");
      return 0;
    } else if (j == 2) {
      for (i = 0; i < p; i++) printf("%c", s[i]);
      printf("7");
      for (i = 0; i < m / 2 - k; i++) printf("4");
      for (i = 0; i < m / 2 - l - 1; i++) printf("7");
      printf("\n");
      return 0;
    } else if (j == 3) {
      if (k == 1) {
        printf("7");
        for (i = 0; i < m / 2; i++) printf("4");
        for (i = 0; i < m / 2 - 1; i++) printf("7");
        printf("\n");
        return 0;
      } else {
        for (z = p - 1; z; z--)
          if (s[z] == '4') break;
        k = 0;
        l = 0;
        for (i = 0; i < z; i++) {
          if (s[i] == '4') k++;
          if (s[i] == '7') l++;
          printf("%c", s[i]);
        }
        printf("7");
        for (i = 0; i < m / 2 - k; i++) printf("4");
        for (i = 0; i < m / 2 - l - 1; i++) printf("7");
        printf("\n");
        return 0;
      }
    } else {
      if (k == m / 2) {
        y = 0;
        for (i = p + 1; i < m; i++) {
          if (s[i] < '7') break;
          if (s[i] > '7') {
            y = 1;
            break;
          }
        }
        if (y == 0) {
          for (i = 0; i <= p; i++) printf("%c", s[i]);
          for (i = p + 1; i < m; i++) printf("7");
          printf("\n");
          return 0;
        } else {
          for (i = 0; i < p; i++) printf("%c", s[i]);
          printf("7");
          printf("4");
          for (i = p + 2; i < m; i++) printf("7");
          printf("\n");
          return 0;
        }
      } else {
        y = 0;
        for (i = p + 1; i < m; i++) {
          if (s[i] < '4') break;
          if (s[i] > '4') {
            y = 1;
            break;
          }
        }
        if (y == 0) {
          for (i = 0; i <= p; i++) printf("%c", s[i]);
          for (i = p + 1; i < m; i++) printf("4");
          printf("\n");
          return 0;
        } else {
          if (k == 1) {
            printf("7");
            for (i = 0; i < m / 2; i++) printf("4");
            for (i = 0; i < m / 2 - 1; i++) printf("7");
            printf("\n");
            return 0;
          } else {
            for (z = p - 1; z; z--)
              if (s[z] == '4') break;
            k = 0, l = 0;
            for (i = 0; i < z; i++) {
              if (s[i] == '4') k++;
              if (s[i] == '7') l++;
              printf("%c", s[i]);
            }
            printf("7");
            for (i = 0; i < m / 2 - k; i++) printf("4");
            for (i = 0; i < m / 2 - l - 1; i++) printf("7");
            printf("\n");
            return 0;
          }
        }
      }
    }
  } else {
    j = 0;
    k = 0;
    l = 0, p = 0, q = 0;
    for (i = 0; i < m; i++) {
      if (s[i] == '4')
        k++;
      else if (s[i] == '7')
        l++;
      else if (s[i] == '0' || s[i] == '1' || s[i] == '2' || s[i] == '3') {
        j = 1;
        p = i;
        break;
      } else if (s[i] == '5' || s[i] == '6') {
        j = 2;
        p = i;
        break;
      } else {
        j = 3;
        p = i;
        break;
      }
      if (k == m / 2 || l == m / 2) {
        p = i;
        break;
      }
    }
    if (j == 1) {
      for (i = 0; i < p; i++) printf("%c", s[i]);
      for (i = 0; i < m / 2 - k; i++) printf("4");
      for (i = 0; i < m / 2 - l; i++) printf("7");
      printf("\n");
      return 0;
    } else if (j == 2) {
      for (i = 0; i < p; i++) printf("%c", s[i]);
      printf("7");
      for (i = 0; i < m / 2 - k; i++) printf("4");
      for (i = 0; i < m / 2 - l - 1; i++) printf("7");
      printf("\n");
      return 0;
    } else if (j == 3) {
      if (k == 0) {
        for (i = 0; i <= m / 2; i++) printf("4");
        for (i = 0; i <= m / 2; i++) printf("7");
        printf("\n");
        return 0;
      } else {
        for (z = p - 1; z; z--)
          if (s[z] == '4') break;
        k = 0;
        l = 0;
        for (i = 0; i < z; i++) {
          if (s[i] == '4') k++;
          if (s[i] == '7') l++;
          printf("%c", s[i]);
        }
        printf("7");
        for (i = 0; i < m / 2 - k; i++) printf("4");
        for (i = 0; i < m / 2 - l - 1; i++) printf("7");
        printf("\n");
        return 0;
      }
    } else {
      if (k == m / 2) {
        y = 0;
        for (i = p + 1; i < m; i++) {
          if (s[i] < '7') break;
          if (s[i] > '7') {
            y = 1;
            break;
          }
        }
        if (y == 0) {
          for (i = 0; i <= p; i++) printf("%c", s[i]);
          for (i = p + 1; i < m; i++) printf("7");
          printf("\n");
          return 0;
        } else {
          for (i = 0; i < p; i++) printf("%c", s[i]);
          printf("7");
          printf("4");
          for (i = p + 2; i < m; i++) printf("7");
          printf("\n");
          return 0;
        }
      } else {
        y = 0;
        for (i = p + 1; i < m; i++) {
          if (s[i] < '4') break;
          if (s[i] > '4') {
            y = 1;
            break;
          }
        }
        if (y == 0) {
          for (i = 0; i <= p; i++) printf("%c", s[i]);
          for (i = p + 1; i < m; i++) printf("4");
          printf("\n");
          return 0;
        } else {
          if (k == 0) {
            for (i = 0; i <= m / 2; i++) printf("4");
            for (i = 0; i <= m / 2; i++) printf("7");
            printf("\n");
            return 0;
          } else {
            for (z = p - 1; z; z--)
              if (s[z] == '4') break;
            k = 0, l = 0;
            for (i = 0; i < z; i++) {
              if (s[i] == '4') k++;
              if (s[i] == '7') l++;
              printf("%c", s[i]);
            }
            printf("7");
            for (i = 0; i < m / 2 - k; i++) printf("4");
            for (i = 0; i < m / 2 - l - 1; i++) printf("7");
            printf("\n");
            return 0;
          }
        }
      }
    }
  }
  return 0;
}