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.

------ Notes ------ 

Different operating systems have different ways of representing a newline; do not assume one particular way will be used.

----- Sample Input 1 ------ 
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 1 ------ 
3
----- explanation 1 ------ 
58 and 888888 and 358 are Ciel numbers.
80 and 85855 and 1 are not Ciel numbers.

Difficulty: MEDIUM

Solutions:
n = int(input())
count1 = 0
for _ in range(n):
	arr = list(input().split())
	price = int(arr[-1])
	c = 0
	l = []
	price
	while price > 0:
		a = price % 10
		c = c + 1
		if a == 3 or a == 5 or a == 8:
			l.append(a)
		else:
			break
		price = int(price / 10)
	if c == len(l) and l.count(8) >= l.count(5) and (l.count(5) >= l.count(3)):
		count1 = count1 + 1
print(count1)


def main():
	from sys import stdin
	input()
	ans = 0
	for x in stdin:
		x = x.split()[-1]
		eight = 0
		five = 0
		three = 0
		flag = True
		for digit in x:
			if digit == '8':
				eight += 1
			elif digit == '5':
				five += 1
			elif digit == '3':
				three += 1
			else:
				flag = False
				break
		if flag:
			if eight >= five >= three:
				ans += 1
	print(ans)
main()


t = int(input())
count = 0
for z in range(t):
	value = list(map(str, input().split()))
	c8 = value[-1].count('8')
	c5 = value[-1].count('5')
	c3 = value[-1].count('3')
	if c5 + c8 + c3 == len(value[-1]) and (c8 >= c5 and c5 >= c3):
		count = count + 1
print(count)


cases = int(input())
out = 0
while cases:
	cases -= 1
	a = input().split()
	price = a[len(a) - 1]
	l8 = price.count('8')
	l5 = price.count('5')
	l3 = price.count('3')
	if l8 >= l5 >= l3 and len(price) - l8 - l5 - l3 == 0:
		out += 1
print(out)


t = int(input())
prices = []
for _ in range(t):
	arr = list(input().split())
	prices.append(arr[-1])
count = 0
for i in prices:
	dic = {}
	for j in i:
		if j in dic:
			dic[j] += 1
		else:
			dic[j] = 1
	keys = dic.keys()
	if '3' not in dic.keys():
		dic['3'] = 0
	if '5' not in dic.keys():
		dic['5'] = 0
	if '8' not in dic.keys():
		dic['8'] = 0
	if '1' in keys or '2' in keys or '4' in keys or ('0' in keys) or ('6' in keys) or ('7' in keys) or ('9' in keys):
		pass
	elif dic['8'] >= dic['5'] and dic['5'] >= dic['3']:
		count += 1
print(count)


t = int(input())
count = 0
while t > 0:
	t = t - 1
	lst = input().split()
	price = lst[len(lst) - 1]
	price = int(price)
	n8 = 0
	n5 = 0
	n3 = 0
	flag = 1
	while price > 0:
		dig = price % 10
		if dig == 8:
			n8 = n8 + 1
		elif dig == 5:
			n5 = n5 + 1
		elif dig == 3:
			n3 = n3 + 1
		else:
			flag = 0
			break
		price = int(price / 10)
	if n8 >= n5 and n5 >= n3 and flag:
		count = count + 1
print(count)


t = int(input())
ans = 0
while t:
	t -= 1
	s = input().split()
	n = s[-1]
	l = [0 for i in range(10)]
	f = 1
	for i in n:
		l[int(i)] += 1
	for i in range(10):
		if i != 5 and i != 8 and (i != 3) and l[i]:
			f = 0
			break
	if f and l[8] >= l[5] and (l[5] >= l[3]):
		ans += 1
print(ans)


ans = 0
for _ in range(int(input())):
	d = {'3': 0, '5': 0, '8': 0}
	s = input()
	s = s.strip()
	s = s.split(' ')
	s = s[-1].strip()
	for i in s:
		if i not in '358':
			break
		d[i] += 1
	else:
		if d['8'] >= d['5'] and d['5'] >= d['3']:
			ans += 1
print(ans)


def check(s):
	(a, b, c) = (0, 0, 0)
	for i in s:
		if i == '8':
			a += 1
		elif i == '5':
			b += 1
		elif i == '3':
			c += 1
		else:
			return False
	return a >= b >= c
n = int(input())
res = 0
for i in range(n):
	s = input().strip()
	s = s.split()[-1]
	if check(s):
		res += 1
print(res)


def chef(s):
	l = s.split()
	num = l[::-1][0]
	eight = num.count('8')
	five = num.count('5')
	three = num.count('3')
	if eight >= five >= three and eight + five + three == len(num):
		return 1
	else:
		return 0
n = int(input())
count = 0
for testcase in range(n):
	s = input()
	count = count + chef(s)
print(count)


def N():
	from sys import stdin
	input()
	ans = 0
	for x in stdin:
		x = x.split()[-1]
		z = {'8': 0, '5': 0, '3': 0}
		flag = True
		for digit in x:
			if digit in '853':
				z[digit] += 1
			else:
				flag = False
				break
		if flag:
			if z['8'] >= z['5'] >= z['3']:
				ans += 1
	print(ans)
N()


n = int(input())
cielnums = 0
for i in range(n):
	price = input().split()[-1]
	threes = 0
	fives = 0
	eights = 0
	others = 0
	for ch in price:
		if ch == '3':
			threes += 1
		elif ch == '5':
			fives += 1
		elif ch == '8':
			eights += 1
		else:
			others += 1
			break
	if others == 0 and eights >= fives and (fives >= threes):
		cielnums += 1
print(cielnums)


n = int(input())
cu = 0
while n:
	n -= 1
	s = input().split()
	k = s[-1]
	if k.count('8') >= k.count('5') and k.count('5') >= k.count('3') and (k.count('8') + k.count('5') + k.count('3') == len(k)):
		cu += 1
print(cu)


sum = 0
for tc in range(int(input())):
	a = input().strip().split()
	n = int(a[len(a) - 1])
	(c8, c5, c3) = (0, 0, 0)
	flag = 1
	while n > 0:
		rem = n % 10
		n = n // 10
		if rem != 8 and rem != 5 and (rem != 3):
			flag = 0
			break
		elif rem == 8:
			c8 += 1
		elif rem == 5:
			c5 += 1
		elif rem == 3:
			c3 += 1
	if flag == 1:
		if c8 >= c5 and c5 >= c3:
			sum += 1
print(sum)


c = 0
for _ in range(int(input())):
	arr = list(map(str, input().split()))
	c8 = arr[-1].count('8')
	c5 = arr[-1].count('5')
	c3 = arr[-1].count('3')
	if c8 + c5 + c3 == len(arr[-1]) and c3 <= c5 and (c5 <= c8):
		c += 1
print(c)


def isCiel(num):
	D = {}
	for i in range(10):
		D[i] = 0
	for digit in str(num):
		D[int(digit)] += 1
	acceptableDigits = [3, 5, 8]
	for key in D:
		if key not in acceptableDigits:
			if D[key] > 0:
				return False
		if D[3] > D[5] or D[5] > D[8] or D[3] > D[8]:
			return False
	return True

def scrapeNum(line):
	line = line.strip()
	line = line.split(' ')
	price = int(line[-1].strip())
	return price

def solve():
	count = 0
	N = int(input())
	for i in range(N):
		line = input()
		num = scrapeNum(line)
		flag = isCiel(num)
		if flag:
			count += 1
	return count
ans = solve()
print(ans)


from audioop import reverse
from itertools import count
from math import *
from operator import index, indexOf
from pickle import TRUE
from re import M, T

def rl():
	return list(map(int, input().split()))

def r2():
	return map(int, input().split())

def func(x):
	l = len(str(x))
	e = str(x).count('8')
	f = str(x).count('5')
	t = str(x).count('3')
	y = e + f + t
	return e >= f and f >= t and (y == l)

def solve(n, arr):
	m = 0
	for i in range(n):
		if func(arr[i]):
			m += 1
	return m
res = []
a = []
n = int(input())
for i in range(n):
	arr = list(input().split())
	a.append(arr[-1])
print(solve(n, a))


def isCielNum(N):
	cnt3 = 0
	cnt5 = 0
	cnt8 = 0
	if N == 0:
		return False
	while N > 0:
		r = N % 10
		if r != 3 and r != 5 and (r != 8):
			return False
		if r == 3:
			cnt3 += 1
		elif r == 5:
			cnt5 += 1
		else:
			cnt8 += 1
		N //= 10
	return cnt3 <= cnt5 and cnt5 <= cnt8
ans = 0
for tc in range(int(input())):
	x = input().strip().split()
	if isCielNum(int(x[len(x) - 1])):
		ans += 1
print(ans)


def is_ciel(n):
	n3 = 0
	n5 = 0
	n8 = 0
	while n > 0:
		k = n % 10
		if k == 3:
			n3 += 1
		elif k == 5:
			n5 += 1
		elif k == 8:
			n8 += 1
		else:
			return 0
		n //= 10
	if n3 <= n5 and n5 <= n8:
		return 1
	return 0
res = 0
for _ in range(int(input())):
	buf = input()
	length = len(buf)
	st = -1
	for i in range(length - 1, -1, -1):
		if buf[i] == ' ':
			st = i
			break
	p = int(buf[i + 1:length])
	if is_ciel(p):
		res += 1
print(res)


Ciels = []
notCiels = []
for i in range(int(input())):
	a = input().strip().split()
	number = a[len(a) - 1]
	digits = len(number)
	count8 = number.count('8')
	count5 = number.count('5')
	count3 = number.count('3')
	if count3 + count5 + count8 == digits and count8 >= count5 and (count5 >= count3):
		Ciels.append(number)
	else:
		notCiels.append(number)
print(len(Ciels))


n = int(input())
ctr = 0
for q in range(n):
	inp = list(input().split())
	l = []
	l1 = len(inp[-1])
	num = int(inp[-1])
	while num > 0:
		last_digit = num % 10
		if last_digit == 3 or last_digit == 5 or last_digit == 8:
			l.append(last_digit)
		else:
			break
		num = int(num / 10)
	if l.count(8) >= l.count(5) and l.count(5) >= l.count(3) and (l1 == len(l)):
		ctr = ctr + 1
print(ctr)


def is_ciel_number(price):
	freq_3 = 0
	freq_5 = 0
	freq_8 = 0
	for d in price:
		if d == '3':
			freq_3 += 1
		elif d == '5':
			freq_5 += 1
		elif d == '8':
			freq_8 += 1
		else:
			return False
	return freq_8 >= freq_5 and freq_5 >= freq_3
N = int(input())
num_ciel_numbers = 0
for n in range(N):
	line = input()
	tokens = line.split()
	if is_ciel_number(tokens[len(tokens) - 1]):
		num_ciel_numbers += 1
print(num_ciel_numbers)


n = int(input())
cu = 0
while n:
	n -= 1
	s = input().split()
	k = s[-1]
	u = len(k)
	x = k.count('8')
	y = k.count('5')
	z = k.count('3')
	if x >= y and y >= z:
		if x + y + z == u:
			cu += 1
print(cu)