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:

/*

Author: Yiu Yu Ho
Creation: <Creation Date>
Last Updated: <Last Updated Date>
*/

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

public class LuckyNumber
{
	public Scanner in = new Scanner(System.in);
	public PrintStream out = System.out;

	public int[] n;
	public int L;
	
	public void main()
	{
		String S = in.next();
		
		n = s2ia(S);
		L = n.length;
		
		if(L % 2 == 0)
		{
			int[] min = minSLucky(L);
			int[] max = maxSLucky(L);
			
			if(compare(min, n) >= 0)
			{
				out.println(ia2s(min)); return;
			}
			
			if(compare(max, n) < 0)
			{
				out.println(ia2s(minSLucky(L + 2)));
				return;
			}
			
			//min < n  <= max
			
			if(isSLucky(n))
			{
				out.println(ia2s(n));
				return;
			}
			
			int C4, C7, i, j;
			C4 = C7 = 0;
			
			int H = L / 2;
			
			i = 0;
			while(i < n.length)
			{
				if(n[i] == 4)
				{
					if(C4 < H) { ++C4; ++i;	}
					else
					{
						//Enough 4s
						n[i] = 7; ++C7;
						put(n, 7, i + 1, L - 1);
						out.println(ia2s(n)); return;
					}
				}
				else if(n[i] == 7)
				{
					if(C7 < H)
					{
						++C7; ++i;
					}
					else
					{
						//Not Enough 7						
						j = i - 1;
						while(j >= 0 && n[j] == 4)
						{
							--C4;
							--j;
						}
						
						while(j >= 0 && n[j] == 7)
						{
							--C7;
							--j;
						}
						
						//n[j] == 4
						n[j] = 7; ++C7; --C4;
						put(n, 4, j + 1, j + (H - C4));
						put(n, 7, j + (H - C4) + 1, L - 1);
						out.println(ia2s(n));
						return;
					}
				}
				else
				{
					//n[i] is not 4 or 7
					if(n[i] < 4)
					{
						if(C4 < H)
						{
							n[i] = 4; ++C4;
							put(n, 4, i + 1, i + (H - C4));
							put(n, 7, i + (H - C4) + 1, L - 1);
							out.println(ia2s(n));
							return;
						}
						else
						{
							n[i] = 7; ++C7;
							put(n, 7, i + 1, L - 1);
							out.println(ia2s(n));
							return;							
						}
					}
					else if(n[i] < 7)
					{
						//4 < n[i] < 7
						if(C7 < H)
						{
							n[i] = 7; ++C7;
							put(n, 4, i + 1, i + (H - C4));
							put(n, 7, i + (H - C4) + 1, L - 1);
							out.println(ia2s(n));	
							return;
						}
						else
						{
							//upOne HERE
							j = i - 1;
							while(j >= 0 && n[j] == 4)
							{
								--C4;
								--j;
							}
							
							while(j >= 0 && n[j] == 7)
							{
								--C7;
								--j;
							}
							
							//n[j] == 4
							n[j] = 7; ++C7; --C4;
							put(n, 4, j + 1, j + (H - C4));
							put(n, 7, j + (H - C4) + 1, L - 1);
							out.println(ia2s(n));
							return;
						}
					}
					else
					{
						//n[i] > 7
						//upOne HERE
						j = i - 1;
						
						if(C7 >= H)
						{
							while(j >= 0 && n[j] == 4)
							{
								--C4;
								--j;
							}
						}
						
						while(j >= 0 && n[j] == 7)
						{
							--C7; --j;
						}
						
						//n[j] == 4
						n[j] = 7; ++C7; --C4;
						put(n, 4, j + 1, j + (H - C4));
						put(n, 7, j + (H - C4) + 1, L - 1);
						out.println(ia2s(n));
						return;
					}
				}
			}
		}
		else
		{
			//L is odd
			out.println(ia2s(minSLucky(L + 1)));
		}		
	}//end public void main()
	
	//compare 2 int[] lexicographically
	public int compare(int[] A, int[] B)
	{
		int i = 0;
		while(i < A.length && i < B.length)
		{
			if(A[i] != B[i]) return A[i] - B[i];
			++i;
		}
		
		return A.length - B.length;
	}	
	
	public int[] minSLucky(int len)
	{
		int H = (len / 2);
		int[] res = new int[len];
		
		put(res, 4, 0, H - 1);
		put(res, 7, H, len - 1);
		
		return res;
	}
	
	public int[] maxSLucky(int len)
	{
		int H = (len / 2);
		int[] res = new int[len];
		
		put(res, 7, 0, H - 1);
		put(res, 4, H, len - 1);
		
		return res;
	}
	
	public boolean isSLucky(int[] n)
	{
		int C4, C7;
		C4 = C7 = 0;
		
		for(int i = 0; i < n.length; ++i)
		{
			if(n[i] == 4) ++C4;
			else if(n[i] == 7) ++C7;
			else return false;
		}
		
		return (C4 == C7);
	}
	
	public void put(int[] v, int x, int i, int j)
	{
		while(i <= j)
		{
			v[i] = x;
			++i;
		}
	}
	
//----------------- Pre-Written Code -------------------------------------------	
    //Parsing a String of digit characters into an array of single digits
    public static int[] s2ia(String s)
    {
        int[] R = new int[s.length()];
        for(int i = 0; i < R.length; ++i) R[i] = (s.charAt(i) - '0');
        return R;
    }
    
    //Convert v into a String of digits
    public static String ia2s(int[] v)
    {
        StringBuffer ret = new StringBuffer("");
        for(int i = 0; i < v.length; ++i) ret.append(v[i]);
        return ret.toString();
    }
 
//----------------- Ends Pre-Written Code --------------------------------------

	public static void main(String[] args)
	{
		long startTime = System.currentTimeMillis();

		try
		{
			(new LuckyNumber()).main();
		}
		catch(Exception e) { e.printStackTrace(); }

		long endTime = System.currentTimeMillis();

		long ms = endTime - startTime;
		long sec = ms/1000; ms = ms%1000;
		long min = sec/60; sec = sec%60;

		System.err.println("Time Spent: " + min + " minute(s) " + sec + " second(s) " + ms + " (ms)");
	}
}