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 JAVA):

Solution:
import java.io.*;
import java.util.*;
import java.math.*;

public class Solution {

    private BufferedReader in;
    private PrintWriter out;
    private StringTokenizer st;

    public String next() throws Exception {
        if (st == null || !st.hasMoreElements()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }

    public int getLength(int n) {
        int ans = 0;
        while(n > 0) {
            ans++;
            n /= 10;
        }
        return ans;
    }

    public void reverse(int[] a, int l, int r) {
        for (int i = l, j = r; i < j; i++, j--)
            swap(a, i, j);
    }

    public void swap(int[] a, int i, int j) {
        int tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
    }
    public boolean nextPermutation(int[] a) {
        int k = a.length - 2;
        while(k > -1 && a[k] > a[k + 1]) k--;
        if (k == -1) return false;
        int l = a.length - 1;
        while(k < l && a[k] > a[l]) l--;
        swap(a, k, l);
        reverse(a, k + 1, a.length - 1);
        return true;
    }

    public long findHappyNumber(int n, int l) {
        int[] a = new int[l];
        for (int i = 0, j = l - 1; i < j; ++i, --j) {
            a[i] = 4;
            a[j] = 7;
        }
        int[] p = new int[l];
        for (int i = 0; i < l; ++i)
            p[i] = i;
        long m = 0;
        long ans = -1;
        do {
            m = 0;
            for (int i = 0; i < l; ++i) {
                m = m * 10 + a[p[i]];
            }
            if (m >= n && (ans == -1 || ans > m)) {
                ans = m;
            }
        } while(nextPermutation(p));
        return ans;
    }

    public void run() throws Exception {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        int n = nextInt();
        int l = getLength(n);
        if (l % 2 == 1) l++;
        long ans = findHappyNumber(n, l);
        if (ans == -1l) ans = findHappyNumber(n, l + 2);
        out.println(ans);
        out.close();
    }

    public static void main(String[] args) throws Exception {
        new Solution().run();
    }
}