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;
int main() {
  string n;
  cin >> n;
  int len = n.length();
  string n_max(len, '?');
  for (int i = 0; i < (len); i++) n_max[i] = (i < len / 2 ? '7' : '4');
  if (len % 2 == 1 || (len % 2 == 0 && n > n_max)) {
    cout << string(len / 2 + 1, '4') << string(len / 2 + 1, '7') << endl;
    return 0;
  }
  bool big = false;
  string ans(len, '?');
  for (int i = 0; i < (len); i++) {
    if (big || n[i] <= '4') {
      ans[i] = '4';
      if (n[i] < ans[i]) big = true;
    } else if (n[i] <= '7') {
      ans[i] = '7';
      if (n[i] < ans[i]) big = true;
    } else {
      for (int j = i; j >= 0; j--) {
        if (n[j] < '7') {
          ans[j] = '7';
          break;
        }
        ans[j] = '4';
      }
      big = true;
    }
  }
  int cnt4 = count((ans).begin(), (ans).end(), '4'),
      cnt7 = count((ans).begin(), (ans).end(), '7');
  if (cnt4 < cnt7) {
    int i, c = 0;
    for (i = len - 1;; i--) {
      if (ans[i] == '7') c++;
      if (c > (cnt7 - cnt4) / 2 && ans[i] == '4' && ans[i + 1] == '7') break;
    }
    ans[i++] = '7';
    c -= (cnt7 - cnt4) / 2 + 1;
    fill(ans.begin() + i, ans.end() - c, '4');
    fill(ans.end() - c, ans.end(), '7');
  } else if (cnt4 > cnt7) {
    for (int i = len - 1;; i--)
      if (ans[i] == '4') {
        if (cnt4 == cnt7) break;
        ans[i] = '7';
        cnt4--;
        cnt7++;
      }
  }
  cout << ans << endl;
  return 0;
}