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.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;


import java.util.*;

public class Watermelon {
	public static void main(String[] args) throws IOException{
		Main m=new Main();
		m.solve();
	}
	}
class Main{
	static int[] temp=new int[100];
	 BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

	   
	    StringTokenizer stringTokenizer;

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

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

	    long nextLong() throws IOException {
	        return Long.parseLong(next());
	    }
	char[] marr;
	    void solve() throws IOException  {
	     Integer n=this.nextInt();
	     char carr[]= n.toString().toCharArray();
	     marr=new char[carr.length];
	     superlucky(carr);
	     while(i<marr.length){
	    	 marr[i]='4';
	    	 i++;
	     }
	while(true){
		int count4=0,count7=0;
		for(int i=0;i<marr.length;i++)
	    {
	    	if(marr[i]=='4')count4++;
	    	if(marr[i]=='7')count7++;
	    	
	    }
		if(count4==count7)
			break;
		marr[marr.length-1]=(char)(marr[marr.length-1]+1);
     //  display(marr);
		carr=marr.clone();
  //      System.out.println("carr");display(carr);
  //      System.out.println("marr");display(marr);
        i=0;
        superlucky(carr);
        
	   //display(marr);
	   while(i<marr.length){
	    	 marr[i]='4';
	    	 i++;
	     }
	//   display(marr);
	   }
	display(marr);
 }
	    int i=0;
	void superlucky(char[] carr){
		//System.out.println(carr[0]);
		if(carr[0]=='1'||carr[0]=='2'||carr[0]=='3'||carr[0]=='4'||carr[0]=='5'||carr[0]=='6'||carr[0]=='7'){
		if(i<carr.length){
		if(carr[i]<='4')
			{if(carr[i]=='4'){marr[i]='4';i++;superlucky(carr);} else{marr[i]='4';i++;return;}}
		else if(carr[i]<='7')
			{if(carr[i]=='7'){marr[i]='7';i++;superlucky(carr);} else{marr[i]='7';i++;return;}}
		else{
			
			carr[i]='4';
			i--;
			carr[i]=(char) (carr[i]+1);
			superlucky(carr);
		}}}else{
			//System.out.println(carr[0]);
			if(carr.length%2!=0){
				marr=new char[carr.length+1];
				for(int i=0;i<marr.length;i++){
					if(i<marr.length/2)
					marr[i]='4';
					else
						marr[i]='7';
				}
				display(marr);
				System.exit(0);
			}
			else{
				marr=new char[carr.length+2];
				for(int i=0;i<marr.length;i++){
					if(i<marr.length/2)
					marr[i]='4';
					else
						marr[i]='7';
				}
				display(marr);
				System.exit(0);
			}
		}
	}
	
	static int fact(int aa) {
		 
	    if (aa == 0 || aa == 1) {
	        return 1;
	    } else {
	        if (temp[aa] != 0)
	            return temp[aa];
	        else
	            return temp[aa] = (aa * fact(aa - 1));
	    }
	 
	}
	private static int gcd(int a, int b)
	{
	    while (b > 0)
	    {
	    	int temp = b;
	        b = a % b; // % is remainder
	        a = temp;
	    }
	    return a;
	}
	private static int lcm(int a, int b)
	{
	    return a * (b / gcd(a, b));
	}
	static int[] toFractionPos(int x,int y){
		int a=gcd(x,y);
		int[] arr={x/a,y/a};
		//display(arr);
		return arr;
	}
   
	static void display(int[][] arr){
		for(int i=0;i<arr.length;i++){
			for(int j=0;j<arr[i].length;j++){
				System.out.print(arr[i][j]+" ");
		}
			System.out.println();
		}
		System.out.println();
	}

	 static void display(String[] arr){
			for(int i=0;i<arr.length;i++){
				
			}	
			System.out.println();
		
	 }
	 
		 static void display(int[] arr){
		 for(int i=0;i<arr.length;i++)
				System.out.print(arr[i]+" ");
		System.out.println();
		 }
	 static void display(char[] arr){
		// System.out.println();
		 int t=0;
			for(int i=0;i<arr.length;i++){
				if(arr[i]!='0'){t=i;break;}
			}	
			while(t!=arr.length){
				System.out.print(arr[t]);
				t++;
			}
			System.out.println();
		
		  }
	 static String str(char[] carr){
		 String str="";
		 for(int i=0;i<carr.length;i++){
			    str=str+carr[i];
			}
		 return str;
	 }
}
class  Count implements Comparable{
	int i,j;
	Count(int i,int j)
	{this.i=i;this.j=j;}
    void display(){
    	System.out.println(i+" "+j);
    }
	@Override
	public int compareTo(Object o) {
		// TODO Auto-generated method stub
		Count c=(Count)o;
		if(this.i>c.i)
			return 1;
		else if(this.i<c.i)
			return -1;
		else return 0;
	}
}
class  Count1 implements Comparable{
	int i,j,k,l;
	Count1(int i,int j,int k,int l)
	{this.i=i;this.j=j;this.k=k;this.l=l;}
    void display(){
    	System.out.println(i+" "+j+" "+k+" "+l);
    }
	@Override
	public int compareTo(Object o) {
		// TODO Auto-generated method stub
		Count c=(Count)o;
		if(this.i>c.i)
			return 1;
		else if(this.i<c.i)
			return -1;
		else return 0;
	}
}