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 n, i, j, c4[100005], c7[100005], co[100005];
char s[1000005];
int main() {
  gets(s);
  n = strlen(s);
  for (i = 0; i < n; i++) {
    if (i > 0) {
      c4[i] = c4[i - 1];
      c7[i] = c7[i - 1];
      co[i] = co[i - 1];
    }
    if (s[i] == '4')
      c4[i]++;
    else if (s[i] == '7')
      c7[i]++;
    else
      co[i]++;
  }
  if (n % 2 == 0 && co[n - 1] == 0 && c4[n - 1] == c7[n - 1]) {
    puts(s);
    exit(0);
  }
  if (n % 2 == 0)
    for (i = n - 1; i >= 0; i--)
      if (i == 0 || co[i - 1] == 0) {
        for (j = (s[i] - '0') + 1; j < 10; j++)
          if (j == 4 || j == 7) {
            int n4 = (i == 0) ? 0 : c4[i - 1];
            int n7 = (i == 0) ? 0 : c7[i - 1];
            if (j == 4)
              n4++;
            else
              n7++;
            int o = n - 1 - i;
            if (n4 + o >= n7 && n7 + o >= n4) {
              s[i] = j + '0';
              for (j = i + 1; j < n; j++) {
                s[j] = '4';
                n4++;
                o--;
                if (n7 + o < n4) {
                  s[j] = '7';
                  n4--;
                  n7++;
                }
              }
              puts(s);
              exit(0);
            }
          }
      }
  n++;
  if (n % 2 == 1) n++;
  for (i = 0; i < n; i++)
    if (i < n / 2)
      s[i] = '4';
    else
      s[i] = '7';
  puts(s);
  return 0;
}