Determine whether a number is nearly lucky: it contains only the digits 4 and 7, and the count of its lucky digits is itself lucky.
Nearly Lucky Number
A positive integer is called lucky if every digit in its decimal representation is either 4 or 7.
A number is called nearly lucky if the number of lucky digits it contains is itself a lucky number.
Given an integer, decide whether it is nearly lucky.
Clarification
- Count only digits
4and7in the number. - Then check whether that count is a lucky number (made only of digits
4and7).
Input Format
- A single integer .
Output Format
- Print
YESif is nearly lucky, otherwise printNO.
Constraints
- is given in decimal form.
Example 1
Input
40047
Output
NO
Explanation
The digits 4 and 7 appear 3 times. Since 3 is not a lucky number, the answer is NO.
Example 2
Input
7744
Output
YES
Explanation
There are 4 lucky digits, and 4 is itself a lucky number, so the answer is YES.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.