Nearly Lucky Number

Practice this coding question on Coding Gurukul.

Problem statement

A puzzle booth issues decimal ticket numbers and highlights tickets using a two-stage lucky-digit rule. The booth first counts how many digits of the ticket are 4 or 7. It then checks whether that count is itself a positive number written using only 4s and 7s. This second check makes the rule different from simply asking whether the ticket contains a lucky digit. Your task Given the ticket number n, count its occurrences of digits 4 and 7. Print YES if the resulting count has only the digits 4 and 7 in its decimal representation; otherwise print NO. All other digits of n are ignored during the first count. Important details A count of zero is not lucky. The value of n can be too large for a 32-bit integer, so reading it as a string is valid. Repeated lucky digits each contribute separately. Worked example Ticket 4477 contains four lucky digits. The count 4 is itself lucky, so the result is YES. Ticket 47 has count 2 and would produce NO.

Input format

One positive decimal integer n.

Output format

Print YES for a nearly lucky ticket, otherwise NO.

Constraints

1 <= n <= 1000000000000000000.

Sample input

4477

Sample output

YES

Sign in to run or submit a solution in C++, Java or Python.