Ciel Numbers II

All submissions for this problem are available.
Recently, chef Ciel often hears about lucky numbers.
Everybody knows that lucky numbers are positive integers
whose decimal representation contains only the lucky digits 4 and 7.
For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Ciel decides to make Ciel numbers.
As you know, Ciel likes the digit 8 very much.
And then, Ciel likes the digits 5 and 3.
So Ciel defines Ciel numbers as the positive integers k such that d(k, 8) ≥ d(k, 5) ≥ d(k, 3) and d(k, i) = 0 for all i = 0, 1, 2, 4, 6, 7, 9,
where d(k, i) denotes the number of the digit i in the decimal representation of the integer k.
For example, the first few Ciel numbers are 8, 58, 85, 88, 358, 385, 538, 583, 588, 835, 853, 858, 885, 888, ....
Ciel's restaurant has N menus.
And Ciel want to know how many menus have Ciel numbers as their price.
Your task is to find it.
Input
The first line contains an integer N.
Then N lines follow.
Each line has the name S_{i} of the menu and its price P_{i} separated by a single space.
Output
Print the number of menus whose prices are one of Ciel numbers.
Constraints
1 ≤ N ≤ 1000
1 ≤ S_{i} ≤ 100, where S_{i} denotes the length of S_{i}
Each letter of S_{i} is either an alphabetical letter or a digit or a single quotation mark or a space.
1 ≤ P_{i} < 1000000 (10^{6})
P_{i} contains no leading zeros.
Sample Input
6 milk 58 Ciel's Drink 80 The curry 2nd edition 888888 rice omelet 85855 unagi 1 The first and last letters can be a space 358
Sample Output
3
Output details
58 and 888888 and 358 are Ciel numbers.
80 and 85855 and 1 are not Ciel numbers.
Notes
Different operating systems have different ways of representing a newline; do not assume one particular way will be used.
Author:  laycurse 
Tester:  rajivka 
Editorial  http://discuss.codechef.com/problems/CIELNUM2 
Tags  cook20, easy, laycurse 
Date Added:  27022012 
Time Limit:  0.621212 sec 
Source Limit:  50000 Bytes 
Languages:  C, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions