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:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


import java.util.Scanner;

/**
 *
 * @author milon
 */
public class Main{
     public static void main(String[] args) {
        
        Scanner sin = new Scanner(System.in);
           
           String a=sin.nextLine();
          
           long low[]=new long[11];
           long up[]=new long[11];
           
           low[2]=47;
           low[4]=4477;
           low[6]=444777;
           low[8]=44447777;
           low[10]=4444477777l;
           
           up[2]=74;
           up[4]=7744;
           up[6]=777444;
           up[8]=77774444;
           up[10]=7777744444l;
           
           
           
           /*
           4500
           
           
               1-47-74
               2-4477-7744
               3-444777-777444
               4-44447777-77774444
               5-4444477777-7777744444
             */  
           
           long num=Long.valueOf(a);
               
           if(a.length()%2==0){
               
               if(num<=up[a.length()] && num>low[a.length()]){
                   //System.out.println("here");
                   
                    for (long i = num; i <= up[a.length()]; i++) {
                         if(goNum(i)==1){
                             break;
                         };
                    }
               }else if(num>up[a.length()]){
                   System.out.println(low[a.length()+2]);
               }else{
                   System.out.println(low[a.length()]);
               }
               
           }else{
               int ii=a.length()/2;
               String n="";
               for (int i = 0; i < (ii+1); i++) {
                   n+="4";
               }
               for (int i = 0; i < (ii+1); i++) {
                   n+="7";
               }
               System.out.println(""+n);
               return;
           }    
               
         
          
           
            
    }
     
     
     public static int goNum(long num){
         int ck=0;
         String s=String.valueOf(num);
               
               if(isLucky(s) && (s.length()%2)==0 ){
                   //System.out.println("yes lucky"+s+"|");
                   int cfour=0,cseven=0;
                   for (int i = 0; i < s.length(); i++) {
                       if(s.charAt(i)=='4'){
                          cfour++; 
                       }
                       
                       if(s.charAt(i)=='7'){
                          cseven++; 
                       }
                       
                   }
                   if(cfour==cseven){
                       System.out.println(s);
                       ck=1;
                   }
               }
               
               return ck;
               
     }
    
    
    static boolean isLucky(String num){
        
                    
    		String four=String.valueOf(4);
    		String seven=String.valueOf(7);
    		String zero=String.valueOf(0);
    		String one=String.valueOf(1);
    		String two=String.valueOf(2);
    		String three=String.valueOf(3);
    		String five=String.valueOf(5);
    		String six=String.valueOf(6);
    		String eight=String.valueOf(8);
    		String nine=String.valueOf(9);
    		
    		if(num.contains(four)  ||  num.contains(seven) ){
                    
                        if(
                           num.contains(zero)
                        || num.contains(one)
                        || num.contains(two)
                        || num.contains(three)
                        || num.contains(five)
                        || num.contains(six)
                        || num.contains(eight)
                        || num.contains(nine)   
                           ){
                            return false;
                        }else{
                             return true;
                        }
                       
                    
                    }
                    
    		else if(num.equals(four) || num.equals(seven)){return true;}
    		else{return false;}
    }
}