Skip to main content
Back to problems
Codeforces
Easy
Math
Strings
Hash Maps
Nearly Lucky Number

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.

Acceptance 0%
Problem Statement

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 4 and 7 in the number.
  • Then check whether that count is a lucky number (made only of digits 4 and 7).

Input Format

  • A single integer nn.

Output Format

  • Print YES if nn is nearly lucky, otherwise print NO.

Constraints

  • 1n1091 \le n \le 10^9
  • nn is given in decimal form.
Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.