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;
void form(string s) {
  int len = s.size();
  if (len % 2 == 1) {
    len++;
  }
  for (int i = 0; i < len / 2; i++) printf("4");
  for (int j = 0; j < len / 2; j++) printf("7");
  printf("\n");
  exit(0);
}
string converttolucky(string s) {
  int flag = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '4' || s[i] == '7') {
      continue;
    } else {
      if (s[i] < '4') {
        s[i] = '4';
        for (int j = i + 1; j < s.size(); j++) s[j] = '4';
        return s;
      } else if (s[i] < '7') {
        s[i] = '7';
        for (int j = i + 1; j < s.size(); j++) s[j] = '4';
        return s;
      } else {
        flag = 0;
        for (int k = i - 1; k >= 0; k--) {
          if (s[k] == '4') {
            flag = 1;
            s[k] = '7';
            for (int j = k + 1; j < s.size(); j++) {
              s[j] = '4';
            }
            return s;
          }
        }
        if (flag == 0) {
          s.append("4");
          form(s);
        }
      }
    }
  }
  return s;
}
string more4(string s) {
  int len4 = 0;
  int len7 = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '4')
      len4++;
    else
      len7++;
  }
  if (len4 >= len7) return s;
  int flag = 0;
  int rem4 = 0;
  int rem7 = 0;
  for (int j = s.size() - 1; j >= 0; j--) {
    if (s[j] == '4') {
      int tmp7 = len7 - rem7 + 1;
      rem4++;
      int tmp4 = len4 - rem4;
      if (tmp4 + (s.size() - j - 1) >= tmp7) {
        s[j] = '7';
        for (int k = j + 1; k < s.size(); k++) s[k] = '4';
        return s;
      }
    } else
      rem7++;
  }
  s.append("4");
  form(s);
}
string solve(string s) {
  int len4 = 0;
  int len7 = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '4')
      len4++;
    else
      len7++;
  }
  for (int j = s.size() - 1; j >= 0; j--) {
    if (len4 == len7) {
      cout << s << "\n";
      return s;
    }
    if (s[j] == '4') {
      s[j] = '7';
      len4--;
      len7++;
    }
  }
  assert(len4 == len7);
}
int main() {
  string s;
  cin >> s;
  int len = s.size();
  if (len % 2 == 1) form(s);
  s = converttolucky(s);
  s = more4(s);
  solve(s);
}