Under construction

Still being built. Things may change

Largest Lucky Number

Interview

Time limit2sMemory limit256 MB

Summary
Given N up to 1,000,000, find the largest number no greater than N whose digits are only 4s and 7s.
Level

Easy3 of 10

Topics
Recursion, Brute force, Math
Solved
No attempts yet

Problem

A lucky number is a positive integer whose decimal representation consists only of the digits 4 and 7.

Given a natural number N, find the largest lucky number that is less than or equal to N.

Input

The first line contains a natural number N. N is at least 4 and at most 1,000,000.

Output

Print the largest lucky number that is less than or equal to N.

Examples4

  1. Example 1

    Input
    100
    
    Expected output
    77
    
  2. Example 2

    Input
    75
    
    Expected output
    74
    
  3. Example 3

    Input
    5
    
    Expected output
    4
    
  4. Example 4

    Input
    474747
    
    Expected output
    474747