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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;


public class C {
	
	static final long INF = (long)1e12;
	
	static long bt(int[] n, int idx, int balance, boolean greater, long m)
	{
		if(idx == n.length)
			return balance == 0 ? m: INF;
		long ret = INF;
		if(greater || 4 >= n[idx])
			ret = bt(n, idx + 1, balance + 1, 4 > n[idx] ? true : greater, m * 10 + 4);
		if(greater || 7 >= n[idx])
			ret = Math.min(ret, bt(n, idx + 1, balance - 1, 7 > n[idx] ? true : greater, m * 10 + 7));
		return ret;
	}
	
	public static void main(String[] args) throws IOException 
	{
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int[] n = split(sc.nextInt());
		long res = bt(n, 0, 0, false, 0);
		if(res != INF)
			out.println(res);
		else
		{
			int c = n.length / 2 + 1;
			for(int i = 0; i < c; ++i)
				out.print(4);
			for(int i = 0; i < c; ++i)
				out.print(7);
		}
		out.flush();
		out.close();

	}
	
	static int[] split(int n)
	{
		int c = 0, z = n;
		while(n > 0)
		{
			++c;
			n /= 10;
		}
		int[] ret = new int[c];
		for(int i = 0; i < c; ++i, z /= 10)
			ret[c - i - 1] = z%10;
		return ret;
	}
	
	static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

		public boolean ready() throws IOException {return br.ready();}


	}
}