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>
const int N = 1e5 + 50;
char s[N];
int lens, ok;
int ws[N];
void dfs(int now, int _4, int _7) {
  if (now == lens) {
    for (int i = 0; i < lens; i++) putchar(ws[i] + 48);
    ok = 1;
    return;
  }
  if (!ok)
    if (s[now] < '4') {
      if (_4)
        ws[now] = 4, _4--;
      else
        ws[now] = 7, _7--;
      for (int i = 0; i <= now; i++) putchar(ws[i] + 48);
      for (int i = 1; i <= _4; i++) putchar('4');
      for (int i = 1; i <= _7; i++) putchar('7');
      ok = 1;
      return;
    }
  if (!ok)
    if (s[now] == '4') {
      if (_4) {
        ws[now] = 4, _4--;
        dfs(now + 1, _4, _7);
        _4++;
      }
      if (!ok)
        if (_7) {
          ws[now] = 7, _7--;
          for (int i = 0; i <= now; i++) putchar(ws[i] + 48);
          for (int i = 1; i <= _4; i++) putchar('4');
          for (int i = 1; i <= _7; i++) putchar('7');
          ok = 1;
          return;
        } else
          return;
    }
  if (!ok)
    if (s[now] < '7') {
      if (_7) {
        ws[now] = 7, _7--;
        for (int i = 0; i <= now; i++) putchar(ws[i] + 48);
        for (int i = 1; i <= _4; i++) putchar('4');
        for (int i = 1; i <= _7; i++) putchar('7');
        ok = 1;
        return;
      } else
        return;
    }
  if (!ok)
    if (s[now] == '7') {
      if (_7) {
        ws[now] = 7, _7--;
        dfs(now + 1, _4, _7);
        _7++;
      } else
        return;
    }
  if (!ok)
    if (s[now] > '7') return;
  return;
}
int main() {
  scanf("%s", s);
  lens = strlen(s);
  if (lens & 1) {
    for (int i = 0; i <= lens / 2; i++) putchar('4');
    for (int i = lens / 2; i < lens; i++) putchar('7');
    return 0;
  }
  if (s[0] < '4') {
    for (int i = 0; i < lens / 2; i++) putchar('4');
    for (int i = lens / 2; i < lens; i++) putchar('7');
    return 0;
  }
  if (s[0] == '4') {
    ws[0] = 4;
    dfs(1, lens / 2 - 1, lens / 2);
    if (!ok) {
      putchar('7');
      for (int i = 0; i < lens / 2; i++) putchar('4');
      for (int i = lens / 2 + 1; i < lens; i++) putchar('7');
      return 0;
    }
    return 0;
  }
  if (s[0] < '7') {
    putchar('7');
    for (int i = 0; i < lens / 2; i++) putchar('4');
    for (int i = lens / 2 + 1; i < lens; i++) putchar('7');
    return 0;
  }
  if (s[0] == '7') {
    ws[0] = 7;
    dfs(1, lens / 2, lens / 2 - 1);
    if (!ok) {
      putchar('4');
      for (int i = 0; i < lens / 2; i++) putchar('4');
      for (int i = lens / 2; i < lens; i++) putchar('7');
      putchar('7');
      return 0;
    }
    return 0;
  }
  if (s[0] > '7') {
    putchar('4');
    for (int i = 0; i < lens / 2; i++) putchar('4');
    for (int i = lens / 2; i < lens; i++) putchar('7');
    putchar('7');
    return 0;
  }
}