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 N = int(3e5), mod = int(1e9) + 7;
char second[N];
int n;
int a[N], b[N];
int main() {
  scanf("%s", second + 1);
  n = strlen(second + 1);
  int ok = 1;
  for (int i = 1; i <= n; i++) {
    if (second[i] != '7') {
      if (second[i] > '7') ok = 0;
      break;
    }
  }
  if (n % 2 == 0) {
    for (int i = 1; i <= n / 2; i++) {
      if (second[i] != '7') {
        if (second[i] > '7')
          ok = 0;
        else
          ok = 2;
        break;
      }
    }
    if (ok == 1) {
      for (int i = n / 2 + 1; i <= n; i++) {
        if (second[i] != '4') {
          if (second[i] > '4')
            ok = 0;
          else
            ok = 2;
          break;
        }
      }
    }
  }
  if ((n & 1) || !ok) {
    int len = n / 2 + 1;
    for (int i = 1; i <= len; i++) {
      printf("4");
    }
    for (int i = 1; i <= len; i++) {
      printf("7");
    }
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    a[i] = a[i - 1];
    b[i] = b[i - 1];
    if (second[i] == '4') a[i]++;
    if (second[i] == '7') b[i]++;
  }
  if (a[n] == n / 2 && b[n] == n / 2) {
    printf("%s", second + 1);
    return 0;
  }
  int mx = -1, cur = 0;
  int c4 = 0, c7 = 0;
  for (int i = 1; i <= n; i++) {
    int n4 = a[i - 1];
    int n7 = b[i - 1];
    if (n4 + n7 != i - 1) break;
    bool ok = 1;
    if (second[i] < '4') {
      n4++;
      if (n4 <= n / 2 && n7 <= n / 2) {
        mx = i - 1;
        cur = 4;
        c4 = n4;
        c7 = n7;
        ok = 0;
      }
    }
    if (ok && second[i] < '7') {
      n7++;
      if (n4 <= n / 2 && n7 <= n / 2) {
        mx = i - 1;
        cur = 7;
        c4 = n4;
        c7 = n7;
      }
    }
  }
  for (int i = 1; i <= mx; i++) printf("%c", second[i]);
  printf("%d", cur);
  while (c4 < n / 2) {
    printf("4");
    c4++;
  }
  while (c7 < n / 2) {
    printf("7");
    c7++;
  }
  return 0;
}