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;
char ch[100000 + 2];
int len;
vector<int> ans;
int cnt[10];
bool flag;
void push(int c, int x) {
  while (x--) {
    ans.push_back(c);
  }
}
bool dfs(int x) {
  if (x == len) return false;
  if (ch[x] < '4') {
    push(4, len - x);
  } else if (ch[x] == '4') {
    push(4, 1);
    if (dfs(x + 1)) {
      ans[x] = 7;
    }
  } else if (ch[x] < '7') {
    push(7, 1);
    push(4, len - x - 1);
  } else if (ch[x] == '7') {
    push(7, 1);
    if (dfs(x + 1)) {
      while (~x) {
        if (ans[x] == 7)
          ans[x] = 4;
        else
          break;
        --x;
      }
      if (x == -1)
        flag = true;
      else
        ans[x - 1] = 7;
    }
  } else {
    push(4, len - x);
    return true;
  }
  return false;
}
void print(int t, int x) {
  while (t--) {
    printf("%d", x);
  }
}
int main() {
  scanf("%s", ch);
  len = strlen(ch);
  if (dfs(0)) flag = true;
  if (flag || (len & 1)) {
    if (flag) ++len;
    print((len + 1) / 2, 4);
    print((len + 1) / 2, 7);
  } else {
    int i;
    for (i = 0; i < len; ++i) ++cnt[ans[i]];
    cnt[0] = (cnt[4] - cnt[7]) / 2;
    if (cnt[0] >= 0) {
      i = len - 1;
      while (cnt[0]--) {
        while (ans[i] == 7) --i;
        ans[i] = 7;
      }
      for (i = 0; i < ans.size(); ++i) printf("%d", ans[i]);
    } else {
      for (i = len - 1; ~i; --i) {
        if (ans[i] == 7)
          ++cnt[0];
        else {
          if (cnt[0] > 0) break;
        }
      }
      if (i == -1) {
        print(len / 2 + 1, 4);
        print(len / 2 + 1, 7);
      } else {
        for (int j = 0; j < i; ++j) printf("%d", ans[j]);
        print(1, 7);
        print(len - i - cnt[0], 4);
        print(cnt[0] - 1, 7);
      }
    }
  }
  return 0;
}