#CF96B. Lucky Numbers (easy)

    ID: 4715 传统题 2000ms 256MiB 尝试: 4 已通过: 1 难度: 10 上传者: 标签>难度普及-基础算法二分其他构造来源codeforces暴力

Lucky Numbers (easy)

CF96B Lucky Numbers (easy)

题目描述

Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 4 and 7 7 . For example, numbers 47 47 , 744 744 , 4 4 are lucky and 5 5 , 17 17 , 467 467 are not.

Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 4 and 7 7 . For example, numbers 47 47 , 7744 7744 , 474477 474477 are super lucky and 4 4 , 744 744 , 467 467 are not.

One day Petya came across a positive integer n n . Help him to find the least super lucky number which is not less than n n .

输入格式

The only line contains a positive integer n n ( 1<=n<=109 1<=n<=10^{9} ). This number doesn't have leading zeroes.

输出格式

Output the least super lucky number that is more than or equal to n n .

Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.

输入输出样例 #1

输入 #1

4500

输出 #1

4747

输入输出样例 #2

输入 #2

47

输出 #2

47