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 Si of the menu and its price Pi separated by a single space.

-----Output-----

Print the number of menus whose prices are one of Ciel numbers.

-----Constraints-----

1 ≤ N ≤ 1000

1 ≤ |Si| ≤ 100, where |Si| denotes the length of Si

Each letter of Si is either an alphabetical letter or a digit or a single quotation mark or a space.

1 ≤ Pi < 1000000 (106)
Pi 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.

Difficulty: interview

Starter code:

Solutions:
#!/usr/bin/env python

def main():
 N = int(input())
 C = 0
 for n in range(N):
  S = input().strip()
  Pi = S.split()[-1]
  L = [Pi.count(k) for k in map(str, list(range(10)))]
  if L[8] >= L[5] and L[5] >= L[3] and \
   L[0] == 0 and L[1] == 0 and \
   L[2] == 0 and L[4] == 0 and \
   L[6] == 0 and L[7] == 0 and \
   L[9] == 0: C += 1
 print(C)

main()



import sys

ngs = "0124679"
def judge(p):
 for i in ngs:
  if i in p:
   return False
 return p.count("3") <= p.count("5") <= p.count("8")

n = int(input())
res = 0
for i in range(n):
 p = sys.stdin.readline().split()[-1].strip()
 if judge(p): res += 1
print(res)


n = int(input());

count = 0;

while n > 0:

 n -= 1;

 inp = input().split(' ')[-1:][0];

#   if len(inp) > 6:
#
#       raise ValueError;

#   print inp;

 eight, five, three, others = 0, 0, 0, False;
 
 for each in inp:

  if each >= '0' and each <= '9':
 
   if each == '8':
 
    eight += 1;

   elif each == '5':

    five += 1;

   elif each == '3':

    three += 1;

   else:
    others = True;
 
    break;

 if not others and eight >= five and five >= three:

  count += 1;

print(count);


import sys

n = int(sys.stdin.readline())

count = 0
def is_ciel(s):
 for i in '0124679':
  if s.count(i) > 0:
   return False
 if s.count('8') >= s.count('5') >= s.count('3'):
  return True
 return False


for _ in range(n):
 s = sys.stdin.readline().split()
 if is_ciel(s[-1]):
  count += 1

print(count)



def check(s):
 d3=d5=d8=0
 for c in s:
  if not c.isdigit():
   continue
  if c=="3":d3+=1
  elif c=="5":d5+=1
  elif c=="8":d8+=1
  else:return False
 #print d3,d5,d8
 return d3<=d5<=d8

def main():
 cnt=0
 for i in range(int(input())):
  s=input().split(" ")[-1]
  #print s
  if check(s):
   #print s
   cnt+=1
 print(cnt)

main()

import sys
n = int (sys.stdin.readline ())
res = 0
for i in range (n):
 s = sys.stdin.readline ().split ()[-1]
 l = len (s)
 a = sum (1 for c in s if c == '8')
 b = sum (1 for c in s if c == '5')
 c = sum (1 for c in s if c == '3')
 if a >= b >= c and a + b + c == l:
  res += 1
print(res)


n=int(input())
res=0;
while n>0:
 n-=1
 s=input()
 l=s.split()
 x=l[-1]
 e=0
 f=0
 t=0
 for ch in x:
  if ch=='8' :
   e+=1
  elif ch=='5' :
   f+=1
  elif ch=='3' :
   t+=1
  else:
   t=1001
   break
 if(e>=f>=t):
  res+=1
print(res)

price=[]
for _ in range(int(input())):
 s=input().split()
 price.append(s[len(s)-1])
   
count=0
for i in price:
 e=i.count('8')
 f=i.count('5')
 t=i.count('3')
 d=i.count('.')
 if e+f+t+d==len(i):
  if e>=f and f>=t:
   count+=1
print(count)

n = int(input())
ret = 0
while n:
 n -= 1
 num = input().split()[-1]
 if num.count('3') > num.count('5') or num.count('5') > num.count('8'):
  continue
 if num.count('3')+num.count('8')+num.count('5') != len(num):
  continue
 ret += 1
print(ret)