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 = 100500;
const unsigned long long PW = 337;
unsigned long long pw[N], hs[N], ht[N];
void calcPW() {
  pw[0] = 1;
  for (int i = 1; i < N; i++) {
    pw[i] = pw[i - 1] * PW;
  }
}
void calcH(char* s, unsigned long long* h, int n) {
  h[0] = 0;
  for (int i = 1; i <= n; i++) {
    h[i] = h[i - 1] + s[i - 1] * pw[i - 1];
  }
}
int sgn(int x) { return x < 0 ? -1 : (x > 0 ? 1 : 0); }
unsigned long long getHash(unsigned long long* h, int l, int r) {
  return (h[r] - h[l - 1]) * pw[N - l - 3];
}
int lcp(unsigned long long* h1, unsigned long long* h2, int l1, int r1, int l2,
        int r2) {
  int l = 0, r = min(r1 - l1 + 1, r2 - l2 + 1) + 1;
  while (r - l > 1) {
    int mid = (l + r) >> 1;
    if (getHash(h1, l1, l1 + mid - 1) == getHash(h2, l2, l2 + mid - 1))
      l = mid;
    else
      r = mid;
  }
  return l;
}
int compare(char* s1, unsigned long long* h1, char* s2, unsigned long long* h2,
            int l1, int r1, int l2, int r2) {
  int comm = lcp(h1, h2, l1, r1, l2, r2);
  char a = (l1 + comm == r1 + 1 ? '\0' : s1[l1 + comm - 1]);
  char b = (l2 + comm == r2 + 1 ? '\0' : s2[l2 + comm - 1]);
  return sgn((int)a - (int)b);
}
char s[N];
char t[N];
int n, half, half2;
void getLR47(int k4, int k7, int& l, int& r) {
  l = half - k7;
  r = l + (k4 + k7) - 1;
  l++, r++;
}
int main() {
  calcPW();
  scanf("%s", s);
  n = strlen(s);
  half = ((n + 1) / 2);
  half2 = half * 2;
  for (int i = 0; i < half; i++) {
    t[i] = '7';
    t[i + half] = '4';
  }
  calcH(s, hs, n);
  calcH(t, ht, half2);
  if (n % 2 == 1) {
    n++;
    for (int i = 0; i < n / 2; i++) {
      putchar('4');
    }
    for (int i = 0; i < n / 2; i++) {
      putchar('7');
    }
    puts("");
    exit(0);
  }
  int l, r;
  getLR47(n / 2, n / 2, l, r);
  if (compare(s, hs, t, ht, 1, n, l, r) == 1) {
    n += 2;
    n++;
    for (int i = 0; i < n / 2; i++) {
      putchar('4');
    }
    for (int i = 0; i < n / 2; i++) {
      putchar('7');
    }
    puts("");
    exit(0);
  }
  int k4 = n / 2, k7 = n / 2;
  for (int i = 0; i < n; i++) {
    if (s[i] == '4' && k4 > 0) {
      getLR47(k4 - 1, k7, l, r);
      if (compare(s, hs, t, ht, i + 2, n, l, r) <= 0) {
        s[i] = '4';
        k4--;
        continue;
      }
    }
    if (s[i] == '7' && k7 > 0) {
      getLR47(k4, k7 - 1, l, r);
      if (compare(s, hs, t, ht, i + 2, n, l, r) <= 0) {
        s[i] = '7';
        k7--;
        continue;
      }
    }
    if (s[i] < '4') {
      for (int j = i; j < n; j++) {
        if (k4 > 0)
          s[j] = '4', k4--;
        else
          s[j] = '7', k7--;
      }
    } else if (s[i] < '7') {
      s[i] = '7', k7--;
      for (int j = i + 1; j < n; j++) {
        if (k4 > 0)
          s[j] = '4', k4--;
        else
          s[j] = '7', k7--;
      }
    }
    break;
  }
  puts(s);
  puts("");
}