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;
string n;
char ans[100005];
int four;
int seven;
bool vec;
bool danger;
void dfs(int x) {
  if (vec == true) return;
  if (four == seven && x == (int)n.length()) {
    vec = true;
    return;
  }
  if (x == (int)n.length()) return;
  if (danger == true) {
    if (n[x] > '7')
      return;
    else if (n[x] == '7') {
      ans[x] = '7';
      seven++;
      dfs(x + 1);
      if (vec == true) return;
      seven--;
    } else if (n[x] > '4') {
      danger = false;
      ans[x] = '7';
      seven++;
      dfs(x + 1);
      if (vec == true) return;
      seven--;
      danger = true;
    } else if (n[x] == '4') {
      ans[x] = '4';
      four++;
      dfs(x + 1);
      if (vec == true) return;
      four--;
      ans[x] = '7';
      danger = false;
      seven++;
      dfs(x + 1);
      if (vec == true) return;
      seven--;
      danger = true;
    } else {
      ans[x] = '4';
      danger = false;
      four++;
      dfs(x + 1);
      if (vec == true) return;
      four--;
      danger = true;
      ans[x] = '7';
      danger = false;
      seven++;
      dfs(x + 1);
      if (vec == true) return;
      danger = true;
      seven--;
    }
  } else {
    if ((seven - four + (int)n.length() - x) % 2 == 0 &&
        (seven - four + (int)n.length() - x) >= 0 &&
        (four + (int)n.length() - x - seven) % 2 == 0 &&
        (four + (int)n.length() - x - seven) >= 0 &&
        (seven + four + (int)n.length() - x) / 2 == (int)n.length() / 2) {
      for (int ii = 0; ii < (seven - four + (int)n.length() - x) / 2; ii++) {
        ans[x + ii] = '4';
      }
      for (int ii = 0; ii < (four + (int)n.length() - x - seven) / 2; ii++) {
        ans[x + ii + (seven - four + (int)n.length() - x) / 2] = '7';
      }
      vec = true;
      return;
    } else {
      return;
    }
  }
}
int main() {
  cin >> n;
  memset(ans, '\0', sizeof(ans));
  four = 0;
  seven = 0;
  vec = false;
  danger = false;
  if ((int)n.length() % 2 == 0 && n[0] > '7') n += '1';
  if ((int)n.length() % 2 == 1) {
    for (int i = 0; i < ((int)n.length() + 1) / 2; i++) {
      ans[i] = '4';
    }
    for (int i = 0; i < ((int)n.length() + 1) / 2; i++) {
      ans[i + ((int)n.length() + 1) / 2] = '7';
    }
    puts(ans);
  } else {
    danger = true;
    dfs(0);
    if (vec == true)
      puts(ans);
    else {
      n += '1';
      for (int i = 0; i < ((int)n.length() + 1) / 2; i++) {
        ans[i] = '4';
      }
      for (int i = 0; i < ((int)n.length() + 1) / 2; i++) {
        ans[i + ((int)n.length() + 1) / 2] = '7';
      }
      puts(ans);
    }
  }
  return 0;
}