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.util.ArrayList;
import java.util.StringTokenizer;

public class CF_96_B_LUCKY_NUMBERS {

	static ArrayList<Long> lucky ;
	
	
	static void generate(String s , int length)
	{
		
		if(s.length() == length)
		{	
			if(isSameLucky(Long.parseLong(s)))
			lucky.add(Long.parseLong(s));
			return;
		}
		
		generate(s+"4", length);
		generate(s+"7", length);
		
		
	}
	static boolean isSameLucky(long n)
	{
		long four = 0;
		long seven = 0;
		long temp = n;
		while (temp!=0)
		{
			if(temp % 10 == 4)
				four++;
			else
				seven++;
			temp/=10;
		}
		return four == seven;
		
	}
	

	

	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		
		long n = sc.nextLong();
		
		lucky = new ArrayList<>();
		
		for(int i = 1 ; i<=15 ;i++)
			generate("", i);
		
		int start = 0 ;
		int end = lucky.size()-1;
		int ans = end;	
		while(start<=end)
		{
			int mid = (start+end)/2;
			
			if(lucky.get(mid)<n)
				start = mid + 1;
			else
			{
				ans = mid;
				end = mid - 1; 
			}
		}
		
		System.out.println(lucky.get(ans));
		
		

	}

	static class Scanner {
		BufferedReader bf;
		StringTokenizer st;

		public Scanner(InputStream i) {
			bf = new BufferedReader(new InputStreamReader(i));

		}

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

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

		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 long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
	}

}