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;
int ans[100005];
int l;
int luck(int t) {
  if (t == l) {
    return 1;
  }
  if (n[t] < '4') {
    ans[t] = 4;
    for (int i = t; i < l; i++) {
      ans[i] = 4;
    }
    return 1;
  } else if (n[t] == '4') {
    if (luck(t + 1)) {
      ans[t] = 4;
    } else {
      ans[t] = 7;
    }
    return 1;
  } else if (n[t] < '7') {
    ans[t] = 7;
    for (int i = t + 1; i < l; i++) {
      ans[i] = 4;
    }
    return 1;
  } else if (n[t] == '7') {
    if (luck(t + 1)) {
      ans[t] = 7;
      return 1;
    } else {
      ans[t] = 4;
      return 0;
    }
  } else {
    ans[t] = 4;
    return 0;
  }
}
int main() {
  cin >> n;
  l = n.size();
  string m;
  for (int i = 0; i < l / 2; i++) {
    m.push_back('7');
  }
  for (int i = 0; i < l / 2; i++) {
    m.push_back('4');
  }
  if (l % 2 || n > m) {
    for (int i = 0; i <= l / 2; i++) {
      printf("4");
    }
    for (int i = 0; i <= l / 2; i++) {
      printf("7");
    }
  } else {
    int f = 0;
    for (int i = 0; i < l; i++) {
      if (ans[i]) {
        continue;
      }
      luck(i);
    }
    for (int i = 0; i < l; i++) {
      if (ans[i] == 4) {
        f++;
      }
    }
    f -= l / 2;
    if (f > 0) {
      for (int i = l - 1; i >= 0; i--) {
        if (ans[i] == 4) {
          ans[i] = 7;
          f--;
        }
        if (f == 0) {
          break;
        }
      }
    } else if (f < 0) {
      bool flag = 1;
      int s = 0;
      for (int i = l - 1; i >= 0; i--) {
        if (ans[i] == 7) {
          s++;
        } else {
          if (s + f >= 1) {
            ans[i] = 7;
            for (int j = i + 1; j < l; j++) {
              if (ans[j] == 7) {
                ans[j] = 4;
                f++;
              }
              if (f == 1) {
                break;
              }
            }
            flag = 0;
            break;
          }
        }
      }
      if (flag) {
        for (int i = 0; i <= l / 2; i++) {
          printf("4");
        }
        for (int i = 0; i <= l / 2; i++) {
          printf("7");
        }
        return 0;
      }
    }
    for (int i = 0; i < l; i++) {
      printf("%d", ans[i]);
    }
  }
  return 0;
}