You are given an array $a$ consisting of $n$ integers. Each $a_i$ is one of the six following numbers: $4, 8, 15, 16, 23, 42$.

Your task is to remove the minimum number of elements to make this array good.

An array of length $k$ is called good if $k$ is divisible by $6$ and it is possible to split it into $\frac{k}{6}$ subsequences $4, 8, 15, 16, 23, 42$.

Examples of good arrays:  $[4, 8, 15, 16, 23, 42]$ (the whole array is a required sequence);  $[4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42]$ (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements);  $[]$ (the empty array is good). 

Examples of bad arrays:   $[4, 8, 15, 16, 42, 23]$ (the order of elements should be exactly $4, 8, 15, 16, 23, 42$);  $[4, 8, 15, 16, 23, 42, 4]$ (the length of the array is not divisible by $6$);  $[4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23]$ (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence). 


-----Input-----

The first line of the input contains one integer $n$ ($1 \le n \le 5 \cdot 10^5$) — the number of elements in $a$.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ (each $a_i$ is one of the following numbers: $4, 8, 15, 16, 23, 42$), where $a_i$ is the $i$-th element of $a$.


-----Output-----

Print one integer — the minimum number of elements you have to remove to obtain a good array.


-----Examples-----
Input
5
4 8 15 16 23

Output
5

Input
12
4 8 4 15 16 8 23 15 16 42 23 42

Output
0

Input
15
4 8 4 8 15 16 8 16 23 15 16 4 42 23 42

Output
3

Source: codeforces | Difficulty: EASY
Tags: Dynamic programming

Implementation

Greedy algorithms


Solutions:
n = int(input())
a = list(map(int, input().strip().split(' ')))
f = [4, 8, 15, 16, 23, 42]
x = [0 for _ in range(6)]
for i in range(n):
	if a[i] == 4:
		a[i] = 0
	elif a[i] == 8:
		a[i] = 1
	elif a[i] == 15:
		a[i] = 2
	elif a[i] == 16:
		a[i] = 3
	elif a[i] == 23:
		a[i] = 4
	elif a[i] == 42:
		a[i] = 5
	else:
		a[i] == 6
for i in a:
	if i >= 6:
		continue
	if i == 0:
		x[0] += 1
	elif x[i - 1] > 0:
		x[i - 1] -= 1
		x[i] += 1
print(n - x[-1] * 6)


n = int(input())
a = list(map(int, input().split()))
cnt4 = 0
cnt8 = 0
cnt15 = 0
cnt16 = 0
cnt23 = 0
cnt42 = 0
for i in a:
	if i == 4:
		cnt4 += 1
	if i == 8 and cnt4 > cnt8:
		cnt8 += 1
	if i == 15 and cnt8 > cnt15:
		cnt15 += 1
	if i == 16 and cnt15 > cnt16:
		cnt16 += 1
	if i == 23 and cnt16 > cnt23:
		cnt23 += 1
	if i == 42 and cnt23 > cnt42:
		cnt42 += 1
print(abs(n - cnt42 * 6))


a = (4, 8, 15, 16, 23, 42)
b = [0] + [int(input())] * 6
for x in input().split():
	i = a.index(int(x))
	b[i + 1] = max(b[i], b[i + 1] - 6)
print(b[6])


n = int(input())
a = list(map(int, input().split()))
b = [0, 4, 8, 15, 16, 23, 42]
cnt = [0, 0, 0, 0, 0, 0, 0]
i = 0
while i < n:
	if a[i] == b[1]:
		cnt[1] += 1
	else:
		t = b.index(a[i])
		if cnt[t - 1] > 0:
			cnt[t - 1] -= 1
			cnt[t] += 1
	i += 1
print(n - cnt[6] * 6)


n = int(input())
arr = [int(i) for i in input().split()]
a_c = [4, 8, 15, 16, 23, 42]
dit = [0, 0, 0, 0, 0, 0]
for i in arr:
	index = a_c.index(i)
	if index == 0:
		dit[index] += 1
	elif dit[index - 1]:
		dit[index] += 1
		dit[index - 1] -= 1
c = 9 ** 9
print(n - dit[5] * 6)


from collections import defaultdict as dfd
n = int(input())
arr = list(map(int, input().split()))
d = dfd(int)
for i in arr:
	if i == 4:
		d[i] += 1
	elif i == 8:
		if d[i] < d[4]:
			d[i] += 1
	elif i == 15:
		if d[i] < d[8]:
			d[i] += 1
	elif i == 16:
		if d[i] < d[15]:
			d[i] += 1
	elif i == 23:
		if d[i] < d[16]:
			d[i] += 1
	elif i == 42:
		if d[i] < d[23]:
			d[i] += 1
print(n - 6 * d[42])


n = int(input())
a = list(map(int, input().split()))
f = [0] * 6
dic = {}
for i in [4, 8, 15, 16, 23, 42]:
	dic[i] = 0
for i in a:
	if i == 4:
		dic[4] += 1
	elif i == 8:
		if dic[4] >= dic[8] + 1:
			dic[8] += 1
	elif i == 15:
		if dic[8] >= dic[15] + 1:
			dic[15] += 1
	elif i == 16:
		if dic[15] >= dic[16] + 1:
			dic[16] += 1
	elif i == 23:
		if dic[16] >= dic[23] + 1:
			dic[23] += 1
	elif i == 42:
		if dic[23] >= dic[42] + 1:
			dic[42] += 1
m = 9999999999999999999999
for i in [4, 8, 15, 16, 23, 42]:
	m = min([m, dic[i]])
print(n - 6 * m)


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())
sys.setrecursionlimit(1500)

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_right(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		l = list(In())
		z = [4, 8, 15, 16, 23, 42]
		d = {}
		for x in z:
			d[x] = 0
		for x in l:
			if x == 4:
				d[4] += 1
			elif x == 8:
				if d[4] >= 1:
					d[4] -= 1
					d[8] += 1
			elif x == 15:
				if d[8] >= 1:
					d[15] += 1
					d[8] -= 1
			elif x == 16:
				if d[15] >= 1:
					d[15] -= 1
					d[16] += 1
			elif x == 23:
				if d[16] >= 1:
					d[16] -= 1
					d[23] += 1
			elif x == 42:
				if d[23] >= 1:
					d[23] -= 1
					d[42] += 1
		print(n - 6 * d[42])
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


n = int(input())
arr = [x for x in input().split(' ')]
myMap = {'4': 0, '8': 0, '15': 0, '16': 0, '23': 0, '42': 0}
bad = 0

def doit(a, b):
	(a, b) = (str(a), str(b))
	if myMap[a] > myMap[b]:
		myMap[b] += 1
	else:
		global bad
		bad += 1
for item in arr:
	if item == '4':
		myMap[item] += 1
	elif item == '8':
		doit(4, 8)
	elif item == '15':
		doit(8, 15)
	elif item == '16':
		doit(15, 16)
	elif item == '23':
		doit(16, 23)
	else:
		doit(23, 42)
temp = min(myMap.values())
bad = bad + (sum(myMap.values()) - temp * 6)
print(bad)


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	a = list(map(int, input().split()))
	x = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
	val = [4, 8, 15, 16, 23, 42]
	ptr = [-1, -1, -1, -1, -1, -1]
	done = False
	sets = 0
	while not done:
		for p in range(6):
			if p == 0:
				while ptr[p] < n and (ptr[p] == -1 or a[ptr[p]] != val[p]):
					ptr[p] += 1
			else:
				while ptr[p] < n and (ptr[p] == -1 or a[ptr[p]] != val[p] or ptr[p] <= ptr[p - 1]):
					ptr[p] += 1
		if all((ptr[i] < n for i in range(6))):
			sets += 1
			for i in range(6):
				ptr[i] += 1
		else:
			done = True
	print(n - 6 * sets)
main()


seq = [4, 8, 15, 16, 23, 42]
n = int(input())
arr = map(int, input().split())
count = [0] * 6
ans = 0
for x in arr:
	i = seq.index(x)
	if i == 0:
		count[0] += 1
	elif count[i - 1] > 0:
		count[i - 1] -= 1
		count[i] += 1
print(n - count[5] * 6)


from sys import stdin
cand = [4, 8, 15, 16, 23, 42]

def solve(tc):
	n = int(stdin.readline().strip())
	li = list(map(int, stdin.readline().split()))
	remove = 0
	cum = [[0 for i in range(6)] for j in range(n + 1)]
	for i in range(1, n + 1):
		for x in range(6):
			cum[i][x] = cum[i - 1][x]
			if li[i - 1] == cand[x]:
				cum[i][x] += 1
			if x and cum[i][x] > cum[i][x - 1]:
				cum[i][x] -= 1
				remove += 1
	mini = min(cum[n])
	for i in cum[n]:
		remove += i - mini
	print(remove)
LOCAL_TEST = not __debug__
if LOCAL_TEST:
	infile = __file__.split('.')[0] + '-test.in'
	stdin = open(infile, 'r')
tcs = int(stdin.readline().strip()) if LOCAL_TEST else 1
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
key = [4, 8, 15, 16, 23, 42]
n = Int()
a = array()
C = defaultdict(int)
for i in range(n):
	for inSearch in range(6):
		if a[i] == key[inSearch] and inSearch > 0:
			if C[inSearch - 1] > C[inSearch]:
				C[inSearch] += 1
		if a[i] == key[inSearch] and inSearch == 0:
			C[inSearch] += 1
print(n - C[5] * 6)


from collections import defaultdict, OrderedDict
n = int(input())
arr = [*map(int, input().split())]
good = [4, 8, 15, 16, 23, 42]
good_d = defaultdict(int)
for a in arr:
	if a in good:
		if a == 4:
			good_d[a] += 1
		elif good_d[a] < good_d[good[good.index(a) - 1]]:
			good_d[a] += 1
good_d = OrderedDict(sorted(good_d.items(), key=lambda t: t[0]))
if len(good_d) != len(good):
	is_good = False
else:
	r = min(good_d.values())
	is_good = True
	for ((k, v), good_v) in zip(good_d.items(), good):
		if k != good_v:
			is_good = False
if is_good:
	print(len(arr) - r * 6)
else:
	print(len(arr))


n = int(input())
a = list(map(int, input().split()))
pattern = [4, 8, 15, 16, 23, 42]
count = [0] * 6
for (i, val) in enumerate(a):
	ptr = pattern.index(val)
	if ptr == 0:
		count[ptr] += 1
	else:
		count[ptr] = min(count[ptr - 1], count[ptr] + 1)
print(n - 6 * count[-1])


import sys
import math
import collections
import heapq
import decimal
input = sys.stdin.readline
n = int(input())
l = [int(i) for i in input().split()]
freq = [0] * 6
for i in range(n):
	if l[i] == 4:
		freq[0] += 1
	elif l[i] == 8:
		if freq[0] > freq[1]:
			freq[1] += 1
	elif l[i] == 15:
		if freq[1] > freq[2]:
			freq[2] += 1
	elif l[i] == 16:
		if freq[2] > freq[3]:
			freq[3] += 1
	elif l[i] == 23:
		if freq[3] > freq[4]:
			freq[4] += 1
	elif freq[4] > freq[5]:
		freq[5] += 1
print(n - freq[5] * 6)


a = []
n = int(input())
if n == 0:
	print(0)
(s_1, s_2, s_3, s_4, s_5, s_6) = (0, 0, 0, 0, 0, 0)
for c in input().split():
	x = int(c)
	if x == 4:
		s_1 += 1
	if x == 8 and s_1:
		s_1 -= 1
		s_2 += 1
	if x == 15 and s_2:
		s_2 -= 1
		s_3 += 1
	if x == 16 and s_3:
		s_3 -= 1
		s_4 += 1
	if x == 23 and s_4:
		s_4 -= 1
		s_5 += 1
	if x == 42 and s_5:
		s_5 -= 1
		s_6 += 1
print(n - s_6 * 6)


n = int(input())
arr = list(map(int, input().split()))
ans = [4, 8, 15, 16, 23, 42]
if n < 6:
	print(n)
else:
	ans1 = [0] * 6
	for a in arr:
		pos = ans.index(a)
		if pos == 0:
			ans1[0] += 1
		elif ans1[pos - 1] > 0:
			ans1[pos - 1] -= 1
			ans1[pos] += 1
	print(n - 6 * ans1[5])


def giveind(i):
	if i == 8:
		return 4
	elif i == 15:
		return 8
	elif i == 16:
		return 15
	elif i == 23:
		return 16
	elif i == 42:
		return 23
n = int(input())
arr = list(map(int, input().split()))
cnt = {}
cnt[4] = 0
cnt[8] = 0
cnt[15] = 0
cnt[16] = 0
cnt[23] = 0
cnt[42] = 0
for i in range(n):
	if arr[i] == 4:
		cnt[4] += 1
	elif cnt[giveind(arr[i])] > 0:
		cnt[giveind(arr[i])] -= 1
		cnt[arr[i]] += 1
ans = n - 6 * cnt[42]
print(ans)


from sys import stdin, stdout
n = int(stdin.readline())
l = list(map(int, stdin.readline().split()))
shan = [0] * 6
for a in l:
	if a == 4:
		shan[0] += 1
	elif a == 8:
		if shan[0] > 0:
			shan[0] -= 1
			shan[1] += 1
	elif a == 15:
		if shan[1] > 0:
			shan[1] -= 1
			shan[2] += 1
	elif a == 16:
		if shan[2] > 0:
			shan[2] -= 1
			shan[3] += 1
	elif a == 23:
		if shan[3] > 0:
			shan[3] -= 1
			shan[4] += 1
	elif a == 42:
		if shan[4] > 0:
			shan[4] -= 1
			shan[5] += 1
print(n - shan[-1] * 6)


def helper(s):
	if s == 4:
		return 0
	if s == 8:
		return 1
	if s == 15:
		return 2
	if s == 16:
		return 3
	if s == 23:
		return 4
	if s == 42:
		return 5
n = int(input())
arr = [int(x) for x in input().split()]
temp = [0 for i in range(6)]
for i in arr:
	if i == 4:
		temp[helper(i)] += 1
	elif temp[helper(i) - 1] > 0:
		temp[helper(i) - 1] -= 1
		temp[helper(i)] += 1
print(n - 6 * temp[-1])


n = int(input())
arr = map(int, input().split(' '))
nums = {4: 1, 8: 2, 15: 3, 16: 4, 23: 5, 42: 6}
pos = []
cnt = [0] * 7
for i in arr:
	pos.append(nums[i])
for i in pos:
	if i == 1:
		cnt[i] += 1
	elif cnt[i - 1] > 0:
		cnt[i] += 1
		cnt[i - 1] -= 1
print(n - cnt[6] * 6)


n = int(input())
m = {}
for (i, x) in enumerate('4 8 15 16 23 42'.split()):
	m[x] = i
c = [0] * 6
cnt = 0
for i in input().split():
	if m[i] == 0 or c[m[i]] < c[m[i] - 1]:
		c[m[i]] += 1
		if i == '42' and all((x - cnt > 0 for x in c)):
			cnt += 1
print(n - cnt * 6)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
l = list(map(int, input().split()))
d = [0] * 6
ans = 0
for i in range(n):
	if l[i] == 4:
		d[0] += 1
	elif l[i] == 8:
		d[1] += 1
		if d[1] > d[0]:
			d[1] -= 1
			ans += 1
	elif l[i] == 15:
		d[2] += 1
		if d[2] > d[1]:
			d[2] -= 1
			ans += 1
	elif l[i] == 16:
		d[3] += 1
		if d[3] > d[2]:
			d[3] -= 1
			ans += 1
	elif l[i] == 23:
		d[4] += 1
		if d[4] > d[3]:
			d[4] -= 1
			ans += 1
	elif l[i] == 42:
		d[5] += 1
		if d[5] > d[4]:
			d[5] -= 1
			ans += 1
s = min(d)
for i in range(6):
	ans += d[i] - s
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
s = [0, 0, 0, 0, 0, 0]
k = {}
k[4] = 0
k[8] = 1
k[15] = 2
k[16] = 3
k[23] = 4
k[42] = 5
for i in range(n):
	x = k[a[i]]
	f = False
	while x != 0:
		x -= 1
		if s[k[a[i]]] >= s[x]:
			f = True
			break
	if not f:
		s[k[a[i]]] += 1
	else:
		continue
print(n - min(s) * 6)


import math
num = int(input())
alpha = (0, 4, 8, 15, 16, 23, 42)
beta = [num] + [0] * 6
for x in input().split():
	i = alpha.index(int(x))
	if beta[i - 1]:
		beta[i - 1] -= 6
		beta[i] += 6
print(num - beta[6])


n = int(input())
s = input().split()
d = ['4', '8', '15', '16', '23', '42']
p = {0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
ans = 0
for i in s:
	if d.index(i) == 0:
		p[d.index(i)] += 1
	elif p[d.index(i) - 1] > p[d.index(i)]:
		p[d.index(i)] += 1
	else:
		ans += 1
print(ans + sum(p.values()) - 6 * min(p.values()))


from sys import stdin
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
hg = lambda x, y: (y + x - 1) // x * x
n = I()
val = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
v = [0] * (n + 1)
ind = [deque() for i in range(50)]
ind[0] = deque([i for i in range(n + 1)])
dlt = 0
for i in R():
	if not ind[val[i]]:
		dlt += 1
	else:
		v[ind[val[i]][0]] += 1
		ind[val[i] + 1] += (ind[val[i]].popleft(),)
for i in v:
	if i != 6:
		dlt += i
print(dlt)


n = int(input())
A = [int(i) for i in input().split()]
solv = [4, 8, 15, 16, 23, 42]
count = [0] * 6
for i in range(n):
	x = solv.index(A[i])
	if x == 0:
		count[0] += 1
	elif x >= 1:
		if count[x - 1] > 0:
			count[x - 1] = count[x - 1] - 1
			count[x] += 1
print(n - 6 * count[5])


a = int(input())
z = list(map(int, input().split()))
r = [4, 8, 15, 16, 23, 42]
temp = [0, 0, 0, 0, 0, 0]
if 4 not in z:
	print(len(z))
	exit()
s = z.index(4)
temp[0] = 1
for i in range(s + 1, len(z)):
	for j in range(len(r)):
		if r[j] == z[i]:
			break
	flag = 0
	for t in range(j):
		if temp[t] >= temp[j] + 1:
			continue
		else:
			flag = 1
			break
	if flag == 0:
		temp[j] += 1
print(len(z) - min(temp) * 6)


n = int(input())
l = [int(i) for i in input().split()]
dp = [0 for i in range(6)]
for i in l:
	if i == 4:
		dp[0] += 1
	elif i == 8 and dp[0] - dp[1] > 0:
		dp[1] += 1
	elif i == 15 and dp[1] - dp[2] > 0:
		dp[2] += 1
	elif i == 16 and dp[2] - dp[3] > 0:
		dp[3] += 1
	elif i == 23 and dp[3] - dp[4] > 0:
		dp[4] += 1
	elif i == 42 and dp[4] - dp[5] > 0:
		dp[5] += 1
print(n - 6 * dp[5])


Dict = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
n = int(input())
for val in list(map(int, input().split())):
	if val == 4:
		Dict[4] += 1
	if val == 8:
		if Dict[4] > 0:
			Dict[8] += 1
			Dict[4] -= 1
	if val == 15:
		if Dict[8] > 0:
			Dict[15] += 1
			Dict[8] -= 1
	if val == 16:
		if Dict[15] > 0:
			Dict[16] += 1
			Dict[15] -= 1
	if val == 23:
		if Dict[16] > 0:
			Dict[23] += 1
			Dict[16] -= 1
	if val == 42:
		if Dict[23] > 0:
			Dict[42] += 1
			Dict[23] -= 1
print(n - 6 * Dict[42])


import sys
n = int(input())
arr = list(map(int, input().split()))
countOne = 0
countTwo = 0
countThree = 0
countFour = 0
countFive = 0
countSix = 0
for i in arr:
	if i == 4:
		countOne += 1
	elif i == 8:
		if countTwo + 1 <= countOne:
			countTwo += 1
	elif i == 15:
		if countThree + 1 <= countTwo:
			countThree += 1
	elif i == 16:
		if countFour + 1 <= countThree:
			countFour += 1
	elif i == 23:
		if countFive + 1 <= countFour:
			countFive += 1
	elif i == 42:
		if countSix + 1 <= countFive:
			countSix += 1
answer = n - countSix * 6
print(answer)


a = [0] + [int(input())] * 6
for x in input().split():
	i = '4 8 15162342'.find(x) // 2
	a[i + 1] = max(a[i], a[i + 1] - 6)
print(a[6])


c = [0 for i in range(6)]
ex = [4, 8, 15, 16, 23, 42]
q = int(input())
inp = input().split()
l = []
for j in range(q):
	l.append(int(inp[j]))
for el in l:
	if el == 4:
		c[0] += 1
	for i in range(1, 6):
		if el == ex[i] and c[i - 1] > 0:
			c[i] += 1
			c[i - 1] -= 1
print(q - c[5] * 6)


n = int(input())
a = list(map(int, input().split()))
p = [4, 8, 15, 16, 23, 42]
cnt = [0] * 6
for i in range(n):
	a[i] = p.index(a[i])
for i in range(n):
	if a[i] == 0:
		cnt[a[i]] += 1
	elif cnt[a[i] - 1] > 0:
		cnt[a[i] - 1] -= 1
		cnt[a[i]] += 1
print(n - 6 * cnt[5])


from __future__ import division, print_function
from io import BytesIO, IOBase
import os, sys, math, heapq, copy
from collections import defaultdict, deque
from bisect import bisect_left, bisect_right
from functools import cmp_to_key
from itertools import permutations, combinations, combinations_with_replacement
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 1000000007

def get_int():
	return int(sys.stdin.readline().strip())

def get_str():
	return sys.stdin.readline().strip()

def get_float():
	return float(sys.stdin.readline().strip())

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_strs():
	return map(str, sys.stdin.readline().strip().split())

def get_floats():
	return map(float, sys.stdin.readline().strip().split())

def list_ints():
	return list(map(int, sys.stdin.readline().strip().split()))

def list_strs():
	return list(map(str, sys.stdin.readline().strip().split()))

def list_floats():
	return list(map(float, sys.stdin.readline().strip().split()))
n = get_int()
l = list_ints()
a = [0] * 6
for i in l:
	if i == 4:
		a[0] += 1
	elif i == 8:
		a[1] = min(a[0], a[1] + 1)
	elif i == 15:
		a[2] = min(a[1], a[2] + 1)
	elif i == 16:
		a[3] = min(a[2], a[3] + 1)
	elif i == 23:
		a[4] = min(a[3], a[4] + 1)
	else:
		a[5] = min(a[4], a[5] + 1)
print(n - a[5] * 6)


from collections import defaultdict
input()
arr = list(map(int, input().strip().split(' ')))
count = defaultdict(int)
previous = {8: 4, 15: 8, 16: 15, 23: 16, 42: 23}
for (idx, num) in enumerate(arr):
	if num == 4:
		count[4] += 1
	elif count[previous[num]] > 0:
		count[previous[num]] -= 1
		count[num] += 1
print(len(arr) - count[42] * 6)


def pos(i):
	if i == 4:
		return 0
	elif i == 8:
		return 1
	elif i == 15:
		return 2
	elif i == 16:
		return 3
	elif i == 23:
		return 4
	else:
		return 5
n = int(input())
l = list(map(int, input().split()))
cnt = [0] * 6
for i in l:
	if pos(i) == 0:
		cnt[0] += 1
	elif cnt[pos(i) - 1] > 0:
		cnt[pos(i) - 1] -= 1
		cnt[pos(i)] += 1
print(n - 6 * cnt[5])


import sys
read = sys.stdin.read
readlines = sys.stdin.readlines

def main():
	(n, *a) = map(int, read().split())
	if n < 6:
		print(n)
		sys.exit()
	nums = [0] * 43
	for ae in a:
		if ae == 4:
			nums[4] += 1
		if ae == 8:
			nums[8] = min(nums[4], nums[8] + 1)
		if ae == 15:
			nums[15] = min(nums[8], nums[15] + 1)
		if ae == 16:
			nums[16] = min(nums[15], nums[16] + 1)
		if ae == 23:
			nums[23] = min(nums[16], nums[23] + 1)
		if ae == 42:
			nums[42] = min(nums[23], nums[42] + 1)
		r = n - nums[42] * 6
	print(r)
main()


n = int(input())
x = [4, 8, 15, 16, 23, 42]
r = [0] * len(x)
z = 0
for v in map(int, input().split()):
	i = x.index(v)
	if not i or r[i - 1] > r[i]:
		r[i] += 1
	else:
		z += 1
z += sum((v - r[-1] for v in r))
print(z)


n = int(input())
num = [4, 8, 15, 16, 23, 42]
a = list(map(int, input().split()))
ans = 0
if n < 6:
	print(n)
else:
	ind = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
	for i in a:
		if i == 4:
			ind[4] += 1
		elif i == 8 and ind[4] > 0:
			ind[8] += 1
			ind[4] -= 1
		elif i == 15 and ind[8] > 0:
			ind[15] += 1
			ind[8] -= 1
		elif i == 16 and ind[15] > 0:
			ind[16] += 1
			ind[15] -= 1
		elif i == 23 and ind[16] > 0:
			ind[23] += 1
			ind[16] -= 1
		elif i == 42 and ind[23] > 0:
			ind[42] += 1
			ind[23] -= 1
		else:
			ans += 1
	for i in range(5):
		ans += ind[num[i]] * (i + 1)
	print(ans)


from sys import stdin, stdout, exit
n = int(input())
a = list(map(int, stdin.readline().split()))
d = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
cts = [0] * 6
ans = 0
for i in range(n):
	idx = d[a[i]]
	cts[idx] += 1
	if idx > 0 and cts[idx] > min(cts[:idx]):
		ans += 1
		cts[idx] -= 1
goodable = min(cts)
ans += sum([c - goodable for c in cts])
stdout.write(str(ans) + '\n')


import sys
input = sys.stdin.readline

def main():
	N = int(input())
	A = list(map(int, input().split()))
	nums = [4, 8, 15, 16, 23, 42]
	count = {}
	for num in nums:
		count[num] = 0
	for a in A:
		if a in nums:
			if a == 4:
				count[a] += 1
			else:
				ind = nums.index(a)
				prem = nums[ind - 1]
				if count[prem] > count[a]:
					count[a] += 1
	M = count[42]
	ans = N - M * 6
	print(ans)
main()


n = int(input())
posl = [4, 8, 15, 16, 23, 42]
posl_d = {}
for (i, elem) in enumerate(posl):
	posl_d[elem] = i
lenp = len(posl)
posl_list = [0] * lenp
for i in input().split():
	i = int(i)
	try:
		indd = posl_d[i]
	except:
		continue
	if indd == 0:
		posl_list[indd + 1] += 1
		continue
	if posl_list[indd]:
		posl_list[indd] -= 1
		if indd == lenp - 1:
			n -= lenp
		else:
			posl_list[indd + 1] += 1
print(n)


n = int(input())
l = list(map(int, input().split()))
import heapq
(q2, q3, q4, q5, q6) = ([], [], [], [], [])
power_l = []
seq = [4, 8, 15, 16, 23, 42]
rem = 0
for i in l:
	if i not in seq:
		rem += 1
	elif i == 4:
		power_l.append([4])
		q2.append(len(power_l) - 1)
	elif i == 8:
		if len(q2) == 0:
			rem += 1
		else:
			index = q2.pop()
			q3.append(index)
			power_l[index].append(8)
	elif i == 15:
		if len(q3) == 0:
			rem += 1
		else:
			index = q3.pop()
			q4.append(index)
			power_l[index].append(15)
	elif i == 16:
		if len(q4) == 0:
			rem += 1
		else:
			index = q4.pop()
			q5.append(index)
			power_l[index].append(16)
	elif i == 23:
		if len(q5) == 0:
			rem += 1
		else:
			index = q5.pop()
			q6.append(index)
			power_l[index].append(23)
	elif i == 42:
		if len(q6) == 0:
			rem += 1
		else:
			index = q6.pop()
			power_l[index].append(42)
for i in power_l:
	if i != seq:
		rem += len(i)
print(rem)


n = int(input())
a = list(map(int, input().split(' ')))
data = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
req1 = 0
req2 = 0
req3 = 0
req4 = 0
req5 = 0
seqs = []
ans = 0
for c in a:
	if data[c] == 0:
		seqs.append([c])
	elif data[c] == 1:
		if len(seqs) >= req1 + 1 and len(seqs[req1]) == 1:
			seqs[req1].append(c)
			req1 += 1
		else:
			ans += 1
	elif data[c] == 2:
		if len(seqs) >= req2 + 1 and len(seqs[req2]) == 2:
			seqs[req2].append(c)
			req2 += 1
		else:
			ans += 1
	elif data[c] == 3:
		if len(seqs) >= req3 + 1 and len(seqs[req3]) == 3:
			seqs[req3].append(c)
			req3 += 1
		else:
			ans += 1
	elif data[c] == 4:
		if len(seqs) >= req4 + 1 and len(seqs[req4]) == 4:
			seqs[req4].append(c)
			req4 += 1
		else:
			ans += 1
	elif data[c] == 5:
		if len(seqs) >= req5 + 1 and len(seqs[req5]) == 5:
			seqs[req5].append(c)
			req5 += 1
		else:
			ans += 1
for l in seqs:
	if len(l) != 6:
		ans += len(l)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
arr4 = []
arr8 = []
arr15 = []
arr16 = []
arr23 = []
arr42 = []
for q in range(n):
	if arr[q] == 4:
		arr4.append(q)
	elif arr[q] == 8:
		arr8.append(q)
	elif arr[q] == 15:
		arr15.append(q)
	elif arr[q] == 16:
		arr16.append(q)
	elif arr[q] == 23:
		arr23.append(q)
	else:
		arr42.append(q)
p4 = 0
p8 = 0
p15 = 0
p16 = 0
p23 = 0
p42 = 0
count = 0
while p4 < len(arr4) and p8 < len(arr8) and (p15 < len(arr15)) and (p16 < len(arr16)) and (p23 < len(arr23)) and (p42 < len(arr42)):
	if arr4[p4] < arr8[p8]:
		if arr8[p8] < arr15[p15]:
			if arr15[p15] < arr16[p16]:
				if arr16[p16] < arr23[p23]:
					if arr23[p23] < arr42[p42]:
						p4 += 1
						p8 += 1
						p15 += 1
						p16 += 1
						p23 += 1
						p42 += 1
						count += 1
					else:
						p42 += 1
				else:
					p23 += 1
			else:
				p16 += 1
		else:
			p15 += 1
	else:
		p8 += 1
print(n - 6 * count)


from bisect import bisect
t = int(input())
a = [int(x) for x in input().split()]
xx = [4, 8, 15, 16, 23, 42]
y = {x: [] for x in xx}
for i in range(len(a)):
	if a[i] in y:
		y[a[i]].append(i)
ans = 0
l8 = 0
l15 = 0
l16 = 0
l23 = 0
l42 = 0
for i in y[4]:
	l8 = max(l8, i)
	l8 = bisect(y[8], l8)
	if l8 == len(y[8]):
		break
	l8 = y[8][l8]
	l15 = max(l15, l8)
	l15 = bisect(y[15], l15)
	if l15 == len(y[15]):
		break
	l15 = y[15][l15]
	l16 = max(l16, l15)
	l16 = bisect(y[16], l16)
	if l16 == len(y[16]):
		break
	l16 = y[16][l16]
	l23 = max(l23, l16)
	l23 = bisect(y[23], l23)
	if l23 == len(y[23]):
		break
	l23 = y[23][l23]
	l42 = max(l42, l23)
	l42 = bisect(y[42], l42)
	if l42 == len(y[42]):
		break
	l42 = y[42][l42]
	ans += 1
ans = len(a) - 6 * ans
print(ans)


from sys import exit
N = int(input())
L = list(map(int, input().split(' ')))
dictio = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
tabs = [0] * (N + 1)
ind = [0, None, None, None, None, None]

def lower_lim(posl):
	for j in range(posl - 1, -1, -1):
		if ind[j] is not None:
			return ind[j]
	exit(1)
for e in L:
	pos = dictio[e]
	if ind[pos] is not None:
		tabs[ind[pos]] += 1
		if pos < 5 and ind[pos + 1] is None:
			ind[pos + 1] = ind[pos]
		if pos > 0 and lower_lim(pos) == ind[pos] + 1:
			ind[pos] = None
		else:
			ind[pos] += 1
i = 0
for i in range(N + 1):
	if tabs[i] != 6:
		break
print(N - 6 * i)


n = int(input())
a = (4, 8, 15, 16, 23, 42)
d = dict(zip(a, range(6)))
b = [0] + [n] * 6
for x in input().split():
	i = d[int(x)]
	if b[i] < n:
		b[i] += 6
		b[i + 1] -= 6
print(b[6])


import math
import sys
import math
import sys
n = int(input())
d = list(map(int, input().split()))
MAX = 5 * 10 ** 5
seq = {4: 8, 8: 15, 15: 16, 16: 23, 23: 42, 42: 4}
need = {4: MAX, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
c = 0
for i in d:
	if i in need:
		if need[i] != 0:
			need[i] -= 1
			need[seq[i]] += 1
			if i == 42:
				c += 1
print(n - c * 6)


def solve():
	n = int(input())
	l = list(map(int, input().split()))
	mp = [0 for _ in range(50)]
	mp[4] = 0
	mp[8] = 1
	mp[15] = 2
	mp[16] = 3
	mp[23] = 4
	mp[42] = 5
	arr = [0, 0, 0, 0, 0, 0]
	for m in l:
		if mp[m] == 0:
			arr[mp[m]] += 1
		elif arr[mp[m] - 1] > 0:
			arr[mp[m]] += 1
			arr[mp[m] - 1] -= 1
	return n - arr[5] * 6
	return n - found * 6
for _ in range(1):
	print(solve())


n = int(input())
arr = list(map(int, input().split()))
mp = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
cnt = [0] * 6
for i in range(n):
	if arr[i] == 4:
		cnt[mp[arr[i]]] += 1
	else:
		temp = cnt[mp[arr[i]]] + 1
		if cnt[mp[arr[i]] - 1] < temp:
			continue
		else:
			cnt[mp[arr[i]]] += 1
print(n - min(cnt) * 6)


n = int(input())
a = list(map(int, input().split()))
l = [4, 8, 15, 16, 23, 42]
d = [[] for i in range(6)]
ind = [0, 0, 0, 0, 0, 0]
ct = 0
for i in range(n):
	j = l.index(a[i])
	d[j].append(i)
p = -1
j = 0
while 1:
	for i in range(ind[j], len(d[j])):
		if d[j][i] >= p:
			ind[j] = i + 1
			p = d[j][i] + 1
			j += 1
			break
	else:
		break
	if j == 6:
		p = -1
		j = 0
		ct += 1
print(n - ct * 6)


n = int(input())
a = list(map(int, input().split()))
k = [None, 4, 8, 15, 16, 23, 42]
s = [n, 0, 0, 0, 0, 0, 0]
for ai in a:
	for i in range(6, 0, -1):
		if ai == k[i] and s[i - 1] > 0:
			s[i] += 1
			s[i - 1] -= 1
			break
print(n - 6 * s[-1])


n = int(input())
nums = [4, 8, 15, 16, 23, 42]
last = {x: 0 for x in nums}
for elem in map(int, input().split()):
	if elem == 4:
		last[elem] += 1
	elif elem in nums:
		idx = nums.index(elem)
		if last[nums[idx - 1]] > last[nums[idx]]:
			last[elem] += 1
print(n - 6 * min(last.values()))


a = [4, 8, 15, 16, 23, 42]
D = dict.fromkeys(a, 0)
n = int(input())
(*L,) = map(int, input().split())
for item in L:
	if item in a:
		count = 0
		for key in D:
			if key < item and D[key] > D[item]:
				count += 1
		if count == a.index(item):
			D[item] += 1
print(n - 6 * D[42])


n = int(input())
l = list(map(int, input().split()))
li4 = []
li48 = []
li4815 = []
li481516 = []
li48151623 = []
lif = []
for i in l:
	if i == 4:
		li4.append([4])
	if i == 8:
		if len(li4) != 0:
			li48.append([4, 8])
			li4.pop(-1)
	if i == 15:
		if len(li48) != 0:
			li4815.append([4, 8, 15])
			li48.pop(-1)
	if i == 16:
		if len(li4815) != 0:
			li481516.append([4, 8, 15, 16])
			li4815.pop(-1)
	if i == 23:
		if len(li481516) != 0:
			li48151623.append([4, 8, 15, 16, 23])
			li481516.pop(-1)
	if i == 42:
		if len(li48151623) != 0:
			lif.append([4, 8, 15, 16, 23, 42])
			li48151623.pop(-1)
ans = 0
for i in range(len(lif)):
	ans += len(lif[i])
print(n - ans)


from sys import stdin, stdout
a = int(stdin.readline())
(s, n, n1, n2, n3, n4, n5, n6) = (0, 0, 0, 0, 0, 0, 0, 0)
for i in stdin.readline().split():
	if i == '4':
		n += 1
	elif i == '8':
		if n:
			n -= 1
			n1 += 1
	elif i == '15':
		if n1:
			n1 -= 1
			n2 += 1
	elif i == '16':
		if n2:
			n2 -= 1
			n3 += 1
	elif i == '23':
		if n3:
			n3 -= 1
			n4 += 1
	elif i == '42':
		if n4:
			n4 -= 1
			n5 += 1
print(a - 6 * n5)


n = int(input())
a = list(map(int, input().split()))
c = [4, 8, 15, 16, 23, 42]
m = 0
d = [n, 0, 0, 0, 0, 0, 0]
for el in a:
	if el in c:
		j = c.index(el) + 1
		if d[j - 1] != 0:
			d[j] += 1
			d[j - 1] -= 1
print(n - d[6] * 6)


nElementos = int(input())
listaBom = [4, 8, 15, 16, 23, 42]
lista = [int(x) for x in input().split()]
lista4 = []
lista8 = []
lista15 = []
lista16 = []
lista23 = []
lista42 = []
for i in range(len(lista)):
	if lista[i] == 4:
		lista4.append(i)
	elif lista[i] == 8:
		lista8.append(i)
	elif lista[i] == 15:
		lista15.append(i)
	elif lista[i] == 16:
		lista16.append(i)
	elif lista[i] == 23:
		lista23.append(i)
	elif lista[i] == 42:
		lista42.append(i)
lista4.sort(reverse=True)
lista8.sort(reverse=True)
lista15.sort(reverse=True)
lista16.sort(reverse=True)
lista23.sort(reverse=True)
lista42.sort(reverse=True)
removidos = 0
while len(lista4) != 0 and len(lista8) != 0 and (len(lista15) != 0) and (len(lista16) != 0) and (len(lista23) != 0) and (len(lista42) != 0):
	if lista4[-1] > lista8[-1]:
		lista8.pop()
		removidos += 1
	elif lista8[-1] > lista15[-1]:
		lista15.pop()
		removidos += 1
	elif lista15[-1] > lista16[-1]:
		lista16.pop()
		removidos += 1
	elif lista16[-1] > lista23[-1]:
		lista23.pop()
		removidos += 1
	elif lista23[-1] > lista42[-1]:
		lista42.pop()
		removidos += 1
	else:
		lista4.pop()
		lista8.pop()
		lista15.pop()
		lista16.pop()
		lista23.pop()
		lista42.pop()
removidos += len(lista4) + len(lista8) + len(lista15) + len(lista16) + len(lista23) + len(lista42)
print(removidos)


from collections import deque
n = int(input())
nums = list(map(int, input().split()))
ayy = {}
ayy[4] = 0
ayy[8] = 0
ayy[15] = 0
ayy[16] = 0
ayy[23] = 0
ayy[42] = 0
for i in nums:
	if i == 4:
		ayy[i] = ayy[i] + 1
	elif i == 8:
		if ayy[4] > 0:
			ayy[4] = ayy[4] - 1
			ayy[8] = ayy[8] + 1
	elif i == 15:
		if ayy[8] > 0:
			ayy[8] = ayy[8] - 1
			ayy[15] = ayy[15] + 1
	elif i == 16:
		if ayy[15] > 0:
			ayy[15] = ayy[15] - 1
			ayy[16] = ayy[16] + 1
	elif i == 23:
		if ayy[16] > 0:
			ayy[16] = ayy[16] - 1
			ayy[23] = ayy[23] + 1
	elif i == 42:
		if ayy[23] > 0:
			ayy[23] = ayy[23] - 1
			ayy[42] = ayy[42] + 1
print(n - 6 * ayy[42])


n = int(input())
l = list(map(int, input().split()))
c = 0
a = [0] * 6
for i in range(n):
	if l[i] == 4:
		a[0] += 1
	elif l[i] == 8:
		if a[0] > a[1]:
			a[1] += 1
		else:
			c += 1
	elif l[i] == 15:
		if a[1] > a[2]:
			a[2] += 1
		else:
			c += 1
	elif l[i] == 16:
		if a[2] > a[3]:
			a[3] += 1
		else:
			c += 1
	elif l[i] == 23:
		if a[3] > a[4]:
			a[4] += 1
		else:
			c += 1
	elif a[4] > a[5]:
		a[5] += 1
	else:
		c += 1
m = min(a)
c += sum(a) - 6 * m
if m == 0:
	print(n)
else:
	print(c)


from collections import defaultdict as dc
import sys
import math
mod = 10 ** 9 + 7

def sinp():
	p = str(sys.stdin.readline())
	return p

def seive(n):
	p = [0] * (n + 1)
	for i in range(2, n):
		for j in range(2 * i, n + 1, i):
			p[i] = 1
	return p

def inp():
	p = int(sys.stdin.readline())
	return p

def line():
	p = list(map(int, sys.stdin.readline().split()))
	return p

def read_mat():
	n = inp()
	a = []
	for i in range(n):
		a.append(line())
	return a

def ind(a):
	return ord(a) - ord('A')

def solve(t):
	n = inp()
	a = line()
	p = {}
	p[4] = 0
	p[8] = 0
	p[15] = 0
	p[16] = 0
	p[23] = 0
	p[42] = 0
	for i in range(n):
		if a[i] == 4:
			p[4] += 1
		elif a[i] == 8:
			if p[4] > 0:
				p[4] -= 1
				p[8] += 1
		elif a[i] == 15:
			if p[8] > 0:
				p[8] -= 1
				p[15] += 1
		elif a[i] == 16:
			if p[15] > 0:
				p[15] -= 1
				p[16] += 1
		elif a[i] == 23:
			if p[16] > 0:
				p[23] += 1
				p[16] -= 1
		elif p[23] > 0:
			p[23] -= 1
			p[42] += 1
	print(n - 6 * p[42])
t = 1
for _ in range(t):
	solve(t)


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

def lin():
	return list(ain())

def indexof(l, v, l3):
	return l3[v]
n = int(input())
l = lin()
l1 = [[], [], [], [], [], []]
for i in range(n):
	x = l[i]
	if x == 4:
		l1[0] += [i]
	if x == 8:
		l1[1] += [i]
	if x == 15:
		l1[2] += [i]
	if x == 16:
		l1[3] += [i]
	if x == 23:
		l1[4] += [i]
	if x == 42:
		l1[5] += [i]
yu = 0
for x in l1:
	if len(x) == 0:
		yu = 1
		break
p = [0, 0, 0, 0, 0, 0]
c = 0
if yu == 0:
	while 1:
		f = 0
		if p[5] >= len(l1[5]):
			f = 1
		else:
			for i in range(0, 5):
				if p[i] >= len(l1[i]) or p[i + 1] >= len(l1[i + 1]):
					f = 1
					break
				while l1[i][p[i]] > l1[i + 1][p[i + 1]]:
					p[i + 1] += 1
					if p[i + 1] >= len(l1[i + 1]):
						f = 1
						break
				p[i] += 1
				if i == 4:
					p[i + 1] += 1
		if f == 0:
			c += 1
		else:
			break
	print(n - 6 * c)
else:
	print(n)


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List
n = int(input())
arr = list(map(int, input().split()))
al = collections.defaultdict(list)
for (i, c) in enumerate(arr):
	al[c].append(i)
sg = al[4]
for x in [8, 15, 16, 23, 42]:
	j = 0
	for i in range(len(al[x])):
		if j == len(sg):
			break
		if al[x][i] > sg[j]:
			sg[j] = al[x][i]
			j += 1
	sg = sg[:j]
print(n - 6 * len(sg))


N = int(input())
l = list(map(int, input().split()))
d = dict()
d[4] = 0
d[8] = 0
d[15] = 0
d[16] = 0
d[23] = 0
d[42] = 0
l1 = [4, 8, 15, 16, 23, 42]
for i in range(N):
	if l[i] == 4:
		d[4] += 1
	elif l[i] == 8:
		if d[4] > d[8]:
			d[8] += 1
	elif l[i] == 15:
		if d[8] > d[15]:
			d[15] += 1
	elif l[i] == 16:
		if d[15] > d[16]:
			d[16] += 1
	elif l[i] == 23:
		if d[16] > d[23]:
			d[23] += 1
	elif l[i] == 42:
		if d[23] > d[42]:
			d[42] += 1
print(N - d[42] * 6)


import sys

def main():
	n = int(sys.stdin.readline())
	lst = list(map(int, sys.stdin.readline().split()))
	normal = [4, 8, 15, 16, 23, 42]
	copy = [0] * 6
	for i in range(n):
		fix = normal.index(lst[i])
		if fix == 0 or copy[fix - 1] > copy[fix]:
			copy[fix] += 1
	sys.stdout.write(str(n - copy[-1] * 6))
main()


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, size, link):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
dick = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
n = int(input())
a = int_array()
counts = [0] * 6
for i in range(n):
	a[i] = dick[a[i]]
for i in range(n):
	if a[i] == 0:
		counts[0] += 1
	elif counts[a[i] - 1] > 0:
		counts[a[i] - 1] -= 1
		counts[a[i]] += 1
print(n - 6 * counts[-1])


import sys
input = sys.stdin.readline
n = int(input())
a_list = list(map(int, input().split()))
arr = [4, 8, 15, 16, 23, 42]
cnt_list = [0] * 6
ans = 0
for a in a_list:
	for (i, b) in enumerate(arr):
		if a == b:
			if i > 0:
				if cnt_list[i - 1] > cnt_list[i]:
					cnt_list[i] = cnt_list[i] + 1
				else:
					ans += 1
			else:
				cnt_list[i] = cnt_list[i] + 1
			break
check = cnt_list[-1]
for cnt in cnt_list:
	ans += max(cnt - check, 0)
print(ans)


n = int(input())
c4 = c8 = c15 = c16 = c23 = c42 = 0
a = list(map(int, input().split()))
for i in range(n):
	if a[i] == 4:
		c4 += 1
	elif a[i] == 8:
		c8 = min(c4, c8 + 1)
	elif a[i] == 15:
		c15 = min(c8, c15 + 1)
	elif a[i] == 16:
		c16 = min(c15, c16 + 1)
	elif a[i] == 23:
		c23 = min(c16, c23 + 1)
	elif a[i] == 42:
		c42 = min(c23, c42 + 1)
print(n - c42 * 6)


while 1:
	n = int(input())
	A = list(map(int, input().split(' ')))
	T = [4, 8, 15, 16, 23, 42]
	j = 0
	l1 = len(A)
	c1 = 0
	F = [0] * 6
	for i in range(n):
		if A[i] == 4:
			F[0] += 1
		if A[i] == 8:
			F[1] += 1
		if A[i] == 15:
			F[2] += 1
		if A[i] == 16:
			F[3] += 1
		if A[i] == 23:
			F[4] += 1
		if A[i] == 42:
			F[5] += 1
	req = min(F)
	if req == 0:
		print(n)
		break
	B = [0] * 6
	g = F[5] * 6
	for i in range(n):
		if i == l1 - 1:
			t1 = c1
			t2 = A[j]
			t3 = j
		if j == 5:
			j = 0
		if A[i] == 4:
			if B[0] < req:
				B[0] += 1
			else:
				c1 += 1
				continue
		if A[i] == 8:
			if B[1] < req and B[1] < B[0]:
				B[1] += 1
			else:
				c1 += 1
				continue
		if A[i] == 15:
			if B[2] < req and B[2] < B[1]:
				B[2] += 1
			else:
				c1 += 1
				continue
		if A[i] == 16:
			if B[3] < req and B[3] < B[2]:
				B[3] += 1
			else:
				c1 += 1
				continue
		if A[i] == 23:
			if B[4] < req and B[4] < B[3]:
				B[4] += 1
				j = 1
			else:
				c1 += 1
				continue
		if A[i] == 42:
			if B[5] < req and B[5] < B[4]:
				B[5] += 1
			else:
				c1 += 1
				continue
	print(n - 6 * B[5])
	break


n = int(input())
a = list(map(int, input().split()))
b = [4, 8, 15, 16, 23, 42]
c = [0] * 6
for i in range(len(a)):
	x = b.index(a[i])
	if x == 0:
		c[0] += 1
	elif c[x] < c[x - 1]:
		c[x] += 1
print(len(a) - c[5] * 6)


n = int(input())
a = list(map(int, input().split()))
d = {8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
d2 = {8: 15, 15: 16, 16: 23, 23: 42}
waste = 0
for i in a:
	if i == 4:
		d[8] += 1
	elif not d[i]:
		waste += 1
	elif i == 42:
		d[42] -= 1
	else:
		d[i] -= 1
		d[d2[i]] += 1
c = 1
for (k, v) in d.items():
	waste += v * c
	c += 1
print(waste)


n = int(input())
l = list(map(int, input().split()))
A = [0, 0, 0, 0, 0, 0]
s = 0
if n < 6:
	print(n)
else:
	for I in l:
		if I == 4:
			A[0] += 1
			continue
		elif I == 8:
			A[1] += 1
			if A[1] > A[0]:
				A[1] -= 1
				s += 1
				continue
		elif I == 15:
			A[2] += 1
			if A[2] > A[1]:
				A[2] -= 1
				s += 1
				continue
		elif I == 16:
			A[3] += 1
			if A[3] > A[2]:
				A[3] -= 1
				s += 1
				continue
		elif I == 23:
			A[4] += 1
			if A[4] > A[3]:
				A[4] -= 1
				s += 1
				continue
		else:
			A[5] += 1
			if A[5] > A[4]:
				A[5] -= 1
				s += 1
				continue
	for j in A:
		s += j - min(A)
	print(s)


n = int(input())
ai = list(map(int, input().split()))
ar = [0] * 7
ar[0] = n // 6
nums = [4, 8, 15, 16, 23, 42]
ans = 0
for num in ai:
	try:
		ind = nums.index(num)
		if ar[ind] == 0:
			ans += 1
		else:
			ar[ind] -= 1
			ar[ind + 1] += 1
	except:
		ans += 1
for i in range(6):
	ans += ar[i] * i
print(ans)


from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def solve():
	n = ii()
	a = li()
	f = {}
	c = 0
	for i in [4, 8, 15, 16, 23, 42]:
		f[i] = c
		c += 1
	cnt = [0] * 6
	for i in a:
		x = f[i]
		f1 = 0
		for j in range(x):
			if cnt[x] == cnt[j]:
				f1 = 1
				break
		if f1:
			continue
		cnt[x] += 1
	x = min(cnt) * 6
	print(n - x)
solve()


order = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
array_size = int(input())
array = list(map(int, input().split(' ')))
frequencies = [0, 0, 0, 0, 0, 0]
elements_to_remove = 0
for i in range(array_size):
	if not array[i] in order:
		elements_to_remove += 1
		continue
	else:
		index = order[array[i]]
		if index == 0:
			frequencies[0] += 1
		else:
			frequencies[index] += 1
			if frequencies[index] > frequencies[index - 1]:
				frequencies[index] -= 1
				elements_to_remove += 1
minfreq = min(frequencies)
for f in frequencies:
	elements_to_remove += f - minfreq
print(elements_to_remove)


import os
import sys
import string
import math

def solution(nums):
	keys = [4, 8, 15, 16, 23, 42]
	counts = [0] * 6
	for num in nums:
		if num == 4:
			counts[0] += 1
			continue
		i = keys.index(num)
		if counts[i - 1] > 0:
			counts[i - 1] -= 1
			counts[i] += 1
	return len(nums) - 6 * counts[-1]

def main(args):
	print(solution(args))

def parse():
	input()
	case = [int(s) for s in input().split(' ')]
	return case
main(parse())


n = int(input())
a = list(map(int, input().split()))
p = dict()
b = [4, 8, 15, 16, 23, 42]
for i in b:
	p[i] = 0
b = []
count = 0
for i in a:
	if i in p:
		b.append(i)
	else:
		count += 1
a = []
a = [] + b
for i in a:
	if i == 4:
		p[i] += 1
	elif i == 8:
		if p[4] - 1 >= p[8]:
			p[8] += 1
		else:
			count += 1
	elif i == 15:
		if p[8] - 1 >= p[15]:
			p[15] += 1
		else:
			count += 1
	elif i == 16:
		if p[15] - 1 >= p[16]:
			p[16] += 1
		else:
			count += 1
	elif i == 23:
		if p[16] - 1 >= p[23]:
			p[23] += 1
		else:
			count += 1
	elif i == 42:
		if p[23] - 1 >= p[42]:
			p[42] += 1
		else:
			count += 1
print(len(a) - 6 * p[42])


n = int(input())
a = list(map(int, input().split()))
g = [4, 8, 15, 16, 23, 42]
x = [0, 0, 0, 0, 0, 0]
for i in range(n):
	p = g.index(a[i])
	if p == 0 or x[p - 1] > x[p]:
		x[p] += 1
b = min(x)
print(n - b * 6)


Four = 0
Eit = 0
Fifteen = 0
Sixteen = 0
TwentyThree = 0
FOTITUebana = 0
Nexia = int(input())
Numbers = list(map(int, input().split()))
for i in Numbers:
	if i == 4:
		Four += 1
	elif i == 8 and Four > 0:
		Four -= 1
		Eit += 1
	elif i == 15 and Eit > 0:
		Eit -= 1
		Fifteen += 1
	elif i == 16 and Fifteen > 0:
		Fifteen -= 1
		Sixteen += 1
	elif i == 23 and Sixteen > 0:
		Sixteen -= 1
		TwentyThree += 1
	elif i == 42 and TwentyThree > 0:
		TwentyThree -= 1
		FOTITUebana += 1
print(Nexia - FOTITUebana * 6)


liste = [4, 8, 15, 16, 23, 42]
pos = []
n = int(input())
arr = list(map(int, input().split()))
count = 0
k = 0
seq = [0 for i in range(6)]
if n < 6:
	print(n)
else:
	for i in range(n):
		if arr[i] == 4:
			arr[i] = 0
		elif arr[i] == 8:
			arr[i] = 1
		elif arr[i] == 15:
			arr[i] = 2
		elif arr[i] == 16:
			arr[i] = 3
		elif arr[i] == 23:
			arr[i] = 4
		elif arr[i] == 42:
			arr[i] = 5
	for i in range(n):
		if arr[i] == 0:
			seq[0] += 1
		elif seq[arr[i] - 1] > 0:
			seq[arr[i] - 1] -= 1
			seq[arr[i]] += 1
	print(n - seq[5] * 6)


n = int(input())
nums = list(map(int, input().split()))
(fs, es, fivs, ss, ts, fts) = (0, 0, 0, 0, 0, 0)
for num in nums:
	if num == 4:
		fs += 1
	if fs - es > 0 and num == 8:
		es += 1
	if es - fivs > 0 and num == 15:
		fivs += 1
	if fivs - ss > 0 and num == 16:
		ss += 1
	if ss - ts > 0 and num == 23:
		ts += 1
	if ts - fts > 0 and num == 42:
		fts += 1
print(n - 6 * fts)


n = int(input())
arr = list(map(int, input().split()))
temp = [0] * 6
req = [4, 8, 15, 16, 23, 42]
for i in arr:
	idx = req.index(i)
	if idx == 0:
		temp[idx] += 1
	elif idx > 0 and temp[idx - 1] > temp[idx]:
		temp[idx] += 1
print(n - 6 * min(temp))


n = int(input())
nums = {'4': 0, '8': 1, '15': 2, '16': 3, '23': 4, '42': 5}

def convert(x):
	return nums[x]
l = list(map(convert, input().split()))
c = [0] * 6
rm = 0
for x in l:
	if x == 0:
		c[x] += 1
	elif c[x - 1] > 0:
		c[x] += 1
		c[x - 1] -= 1
print(n - c[5] * 6)


n = int(input())
a = [int(x) for x in input().split()]
four = []
egt = []
fif = []
six = []
thr = []
two = []
for i in range(n):
	if a[i] == 4:
		four.append(i)
	if a[i] == 8:
		egt.append(i)
	if a[i] == 15:
		fif.append(i)
	if a[i] == 16:
		six.append(i)
	if a[i] == 23:
		thr.append(i)
	if a[i] == 42:
		two.append(i)
if len(four) == 0 or len(egt) == 0 or len(fif) == 0 or (len(six) == 0) or (len(thr) == 0) or (len(two) == 0):
	print(n)
else:
	(fo, eg, fi, si, th, tw) = [0] * 6
	ans = 0
	mark = [0] * n
	while True:
		if fo >= len(four) or eg >= len(egt) or fi >= len(fif) or (si >= len(six)) or (th >= len(thr)) or (tw >= len(two)):
			break
		if egt[eg] < four[fo] and eg < len(egt):
			while eg < len(egt) and egt[eg] < four[fo]:
				eg += 1
				ans += 1
			if eg >= len(egt):
				break
		if fif[fi] < egt[eg] and fi < len(fif):
			while fi < len(fif) and fif[fi] < egt[eg]:
				fi += 1
				ans += 1
			if fi >= len(fif):
				break
		if six[si] < fif[fi] and si < len(six):
			while si < len(six) and six[si] < fif[fi]:
				si += 1
				ans += 1
			if si >= len(six):
				break
		if thr[th] < six[si] and th < len(thr):
			while th < len(thr) and thr[th] < six[si]:
				th += 1
				ans += 1
			if th >= len(thr):
				break
		if two[tw] < thr[th] and tw < len(two):
			while tw < len(two) and two[tw] < thr[th]:
				tw += 1
				ans += 1
			if tw >= len(two):
				break
		mark[four[fo]] = 1
		mark[egt[eg]] = 1
		mark[fif[fi]] = 1
		mark[six[si]] = 1
		mark[thr[th]] = 1
		mark[two[tw]] = 1
		fo += 1
		eg += 1
		fi += 1
		si += 1
		th += 1
		tw += 1
	print(n - sum(mark))


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
sys.setrecursionlimit(100000000)
inp = lambda : int(input())
strng = lambda : input().strip()
strl = lambda : list(input().strip())
jn = lambda x, l: x.join(map(str, l))
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(int, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
mod = 1000000007

def ceil(x):
	d = int(x)
	if x == d:
		return int(x)
	return int(x) + 1

def ceildiv(x, d):
	if x % d == 0:
		return x // d
	return x // d + 1
n = inp()
l = seq()
d = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
l1 = [0, 0, 0, 0, 0, 0]
for i in range(n):
	ind = d[l[i]]
	if ind == 0 or (ind != 0 and l1[ind - 1] > l1[ind]):
		l1[ind] += 1
ct = min(l1)
print(n - 6 * ct)


import sys, collections
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
res = dict().fromkeys([4, 8, 15, 16, 23, 42])
ans = []
mid = 0
for i in res:
	res[i] = collections.deque()
for i in range(n):
	res[arr[i]].append(i)
while True:
	can = True
	for i in res:
		if not res[i]:
			can = False
			break
	if not can:
		break
	cnt = 0
	temp = []
	for i in res:
		if not temp:
			if res[i]:
				temp.append(res[i].popleft())
		elif res[i]:
			while res[i]:
				if res[i][0] > temp[-1]:
					temp.append(res[i].popleft())
					break
				else:
					ans.append(res[i].popleft())
	if len(temp) != 6:
		mid += len(temp)
for i in res:
	mid += len(res[i])
print(len(ans) + mid)


n = int(input())
a = list(map(int, input().split()))
d = {4: 1, 8: 2, 15: 3, 16: 4, 23: 5, 42: 6}
dp = [0 for i in range(7)]
dp[0] = 9999999999
for i in range(n):
	a[i] = d[a[i]]
for i in range(n):
	if dp[a[i] - 1] > dp[a[i]]:
		dp[a[i]] += 1
print(n - 6 * dp[6])


n = int(input())
a = (0, 4, 8, 15, 16, 23, 42)
b = [0] * 43
for (x, y) in zip(a, a[1:]):
	b[y] = x
c = [0] + [n] * 42
for x in map(int, input().split()):
	if c[b[x]] < n:
		c[b[x]] += 6
		c[x] -= 6
print(c[42])


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	n = int(input())
	a = list(map(int, input().split()))
	s = set([4, 8, 15, 16, 23, 42])
	ans = 0
	(b, c, d, e, f, g) = (0, 0, 0, 0, 0, 0)
	for x in a:
		if x not in s:
			ans += 1
			continue
		if x == 4:
			b += 1
		elif x == 8:
			c += 1
			if c > b:
				c -= 1
				ans += 1
		elif x == 15:
			d += 1
			if d > c:
				d -= 1
				ans += 1
		elif x == 16:
			e += 1
			if e > d:
				e -= 1
				ans += 1
		elif x == 23:
			f += 1
			if f > e:
				f -= 1
				ans += 1
		elif x == 42:
			g += 1
			if g > f:
				g -= 1
				ans += 1
	print(ans + b + c + d + e + f + g - 6 * g)
main()


n = int(input())
list = []
val = input().split()
for x in range(n):
	list.append(int(val[x]))
dp = [0, 0, 0, 0, 0, 0]
count = 0
for x in range(n):
	if int(list[x]) == 4:
		dp[0] = dp[0] + 1
		for y in range(1, 6):
			if dp[y] > dp[y - 1]:
				dp[y] = dp[y] - 1
				count = count + 1
	elif int(list[x]) == 8:
		dp[1] = dp[1] + 1
		for y in range(1, 6):
			if dp[y] > dp[y - 1]:
				dp[y] = dp[y] - 1
				count = count + 1
	elif int(list[x]) == 15:
		dp[2] = dp[2] + 1
		for y in range(1, 6):
			if dp[y] > dp[y - 1]:
				dp[y] = dp[y] - 1
				count = count + 1
	elif int(list[x]) == 16:
		dp[3] = dp[3] + 1
		for y in range(1, 6):
			if dp[y] > dp[y - 1]:
				dp[y] = dp[y] - 1
				count = count + 1
	elif int(list[x]) == 23:
		dp[4] = dp[4] + 1
		for y in range(1, 6):
			if dp[y] > dp[y - 1]:
				dp[y] = dp[y] - 1
				count = count + 1
	elif int(list[x]) == 42:
		dp[5] = dp[5] + 1
		for y in range(1, 6):
			if dp[y] > dp[y - 1]:
				dp[y] = dp[y] - 1
				count = count + 1
	else:
		count = count + 1
min = 10000000000
for x in range(6):
	if dp[x] < min:
		min = dp[x]
for x in range(6):
	count = count + dp[x] - min
print(count)


from sys import stdin
n = int(input())
l = list(map(int, stdin.readline().rstrip().split(' ')))
a = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
for i in range(n):
	if l[i] == 4:
		a[4] += 1
	elif l[i] == 8:
		if a[4] > a[8]:
			a[8] += 1
	elif l[i] == 15:
		if a[8] > a[15]:
			a[15] += 1
	elif l[i] == 16:
		if a[15] > a[16]:
			a[16] += 1
	elif l[i] == 23:
		if a[16] > a[23]:
			a[23] += 1
	elif l[i] == 42:
		if a[23] > a[42]:
			a[42] += 1
r = n - 6 * a[42]
print(r)


l = [4, 8, 15, 16, 23, 42]
n = int(input())
a = list(map(int, input().split()))
if n < 6:
	print(n)
	exit(0)
m = [0] * 6
c = 0
for i in range(n):
	x = l.index(a[i])
	if x == 0 or m[x] < m[x - 1]:
		m[x] += 1
	else:
		c += 1
mi = min(m)
s = sum([m[i] - mi for i in range(6)])
print(s + c)


n = int(input())
a = [int(o) for o in input().split()]
dp = [[0 for i in range(7)] for j in range(n + 1)]
d = {4: 0, 8: 1, 15: 2, 16: 3, 42: 5, 23: 4}
for i in range(n):
	dp[i][0] = dp[i - 1][0]
	if a[i] == 4:
		dp[i][0] += 1
for i in range(n):
	for j in range(7):
		dp[i][j] = max(dp[i][j], dp[i - 1][j])
	if dp[i - 1][d[a[i]] - 1] != 0:
		dp[i][d[a[i]]] = min(dp[i - 1][d[a[i]]] + 1, dp[i - 1][d[a[i]] - 1])
print(n - 6 * dp[n - 1][5])


n = int(input())
a = [int(i) for i in filter(None, input().split(' '))]
x = [0, 0, 0, 0, 0, 0]
for i in range(0, n):
	if a[i] == 4:
		x[0] += 1
	if a[i] == 8 and x[0] > x[1]:
		x[1] += 1
	if a[i] == 15 and x[1] > x[2]:
		x[2] += 1
	if a[i] == 16 and x[2] > x[3]:
		x[3] += 1
	if a[i] == 23 and x[3] > x[4]:
		x[4] += 1
	if a[i] == 42 and x[4] > x[5]:
		x[5] += 1
print(n - x[5] * 6)


def func(a, n):
	arr = []
	last4 = 0
	last8 = 0
	last15 = 0
	last16 = 0
	last23 = 0
	last42 = 0
	l = 0
	for i in range(n):
		if a[i] == 4:
			last4 += 1
		elif a[i] == 8:
			if last8 < last4:
				last8 += 1
		elif a[i] == 15:
			if last15 < last8:
				last15 += 1
		elif a[i] == 16:
			if last16 < last15:
				last16 += 1
		elif a[i] == 23:
			if last23 < last16:
				last23 += 1
		elif last42 < last23:
			last42 += 1
	return n - 6 * last42
n = int(input())
a = [int(i) for i in input().split()]
print(func(a, n))


from sys import stdin
input = lambda : stdin.readline()
from math import ceil, sqrt, gcd
n = int(input())
l = list(map(int, input().split()))
count = 0
d = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
for i in range(n):
	if l[i] == 4:
		d[4] += 1
	elif l[i] == 8:
		if d[4] > 0:
			d[8] += 1
			d[4] -= 1
		else:
			count += 1
	elif l[i] == 15:
		if d[8] > 0:
			d[15] += 1
			d[8] -= 1
		else:
			count += 1
	elif l[i] == 16:
		if d[15] > 0:
			d[16] += 1
			d[15] -= 1
		else:
			count += 1
	elif l[i] == 23:
		if d[16] > 0:
			d[23] += 1
			d[16] -= 1
		else:
			count += 1
	elif d[23] > 0:
		d[42] += 1
		d[23] -= 1
	else:
		count += 1
for i in d:
	if i == 4:
		count += d[i]
	elif i == 8:
		count += 2 * d[i]
	elif i == 15:
		count += 3 * d[i]
	elif i == 16:
		count += 4 * d[i]
	elif i == 23:
		count += 5 * d[i]
print(count)


p = [4, 8, 15, 16, 23, 42]
n = int(input())
a = list(map(int, input().split()))
ans = [0] * 6
if n < 6:
	exit(print(n))
for i in a:
	if i == p[0]:
		ans[0] += 1
	else:
		x = p.index(i)
		if ans[x - 1] > ans[x]:
			ans[x] += 1
mn = 10 ** 18
for i in ans:
	mn = min(i, mn)
print(n - 6 * mn)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict
import math
import heapq

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
n = intIn()
a = listIn()
A = [4, 8, 15, 16, 23, 42]
di = {}
di2 = {}
for i in range(n):
	if a[i] not in di:
		di[a[i]] = 1
		di2[a[i]] = [i]
	else:
		di2[a[i]].append(i)
		di[a[i]] += 1
if n < 6:
	print(n)
	exit(0)
elif len(di) == 6:
	b = di.values()
	m = min(b)
	arr = [0] * n
	t = 0
	cnt = 0
	arr = [0] * 6
	f = 0
	while cnt < m:
		i = 1
		while i < 6:
			if arr[i] < di[A[i]]:
				p1 = di2[A[i]][arr[i]]
			if arr[i - 1] < di[A[i - 1]]:
				p2 = di2[A[i - 1]][arr[i - 1]]
			if p2 < p1:
				if arr[i - 1] < di[A[i - 1]]:
					arr[i - 1] += 1
				else:
					f = 1
					break
				i += 1
			elif arr[i] < di[A[i]]:
				arr[i] += 1
			else:
				f = 1
				break
		if i == 6:
			cnt += 1
			if arr[i - 1] < di[A[i - 1]]:
				arr[i - 1] += 1
			else:
				f = 1
				break
		if f:
			break
	print(n - cnt * 6)
else:
	print(n)
	exit(0)


n = int(input())
arr = input().split()
flag0 = 0
flag1 = 0
flag2 = 0
flag3 = 0
flag4 = 0
flag5 = 0
for i in range(n):
	if int(arr[i]) == 4:
		flag0 += 1
	if int(arr[i]) == 8:
		if flag0 >= 1:
			flag0 -= 1
			flag1 += 1
	if int(arr[i]) == 15:
		if flag1 >= 1:
			flag1 -= 1
			flag2 += 1
	if int(arr[i]) == 16:
		if flag2 >= 1:
			flag2 -= 1
			flag3 += 1
	if int(arr[i]) == 23:
		if flag3 >= 1:
			flag3 -= 1
			flag4 += 1
	if int(arr[i]) == 42:
		if flag4 >= 1:
			flag4 -= 1
			flag5 += 1
print(n - flag5 * 6)


import sys
input = sys.stdin.readline
from collections import *
n = int(input())
a = list(map(int, input().split()))
cnt = [0] * 5
ans = 0
for ai in a:
	if ai == 4:
		cnt[0] += 1
	elif ai == 8:
		if cnt[0] >= 1:
			cnt[0] -= 1
			cnt[1] += 1
		else:
			ans += 1
	elif ai == 15:
		if cnt[1] >= 1:
			cnt[1] -= 1
			cnt[2] += 1
		else:
			ans += 1
	elif ai == 16:
		if cnt[2] >= 1:
			cnt[2] -= 1
			cnt[3] += 1
		else:
			ans += 1
	elif ai == 23:
		if cnt[3] >= 1:
			cnt[3] -= 1
			cnt[4] += 1
		else:
			ans += 1
	elif ai == 42:
		if cnt[4] >= 1:
			cnt[4] -= 1
		else:
			ans += 1
ans += cnt[0] + 2 * cnt[1] + 3 * cnt[2] + 4 * cnt[3] + 5 * cnt[4]
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
h = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
ct = [0, 0, 0, 0, 0, 0]
for i in range(n):
	if a[i] == 4:
		ct[h[a[i]]] += 1
	elif ct[h[a[i]] - 1] > 0:
		ct[h[a[i]] - 1] -= 1
		ct[h[a[i]]] += 1
print(n - 6 * ct[5])


n = int(input())
a = list(map(int, input().split()))
b = [4, 8, 15, 16, 23, 42]
ans = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
for i in range(n):
	if a[i] == b[0]:
		ans[4] += 1
	else:
		j = b.index(a[i]) - 1
		if ans[b[j]] > 0:
			ans[b[j]] -= 1
			ans[b[j + 1]] += 1
print(len(a) - ans[42] * 6)


import heapq as h
n = int(input())
arr = list(map(int, input().split()))
vals = [4, 8, 15, 16, 23, 42]
list = {}
for val in vals:
	list[val] = []
for idx in range(n):
	list[arr[idx]].append(idx)
for val in vals:
	h.heapify(list[val])
used = [False] * n
while len(list[4]) != 0:
	seq = [list[4][0]]
	h.heappop(list[4])
	for idx in range(1, len(vals)):
		while len(list[vals[idx]]) != 0 and list[vals[idx]][0] < seq[-1] and (not used[list[vals[idx]][0]]):
			h.heappop(list[vals[idx]])
		if len(list[vals[idx]]) != 0:
			seq.append(list[vals[idx]][0])
			h.heappop(list[vals[idx]])
		else:
			break
	if len(seq) < 6:
		break
	for no in seq:
		used[no] = True
cnt = 0
for no in used:
	if no == False:
		cnt += 1
print(cnt)


n = int(input())
a = list(map(int, input().split()))
v = [[] for j in range(44)]
for j in range(n):
	v[a[j]].append(j)
i = 0
t = 0
y = v[4]
j = 0
k = 0
while j < len(v[4]):
	u = 0
	while k < len(v[8]):
		if v[4][j] < v[8][k]:
			t += 1
			u = 1
			y[j] = v[8][k]
			k += 1
			break
		k += 1
	if k == len(v[8]) or u == 0:
		break
	j += 1
y = y[0:t]
t = 0
j = 0
k = 0
while j < len(y):
	u = 0
	while k < len(v[15]):
		if y[j] < v[15][k]:
			t += 1
			u = 1
			y[j] = v[15][k]
			k += 1
			break
		k += 1
	if k == len(v[15]) or u == 0:
		break
	j += 1
y = y[0:t]
t = 0
j = 0
k = 0
while j < len(y):
	u = 0
	while k < len(v[16]):
		if y[j] < v[16][k]:
			t += 1
			u = 1
			y[j] = v[16][k]
			k += 1
			break
		k += 1
	if k == len(v[16]) or u == 0:
		break
	j += 1
y = y[0:t]
t = 0
j = 0
k = 0
while j < len(y):
	u = 0
	while k < len(v[23]):
		if y[j] < v[23][k]:
			t += 1
			u = 1
			y[j] = v[23][k]
			k += 1
			break
		k += 1
	if k == len(v[23]) or u == 0:
		break
	j += 1
y = y[0:t]
t = 0
j = 0
k = 0
while j < len(y):
	u = 0
	while k < len(v[42]):
		if y[j] < v[42][k]:
			t += 1
			u = 1
			y[j] = v[42][k]
			k += 1
			break
		k += 1
	if k == len(v[42]) or u == 0:
		break
	j += 1
y = y[0:t]
t = len(y) * 6
print(n - t)


n = int(input())
aa = [int(i) for i in input().split()]
dic = {}
wa = [4, 8, 15, 16, 23, 42]
(dic[4], dic[8], dic[15], dic[16], dic[23], dic[42]) = (0, 0, 0, 0, 0, 0)
ans = 0
for i in aa:
	ind = wa.index(i)
	if ind == 0:
		dic[wa[ind]] += 1
	elif dic[wa[ind - 1]] > 0:
		dic[wa[ind - 1]] -= 1
		dic[wa[ind]] += 1
print(n - 6 * dic[42])


n = int(input())
a = [int(i) for i in input().split()]
dp = [int(0) for i in range(6)]
for i in range(n):
	if a[i] == 4:
		dp[0] += 1
	if a[i] == 8:
		if dp[0] != 0:
			dp[1] += 1
			dp[0] -= 1
	if a[i] == 15:
		if dp[1] != 0:
			dp[2] += 1
			dp[1] -= 1
	if a[i] == 16:
		if dp[2] != 0:
			dp[3] += 1
			dp[2] -= 1
	if a[i] == 23:
		if dp[3] != 0:
			dp[4] += 1
			dp[3] -= 1
	if a[i] == 42:
		if dp[4] != 0:
			dp[5] += 1
			dp[4] -= 1
ans = n - 6 * dp[5]
print(ans)


n = int(input())
L = list(map(int, input().split()))
T = [0, 0, 0, 0, 0, 0]
for i in range(n):
	if L[i] == 4:
		T[0] += 1
	if L[i] == 8 and T[0] > T[1]:
		T[1] += 1
	if L[i] == 15 and T[1] > T[2]:
		T[2] += 1
	if L[i] == 16 and T[2] > T[3]:
		T[3] += 1
	if L[i] == 23 and T[3] > T[4]:
		T[4] += 1
	if L[i] == 42 and T[4] > T[5]:
		T[5] += 1
print(n - 6 * T[5])


n = int(input())
a = [int(x) for x in input().split()]
m = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
ans = {0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
for each in a:
	if m[each] == 0:
		ans[0] += 1
	elif ans[m[each] - 1] > 0:
		ans[m[each] - 1] -= 1
		ans[m[each]] += 1
print(n - 6 * ans[5])


n = int(input())
a = list(map(int, input().split(' ')))
seq = [4, 8, 15, 16, 23, 42]
answer = [0] * 6
for a in a:
	i = seq.index(a)
	if i == 0:
		answer[i] += 1
	elif answer[i - 1] > 0:
		answer[i - 1] -= 1
		answer[i] += 1
print(n - 6 * answer[5])


n = int(input())
l = list(map(int, input().split()))
a = [4, 8, 15, 16, 23, 42]
b = [0] * 6
d = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
c = 0
ans = 0
if n < 6:
	print(n)
else:
	k = l.index(4) - 0
	ans += k
	for i in range(k, n):
		d[l[i]] += 1
		x = a.index(l[i])
		b[x] += 1
		for j in range(x - 1, -1, -1):
			if d[l[i]] > d[a[j]]:
				ans += 1
				d[l[i]] -= 1
				b[x] -= 1
				break
	for i in range(5):
		ans += b[i] - b[5]
	print(ans)


def get(n, a):
	state = [0] * 6
	for ai in a:
		if ai == 0:
			state[0] += 1
			continue
		if state[ai - 1] > 0:
			state[ai - 1] -= 1
			state[ai] += 1
	return n - 6 * state[5]
s2i = {'4': 0, '8': 1, '15': 2, '16': 3, '23': 4, '42': 5}
n = int(input())
a = map(lambda s: s2i[s], input().split())
print(get(n, a))


import collections
N = int(input())
A = [int(_) for _ in input().split()]
dp = [0] * 7
ai = collections.defaultdict(int)
ai[4] = 1
ai[8] = 2
ai[15] = 3
ai[16] = 4
ai[23] = 5
ai[42] = 6
ia = collections.defaultdict(int)
for a in ai:
	i = ai[a]
	ia[i] = a
for a in A:
	i = ai[a]
	if i < 2:
		dp[i] += 1
	elif dp[i - 1]:
		dp[i] += 1
		dp[i - 1] -= 1
	else:
		dp[0] += 1
print(N - dp[6] * 6)


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
e = [4, 8, 15, 16, 23, 42]
opened = defaultdict(int)
prev_ai = {ei: e[i - 1] if i - 1 >= 0 else None for (i, ei) in enumerate(e)}
possible = 0
for ai in a:
	prev = prev_ai[ai]
	if prev:
		if not opened[prev]:
			opened[ai] -= 1
		else:
			opened[prev] -= 1
			if ai == e[-1]:
				possible += 1
	opened[ai] += 1
ans = len(a) - possible * len(e)
print(ans)


from collections import Counter

def read_nums():
	return [int(x) for x in input().split()]

def solve(nums):
	c = Counter()
	res = 0
	for num in nums:
		c[num] += 1
		if num > 0:
			if c[num - 1] == 0:
				res += 1
				c[num] -= 1
			else:
				c[num - 1] -= 1
	for i in range(5):
		res += (i + 1) * c[i]
	return res

def main():
	(n,) = read_nums()
	d = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
	nums = [d[x] for x in read_nums()]
	print(solve(nums))
main()


n = int(input())
arr = map(int, input().split())
dict1 = [0, 0, 0, 0, 0, 0]
for i in arr:
	if i == 4:
		dict1[0] += 1
	if i == 8 and dict1[1] < dict1[0]:
		dict1[1] += 1
	if i == 15 and dict1[2] < dict1[1]:
		dict1[2] += 1
	if i == 16 and dict1[3] < dict1[2]:
		dict1[3] += 1
	if i == 23 and dict1[4] < dict1[3]:
		dict1[4] += 1
	if i == 42 and dict1[5] < dict1[4]:
		dict1[5] += 1
t = min(dict1)
print(n - t * 6)


t = [4, 8, 15, 16, 23, 42]
from collections import defaultdict
n = int(input())
l = list(map(int, input().split()))
j = 0
c = 0
for i in range(n):
	if l[i] == t[j]:
		j = j + 1
	else:
		c = c + 1
	if j == 6:
		j = 0
dp = [[] for i in range(6)]
for i in range(n):
	for j in range(6):
		if t[j] == l[i]:
			dp[j].append(i)
			break
d = {}
for i in range(1, 6):
	temp = []
	j = 0
	k = 0
	while j < len(dp[i - 1]) and k < len(dp[i]):
		if dp[i - 1][j] < dp[i][k]:
			temp.append(dp[i][k])
			j = j + 1
			k = k + 1
		elif dp[i - 1][j] > dp[i][k]:
			k = k + 1
	if len(temp) == 0:
		dp[i] = list(temp)
	else:
		dp[i] = list(temp)
z = float('inf')
for i in range(6):
	z = min(z, len(dp[i]))
print(n - z * 6)


from sys import stdin, stdout

def INI():
	return int(stdin.readline())

def INL():
	return [int(_) for _ in stdin.readline().split()]

def INS():
	return stdin.readline()

def OPS(ans):
	stdout.write(str(ans) + '\n')

def OPL(ans):
	[stdout.write(str(_) + ' ') for _ in ans]
	stdout.write('\n')
n = INI()
A = INL()
(_4, _8, _15, _16, _23, _42) = [0] * 6
ans = 0
for _ in range(n):
	if A[_] == 4:
		_4 += 1
	elif A[_] == 8:
		if _4 > _8:
			_8 += 1
	elif A[_] == 15:
		if _8 > _15:
			_15 += 1
	elif A[_] == 16:
		if _15 > _16:
			_16 += 1
	elif A[_] == 23:
		if _16 > _23:
			_23 += 1
	elif _23 > _42:
		_42 += 1
s = sum([_4, _8, _15, _16, _23, _42])
OPS(n - s + sum([_ - _42 for _ in [_4, _8, _15, _16, _23, _42]]))


n = int(input())
d = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
a = list(map(lambda x: d[int(x)], input().split()))
c = [0] * 6
ans = 0
for i in range(len(a)):
	new = a[i]
	if new == 0:
		c[0] += 1
	elif c[new - 1] > 0:
		c[new - 1] -= 1
		c[new] += 1
	else:
		ans += 1
for i in range(5):
	ans += (i + 1) * c[i]
print(ans)


numbers = [4, 8, 15, 16, 23, 42]

def find(where, what):
	for (i, item) in enumerate(where):
		if item == what:
			return i
	return -1
n = int(input())
a = [find(numbers, int(i)) for i in input().split()]
useless = 0
k = [0 for i in range(7)]
k[-1] = len(a) // 6
for (i, x) in enumerate(a):
	if k[x - 1]:
		k[x - 1] -= 1
		k[x] += 1
	else:
		useless += 1
k[5] = 0
print(useless + sum([(i + 1) * j for (i, j) in enumerate(k)]))


n = int(input())
MAP = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}

def map_number(x: str) -> int:
	return MAP[int(x)]
A = list(map(map_number, input().split(' ')))
CHAIN_LEN = 6
LEN = [0 for x in range(CHAIN_LEN)]
for i in range(n):
	x = A[i]
	if x == 0:
		LEN[0] += 1
	elif LEN[x - 1]:
		LEN[x] += 1
		LEN[x - 1] -= 1
print(n - CHAIN_LEN * LEN[-1])


n = int(input())
a = [int(i) for i in input().split()]
ar = []
vis = []
ans = n
for _ in range(6):
	ar.append([])
	vis.append([])
for i in range(n):
	if a[i] == 4:
		ar[0].append(i)
		vis[0].append(False)
	elif a[i] == 8:
		ar[1].append(i)
		vis[1].append(False)
	elif a[i] == 15:
		ar[2].append(i)
		vis[2].append(False)
	elif a[i] == 16:
		ar[3].append(i)
		vis[3].append(False)
	elif a[i] == 23:
		ar[4].append(i)
		vis[4].append(False)
	elif a[i] == 42:
		ar[5].append(i)
		vis[5].append(False)
i = [0] * 6
p = -1
flag = True
while flag:
	z = 0
	while z < 6:
		if len(ar[z]) <= i[z]:
			flag = False
			break
		if ar[z][i[z]] > p:
			if z == 5:
				ans -= 6
				p = -1
				i[z] += 1
				z = 6
			else:
				p = ar[z][i[z]]
				i[z] += 1
				z += 1
		else:
			i[z] += 1
print(ans)


import math
from decimal import *
import random
mod = int(1000000000.0) + 7
n = int(input())
arr = list(map(int, input().split()))
d = {4: 0, (4, 8): 0, (4, 8, 15): 0, (4, 8, 15, 16): 0, (4, 8, 15, 16, 23): 0, (4, 8, 15, 16, 23, 42): 0}
ans = 0
for i in range(n):
	if arr[i] == 4:
		d[4] += 1
	if arr[i] == 8:
		if d[4] > 0:
			d[4] -= 1
			d[4, 8] += 1
	if arr[i] == 15:
		if d[4, 8] > 0:
			d[4, 8] -= 1
			d[4, 8, 15] += 1
	if arr[i] == 16:
		if d[4, 8, 15] > 0:
			d[4, 8, 15] -= 1
			d[4, 8, 15, 16] += 1
	if arr[i] == 23:
		if d[4, 8, 15, 16] > 0:
			d[4, 8, 15, 16] -= 1
			d[4, 8, 15, 16, 23] += 1
	if arr[i] == 42:
		if d[4, 8, 15, 16, 23] > 0:
			d[4, 8, 15, 16, 23] -= 1
			ans += 1
print(n - ans * 6)


n = int(input())
a = list(map(int, input().split()))
t = [0] * 6 + [-1]
s = 0
v = (4, 8, 15, 16, 23, 42)
while a:
	i = v.index(a.pop())
	if i < 0:
		s += 1
	elif t[i + 1]:
		t[i + 1] -= 1
		t[i] += 1
	else:
		s += 1
for i in (1, 2, 3, 4, 5):
	s += (6 - i) * t[i]
print(s)


n = int(input())
a = map(int, input().split())
b = [4, 8, 15, 16, 23, 42]
s = [0] * 6
for x in a:
	i = b.index(x)
	if i == 0:
		s[i] += 1
	if s[i - 1] > s[i]:
		s[i] += 1
print(n - s[5] * 6)


n = int(input())
a = list(map(int, input().split()))
c1 = 0
c2 = 0
c3 = 0
c4 = 0
c5 = 0
c6 = 0
for j in a:
	if j == 4:
		c1 += 1
	elif j == 8:
		if c1 - c2 >= 1:
			c2 += 1
	elif j == 15:
		if c2 - c3 >= 1:
			c3 += 1
	elif j == 16:
		if c3 - c4 >= 1:
			c4 += 1
	elif j == 23:
		if c4 - c5 >= 1:
			c5 += 1
	elif c5 - c6 >= 1:
		c6 += 1
final = min(c1, c2, c3, c4, c5, c6)
total = final * 6
if n < 6:
	print(n)
else:
	print(n - total)


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
x = [4, 8, 15, 16, 23, 42]
n = I()
l = L()
d = defaultdict(int)
y = []
ans = 1
for i in range(n):
	for j in range(len(x)):
		if l[i] == x[j] and l[i] == 4:
			d[x[j]] += 1
		elif l[i] == x[j]:
			if d[x[j]] < d[x[j - 1]]:
				d[x[j]] += 1
print(n - d[42] * 6)


from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7
n = iinput()
a = rlinput()
samp = [4, 8, 15, 16, 23, 42]
indx = [0] * 43
for i in range(6):
	indx[samp[i]] = i
d = dict()
for i in samp:
	d[i] = 0
ans = 0
for i in a:
	idx = indx[i]
	flag = True
	for j in range(idx):
		if d[i] + 1 > d[samp[j]]:
			ans += 1
			flag = False
			break
	if flag:
		d[i] += 1
mn = min(d.values())
for i in d:
	ans += d[i] - mn
print(ans)


a = [4, 8, 15, 16, 23, 42]
n = int(input())
l = list(map(int, input().split()))
b = [0 for _ in range(6)]
for e in l:
	try:
		i = a.index(e)
	except ValueError:
		continue
	if i == 0:
		b[0] += 1
	else:
		if b[i - 1] <= 0:
			continue
		b[i - 1] -= 1
		b[i] += 1
print(n - b[-1] * 6)


n = int(input())
a = list(map(int, input().split(' ')))
(4, 8, 15, 16, 23, 42)
l = []
for i in range(6):
	l.append([])
for i in range(n):
	if a[i] == 4:
		l[0].append(i)
	elif a[i] == 8:
		l[1].append(i)
	elif a[i] == 15:
		l[2].append(i)
	elif a[i] == 16:
		l[3].append(i)
	elif a[i] == 23:
		l[4].append(i)
	else:
		l[5].append(i)
mn = -1
tot = 0
flg = 0
i = 0
indx1 = 0
indx2 = 0
indx3 = 0
indx4 = 0
indx5 = 0
indx6 = 0
while flg == 0:
	if i % 6 == 0:
		if indx1 >= len(l[0]):
			flg = 1
		else:
			mn = l[0][indx1]
			indx1 += 1
	elif i % 6 == 1:
		if indx2 >= len(l[1]):
			flg = 1
		else:
			while indx2 < len(l[1]) and mn > l[1][indx2]:
				indx2 += 1
			if indx2 >= len(l[1]):
				flg = 1
			else:
				mn = l[1][indx2]
				indx2 += 1
	elif i % 6 == 2:
		if indx3 >= len(l[2]):
			flg = 1
		else:
			while indx3 < len(l[2]) and mn > l[2][indx3]:
				indx3 += 1
			if indx3 >= len(l[2]):
				flg = 1
			else:
				mn = l[2][indx3]
				indx3 += 1
	elif i % 6 == 3:
		if indx4 >= len(l[3]):
			flg = 1
		else:
			while indx4 < len(l[3]) and mn > l[3][indx4]:
				indx4 += 1
			if indx4 >= len(l[3]):
				flg = 1
			else:
				mn = l[3][indx4]
				indx4 += 1
	elif i % 6 == 4:
		if indx5 >= len(l[4]):
			flg = 1
		else:
			while indx5 < len(l[4]) and mn > l[4][indx5]:
				indx5 += 1
			if indx5 >= len(l[4]):
				flg = 1
			else:
				mn = l[4][indx5]
				indx5 += 1
	elif indx6 >= len(l[5]):
		flg = 1
	else:
		while indx6 < len(l[5]) and mn > l[5][indx6]:
			indx6 += 1
		if indx6 >= len(l[5]):
			flg = 1
		else:
			mn = l[5][indx6]
			tot += 1
			indx6 += 1
	i += 1
print(n - 6 * tot)


used = [0] * 6
reverse = [0] * 43
reverse[8] = 1
reverse[15] = 2
reverse[16] = 3
reverse[23] = 4
reverse[42] = 5
n = int(input())
nums = list(map(int, input().split()))
for i in nums:
	i = reverse[i]
	if i == 0:
		used[i] += 1
	elif used[i - 1] > 0:
		used[i - 1] -= 1
		used[i] += 1
print(n - used[5] * 6)


n = int(input())
A = list(map(int, input().split()))
d = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
A = [d[a] for a in A]
import bisect
B = [0] * 6
ans = 0
for a in A:
	if a == 0:
		B[0] += 1
		continue
	elif B[a - 1] != 0:
		B[a - 1] -= 1
		B[a] += 1
	else:
		ans += 1
for j in range(6):
	if j != 5:
		ans += B[j] * (j + 1)
print(ans)


import sys
from collections import defaultdict
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
dic = defaultdict(list)
for i in range(n):
	dic[arr[i]].append(i)
l = [4, 8, 15, 16, 23, 42]
ind = defaultdict(int)
for i in range(6):
	ind[l[i]] = 0
(count, z) = (0, True)
while z:
	prev = -1
	for i in range(6):
		if ind[l[i]] >= len(dic[l[i]]):
			z = False
			break
		if dic[l[i]][ind[l[i]]] > prev:
			prev = dic[l[i]][ind[l[i]]]
			ind[l[i]] += 1
		else:
			while ind[l[i]] < len(dic[l[i]]) and dic[l[i]][ind[l[i]]] <= prev:
				ind[l[i]] += 1
			if ind[l[i]] >= len(dic[l[i]]):
				z = False
				break
			if dic[l[i]][ind[l[i]]] <= prev:
				z = False
				break
			else:
				prev = dic[l[i]][ind[l[i]]]
				ind[l[i]] += 1
	if z:
		count += 1
ans = n - 6 * count
print(ans)


n = int(input())
d = {0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
l = list(map(int, input().rstrip().split()))

def f(n):
	if n == 4:
		return 0
	elif n == 8:
		return 1
	elif n == 15:
		return 2
	elif n == 16:
		return 3
	elif n == 23:
		return 4
	return 5
for i in l:
	la = f(i)
	if la == 0 or d[la - 1] > d[la]:
		d[la] += 1
print(n - 6 * d[5])


input()
nums = list(map(int, input().split()))
idx = [4, 8, 15, 16, 23, 42]
d = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
res = 0
for num in nums:
	t_idx = idx.index(num)
	if t_idx == 0:
		d[4] += 1
	else:
		dic_idx = idx[t_idx - 1]
		if d[num] < d[dic_idx]:
			d[num] += 1
		else:
			res += 1
for (_, value) in d.items():
	res += value - d[42]
print(res)


n = int(input())
a = list(map(int, input().rstrip().split()))
ans = 0
li = [4, 8, 15, 16, 23, 42]
d = dict()
for x in li:
	d[x] = []
for i in range(n):
	if a[i] == 4:
		d[4].append(i)
for i in range(1, 6):
	j = 0
	l = len(d[li[i - 1]])
	for k in range(n):
		if a[k] == li[i] and l > j and (k > d[li[i - 1]][j]):
			d[li[i]].append(k)
			j += 1
minm = n
for x in d:
	minm = min(minm, len(d[x]))
print(n - minm * 6)


n = int(input())
arr = [int(integer) for integer in input().split()]
six_numbers = [4, 8, 15, 16, 23, 42]
dic = {}
for number in six_numbers:
	dic[number] = 0
dit = {}
dit[8] = 4
dit[15] = 8
dit[16] = 15
dit[23] = 16
dit[42] = 23
num_remove = 0
for element in arr:
	if element != 4:
		if dic[dit[element]] == 0:
			num_remove += 1
		else:
			dic[dit[element]] -= 1
			if element != 42:
				dic[element] += 1
	else:
		dic[4] += 1
for i in range(6):
	num_remove += (i + 1) * dic[six_numbers[i]]
print(num_remove)


n = int(input())
arr = list(map(int, input().split(' ')))
i4 = 0
i8 = 0
i15 = 0
i16 = 0
i23 = 0
i42 = 0
if n > 5:
	for i in arr:
		if i == 4:
			i4 += 1
		if i == 8 and i4 > i8:
			i8 += 1
		if i == 15 and i8 > i15:
			i15 += 1
		if i == 16 and i15 > i16:
			i16 += 1
		if i == 23 and i16 > i23:
			i23 += 1
		if i == 42 and i23 > i42:
			i42 += 1
	m = min(i4, i8, i15, i16, i23, i42)
	if m == 0:
		print(len(arr))
	else:
		print(len(arr) - m * 6)
else:
	print(n)


n = int(input())
a = [int(x) for x in input().split()]
s = [4, 8, 15, 16, 23, 42]
for i in range(n):
	a[i] = s.index(a[i])
dp = [0 for i in range(6)]
c = 0
for i in range(n):
	dp[a[i]] += 1
	if a[i] != 0 and dp[a[i]] > min(dp[:a[i]]):
		c += 1
		dp[a[i]] -= 1
print(c + sum(dp) - min(dp) * 6)


n = int(input())
nodes = [int(x) for x in input().split(' ')]
stand = [4, 8, 15, 16, 23, 42]
stepper = [0] * len(stand)
count = 0
for node in nodes:
	try:
		s_index = stand.index(node)
		if s_index > 0:
			if stepper[s_index - 1] <= stepper[s_index]:
				raise ValueError
		stepper[s_index] += 1
	except:
		count += 1
count_set = min(stepper)
stepper = [x - count_set for x in stepper]
count += sum(stepper)
print(count)


import sys
n = 0
b = 0
for line in sys.stdin:
	if n == 0:
		n = int(line.strip())
	else:
		b += 1
		l = list(map(int, line.strip().split()))
		a = [0, 0, 0, 0, 0, 0]
		counter = 0
		f = []
		c2 = 0
		for x in range(n):
			if l[x] == 4:
				a[0] += 1
			if l[x] == 8 and a[0] > a[1]:
				a[1] += 1
			if l[x] == 15 and a[1] > a[2]:
				a[2] += 1
			if l[x] == 16 and a[2] > a[3]:
				a[3] += 1
			if l[x] == 23 and a[3] > a[4]:
				a[4] += 1
			if l[x] == 42 and a[4] > a[5]:
				a[5] += 1
				counter += 6
		print(n - counter)
	if b == 1:
		sys.exit()


ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
si = lambda : input()
msi = lambda : map(int, stdin.readline().split())
lsi = lambda : list(msi())
n = ii()
a = li()
b = [0] * 6
for e in a:
	if e == 4:
		b[0] += 1
	elif e == 8 and b[0] > b[1]:
		b[1] += 1
	elif e == 15 and b[1] > b[2]:
		b[2] += 1
	elif e == 16 and b[2] > b[3]:
		b[3] += 1
	elif e == 23 and b[3] > b[4]:
		b[4] += 1
	elif e == 42 and b[4] > b[5]:
		b[5] += 1
print(n - 6 * b[5])


n = int(input())
a = list(map(int, input().split()))
vis = [0] * 6
for i in range(n):
	if a[i] == 42:
		a[i] = 5
	else:
		a[i] //= 4
		a[i] -= 1
for i in range(n):
	if a[i] == 0:
		vis[0] += 1
	else:
		vis[a[i]] = min(vis[a[i] - 1], vis[a[i]] + 1)
cnt = vis[5]
cnt *= 6
n -= cnt
print(n)


def doarun(a, i):
	temp = [4, 8, 15, 16, 23, 42]
	ind = temp.index(i)
	for i in range(ind):
		try:
			tem = a[temp[i]]
		except:
			return 0
	return 1
n = input()
arr = list(map(int, input().rstrip().split()))
a = dict()
lol = [a]
ind = dict()
tot = 0
ind[4] = ind[8] = ind[15] = ind[16] = ind[23] = ind[42] = 0
for i in arr:
	if i in {4, 8, 15, 16, 23, 42} and doarun(lol[ind[i]], i):
		lol[ind[i]][i] = 1
		ind[i] += 1
		try:
			temp = lol[ind[i]]
		except:
			temp = dict()
			lol.append(temp)
	else:
		tot += 1
for i in lol:
	if sum(i) != 108:
		for j in i:
			tot += i[j]
print(tot)


W = int(input())
A = list(map(int, input().split()))
B = [[], [], [], [], [], []]
for i in range(len(A)):
	if A[i] == 4:
		A[i] = 0
	elif A[i] == 8:
		A[i] = 1
	elif A[i] == 15:
		A[i] = 2
	elif A[i] == 16:
		A[i] = 3
	elif A[i] == 23:
		A[i] = 4
	elif A[i] == 42:
		A[i] = 5
Bb = [0, 0, 0, 0, 0, 0, 100000000000000]
for a in range(len(A)):
	if Bb[A[a] - 1] > 0:
		Bb[A[a]] += 1
		Bb[A[a] - 1] -= 1
print(len(A) - Bb[-2] * 6)


n = int(input())
a = list(map(int, input().split()))
d = dict()
d[4] = 0
d[8] = 0
d[15] = 0
d[16] = 0
d[23] = 0
d[42] = 0
l1 = [4, 8, 15, 16, 23, 42]
for i in a:
	if i == 4:
		d[4] += 1
	elif i == 8:
		if d[4] > d[8]:
			d[8] += 1
	elif i == 15:
		if d[8] > d[15]:
			d[15] += 1
	elif i == 16:
		if d[15] > d[16]:
			d[16] += 1
	elif i == 23:
		if d[16] > d[23]:
			d[23] += 1
	elif i == 42:
		if d[23] > d[42]:
			d[42] += 1
print(n - d[42] * 6)


n = int(input())
a = list(map(int, input().split()))
(l, t) = (0, n // 6)
k = [[] for _ in range(t)]
b = list(reversed(a))
d = [0 for _ in range(6)]
for i in range(n):
	s = b.pop()
	if s == 4:
		if d[0] < t:
			if k[d[0]] == []:
				k[d[0]].append(4)
				d[0] += 1
		else:
			l -= 1
	if s == 8:
		if d[1] < t:
			if k[d[1]] == [4]:
				k[d[1]].append(8)
				d[1] += 1
		else:
			l -= 1
	if s == 15:
		if d[2] < t:
			if k[d[2]] == [4, 8]:
				k[d[2]].append(15)
				d[2] += 1
		else:
			l -= 1
	if s == 16:
		if d[3] < t:
			if k[d[3]] == [4, 8, 15]:
				k[d[3]].append(16)
				d[3] += 1
		else:
			l -= 1
	if s == 23:
		if d[4] < t:
			if k[d[4]] == [4, 8, 15, 16]:
				k[d[4]].append(23)
				d[4] += 1
		else:
			l -= 1
	if s == 42:
		if d[5] < t:
			if k[d[5]] == [4, 8, 15, 16, 23]:
				k[d[5]].append(42)
				d[5] += 1
		else:
			l -= 1
l = k.count([4, 8, 15, 16, 23, 42]) * 6
print(n - l)


import traceback
import math
from collections import defaultdict
from functools import lru_cache
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def geti():
	return int(input())

def gets():
	return input()

def getil():
	return list(map(int, input().split()))
inf = float('inf')
mod = 10 ** 9 + 7

def main():
	N = geti()
	a = getil()
	seq = [4, 8, 15, 16, 23, 42]
	prv = {seq[i]: seq[i - 1] for i in range(1, 6)}
	prv[4] = 0
	d = defaultdict(int)
	d[0] = inf
	for n in a:
		if d[prv[n]] > 0:
			d[prv[n]] -= 1
			d[n] += 1
	return N - d[42] * 6
try:
	ans = main()
	print(ans)
except Exception as e:
	traceback.print_exc()


lista = [0] * 6
sequencia = [4, 8, 15, 16, 23, 42]
n = int(input())
entrada = map(int, input().split())
for x in entrada:
	indice = sequencia.index(x)
	if indice == 0:
		lista[indice] += 1
	elif lista[indice - 1]:
		lista[indice - 1] -= 1
		lista[indice] += 1
print(n - lista[5] * 6)


n = int(input())
a = list(map(int, input().split()))
t = [4, 8, 15, 16, 23, 42]
d = {}
for i in range(6):
	d[t[i]] = i
req = [0 for i in range(6)]
ans = 0
for i in a:
	if i not in d:
		ans += 1
	elif i == 4:
		req[d[i] + 1] += 1
	elif req[d[i]]:
		req[d[i]] -= 1
		if d[i] == 5:
			ans += 1
		else:
			req[d[i] + 1] += 1
print(-ans * 6 + n)


n = int(input())
a = list(map(lambda x: int(x), input().split()))
seq = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
seqList = [4, 8, 15, 16, 23, 42]
cont = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
subs = int(n / 6)
mat = [[] for i in range(subs)]
for el in a:
	pos = seq[el]
	prev = seqList[pos - 1]
	if pos > 0 and cont[prev] != 0:
		cont[prev] -= 1
		cont[el] += 1
	elif pos == 0:
		cont[4] += 1
print(n - cont[42] * 6)


def fcukof(n):
	a = input().split(' ')
	x = [0] * 6
	for i in a:
		if i == '4':
			x[0] += 1
		elif i == '8' and x[0] > x[1]:
			x[1] += 1
		elif i == '15' and x[1] > x[2]:
			x[2] += 1
		elif i == '16' and x[2] > x[3]:
			x[3] += 1
		elif i == '23' and x[3] > x[4]:
			x[4] += 1
		elif i == '42' and x[4] > x[5]:
			x[5] += 1
	return n - 6 * x[5]
x = int(input())
print(fcukof(x))


n = int(input())
c = [1000000000, 0, 0, 0, 0, 0, 0]
v = [0, 4, 8, 15, 16, 23, 42]
for i in map(int, input().split()):
	for j in range(1, 7):
		if i == v[j] and c[j - 1]:
			c[j] += 1
			c[j - 1] -= 1
print(n - c[6] * 6)


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	total = 0
	stack = [0] * 6
	for i in arr:
		if i == 4:
			stack[0] += 1
		elif i == 8:
			if stack[0] > 0:
				stack[1] += 1
				stack[1] = min(stack[0], stack[1])
		elif i == 15:
			if stack[0] > 0 and stack[1] > 0:
				stack[2] += 1
				stack[2] = min(stack[0], stack[1], stack[2])
		elif i == 16:
			if stack[0] > 0 and stack[1] > 0 and (stack[2] > 0):
				stack[3] += 1
				stack[3] = min(stack[0], stack[1], stack[2], stack[3])
		elif i == 23:
			if stack[0] > 0 and stack[1] > 0 and (stack[2] > 0) and (stack[3] > 0):
				stack[4] += 1
				stack[4] = min(stack[0], stack[1], stack[2], stack[3], stack[4])
		elif i == 42:
			if stack[0] > 0 and stack[1] > 0 and (stack[2] > 0) and (stack[3] > 0) and (stack[4] > 0):
				stack[5] += 1
				stack[0] -= 1
				stack[1] -= 1
				stack[2] -= 1
				stack[3] -= 1
				stack[4] -= 1
	print(n - 6 * stack[-1])
main()


n = int(input())
a = list(map(int, input().split()))
di = dict()
di[4] = 0
di[8] = 0
di[15] = 0
di[16] = 0
di[23] = 0
di[42] = 0
l = [4, 8, 15, 16, 23, 42]
for i in range(n):
	flag = 1
	for j in range(l.index(a[i])):
		if di[a[i]] >= di[l[j]]:
			flag = 0
			break
	if flag == 1:
		di[a[i]] += 1
mi = min(di.values())
ans = n - mi * 6
print(ans)


n = int(input())
l = list(map(int, input().split()))
dict = {4: 1, 8: 2, 15: 3, 16: 4, 23: 5, 42: 6}
a = [0] * 7
a[0] = n
for i in l:
	check = dict[i]
	if a[check - 1]:
		a[check - 1] -= 1
		a[check] += 1
print(n - a[6] * 6)


n = int(input())
cnt = {i: 0 for i in range(1, 7)}
cnt[0] = float('inf')
f = {x: i + 1 for (i, x) in enumerate((4, 8, 15, 16, 23, 42))}
for e in map(int, input().split()):
	e = f[e]
	if cnt[e - 1] > 0:
		cnt[e] += 1
		cnt[e - 1] -= 1
print(n - 6 * cnt[6])


n = int(input())
l = list(map(int, input().split()))
a = [4, 8, 15, 16, 23, 42]
d = [0] * 6
for i in range(n):
	s = a.index(l[i])
	if s == 0:
		d[s] += 1
	if d[s - 1] > d[s]:
		d[s] += 1
print(n - d[5] * 6)


good = [4, 8, 15, 16, 23, 42]
count = [0] * 6
t = 0
n = int(input())
for i in map(int, input().split()):
	x = good.index(i)
	if x == 0 or count[x - 1] > count[x]:
		count[x] += 1
	else:
		t += 1
t += sum((k - count[-1] for k in count))
print(t)


import sys
n = int(input())
a = list(map(int, input().split()))
v = [4, 8, 15, 16, 23, 42]
if n < 6:
	print(n)
elif n == 6:
	if v == a:
		print(0)
	else:
		print(6)
else:
	s = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
	d = 0
	for i in a:
		if i == 8 and s[i] == s[4]:
			d += 1
		elif i == 15 and s[i] == s[8]:
			d += 1
		elif i == 16 and s[i] == s[15]:
			d += 1
		elif i == 23 and s[i] == s[16]:
			d += 1
		elif i == 42 and s[i] == s[23]:
			d += 1
		else:
			s[i] += 1
	mval = min(s.values())
	for i in s:
		d += s[i] - mval
	print(d)


n = int(input())
a = [int(x) for x in input().split()]
exist = [4, 8, 15, 16, 23, 42]
s = set(exist)
waiting = [0] * 6
ans = 0
for x in a:
	if x not in s:
		ans += 1
		continue
	if x == 4:
		waiting[0] += 1
		continue
	pos = exist.index(x)
	if waiting[pos - 1] == 0:
		ans += 1
		continue
	waiting[pos - 1] -= 1
	if x != 42:
		waiting[pos] += 1
for i in range(6):
	ans += (i + 1) * waiting[i]
print(ans)


n = int(input())
s = input()
s1 = s.split()
l = [int(i) for i in s1]
d = [4, 8, 15, 16, 23, 42]
dp = {}
for i in range(len(l)):
	if l[i] == 4:
		if 4 not in dp:
			dp[4] = 1
		else:
			dp[4] = dp[4] + 1
	if l[i] == 8:
		if 4 in dp and 8 not in dp:
			dp[8] = 1
		elif 4 in dp and dp[8] < dp[4]:
			dp[8] = dp[8] + 1
	if l[i] == 15:
		if 8 in dp and 15 not in dp:
			dp[15] = 1
		elif 8 in dp and dp[15] < dp[8]:
			dp[15] = dp[15] + 1
	if l[i] == 16:
		if 15 in dp and 16 not in dp:
			dp[16] = 1
		elif 16 in dp and dp[16] < dp[15]:
			dp[16] = dp[16] + 1
	if l[i] == 23:
		if 16 in dp and 23 not in dp:
			dp[23] = 1
		elif 23 in dp and dp[23] < dp[16]:
			dp[23] = dp[23] + 1
	if l[i] == 42:
		if 23 in dp and 42 not in dp:
			dp[42] = 1
		elif 42 in dp and dp[42] < dp[23]:
			dp[42] = dp[42] + 1
if 42 in dp:
	print(len(l) - 6 * dp[42])
else:
	print(len(l))


n = int(input())
arr = list(map(int, input().split()))
cnt1 = 0
cnt2 = 0
cnt3 = 0
cnt4 = 0
cnt5 = 0
cnt6 = 0
for i in range(n):
	if arr[i] == 4:
		cnt1 += 1
	elif arr[i] == 8:
		if cnt2 < cnt1:
			cnt2 += 1
	elif arr[i] == 15:
		if cnt3 < cnt2:
			cnt3 += 1
	elif arr[i] == 16:
		if cnt4 < cnt3:
			cnt4 += 1
	elif arr[i] == 23:
		if cnt5 < cnt4:
			cnt5 += 1
	elif arr[i] == 42:
		if cnt6 < cnt5:
			cnt6 += 1
print(n - 6 * cnt6)


len_arr = int(input())
arr = input()
num_arr = map(int, arr.split(' '))
order = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
progress = [0] * 6
for elt in num_arr:
	o = order[elt]
	if o == 0:
		progress[0] += 1
	elif progress[o - 1] != 0:
		progress[o - 1] -= 1
		progress[o] += 1
s = progress[-1] * 6
print(len_arr - s)


n = int(input())
x = list(map(int, input().split()))
ans = 0
(cnt4, cnt8, cnt15, cnt16, cnt23, cnt42) = (0, 0, 0, 0, 0, 0)
for i in range(n):
	if x[i] == 4:
		cnt4 += 1
	elif x[i] == 8:
		if cnt4 > cnt8:
			cnt8 += 1
		else:
			ans += 1
	elif x[i] == 15:
		if cnt8 > cnt15:
			cnt15 += 1
		else:
			ans += 1
	elif x[i] == 16:
		if cnt15 > cnt16:
			cnt16 += 1
		else:
			ans += 1
	elif x[i] == 23:
		if cnt16 > cnt23:
			cnt23 += 1
		else:
			ans += 1
	elif x[i] == 42:
		if cnt23 > cnt42:
			cnt42 += 1
		else:
			ans += 1
if n >= 6:
	print(n - cnt42 * 6)
else:
	print(n)


import math
import bisect
import heapq
from collections import defaultdict

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, x, y) = egcd(b % a, a)
		return (g, y - b // a * x, x)

def mulinv(b, n):
	(g, x, _) = egcd(b, n)
	if g == 1:
		return x % n

def isprime(n):
	for d in range(2, int(math.sqrt(n)) + 1):
		if n % d == 0:
			return False
	return True

def argsort(ls):
	return sorted(range(len(ls)), key=ls.__getitem__)

def f(p=0):
	if p == 1:
		return map(int, input().split())
	elif p == 2:
		return list(map(int, input().split()))
	elif p == 3:
		return list(input())
	else:
		return int(input())

class DisjointSet:
	_disjoint_set = list()

	def __init__(self, init_arr):
		self._disjoint_set = []
		if init_arr:
			for item in list(set(init_arr)):
				self._disjoint_set.append([item])

	def _find_index(self, elem):
		for item in self._disjoint_set:
			if elem in item:
				return self._disjoint_set.index(item)
		return None

	def find(self, elem):
		for item in self._disjoint_set:
			if elem in item:
				return self._disjoint_set[self._disjoint_set.index(item)]
		return None

	def union(self, elem1, elem2):
		index_elem1 = self._find_index(elem1)
		index_elem2 = self._find_index(elem2)
		if index_elem1 != index_elem2 and index_elem1 is not None and (index_elem2 is not None):
			self._disjoint_set[index_elem2] = self._disjoint_set[index_elem2] + self._disjoint_set[index_elem1]
			del self._disjoint_set[index_elem1]
		return self._disjoint_set

	def get(self):
		return self._disjoint_set

def graph(n, m, edg=False):
	edges = []
	visited = [0] * n
	g = [list() for _ in range(n + 1)]
	for i in range(m):
		(u, v) = f(1)
		g[u].append(v)
		g[v].append(u)
		if edg:
			edges.append((u, v))
	if edg:
		return (g, visited, edg)
	else:
		return (g, visited)

def bfs(g, visited):
	queue = [1]
	visited[1] = 1
	for u in queue:
		for v in g[u]:
			if visited[v] == 0:
				queue.append(v)
			visited[v] = 1

def dfs(u, g, visited):
	print(u)
	visited[u] = 1
	for v in g[u]:
		if visited[v] == 0:
			dfs(v, g, visited)
queue = [0, 0, 0, 0, 0, 0]
n = f()
cl = f(2)
count = 0
for i in range(n):
	st = True
	pos = 0
	if cl[i] == 4:
		pos = 0
	elif cl[i] == 8:
		pos = 1
	elif cl[i] == 15:
		pos = 2
	elif cl[i] == 16:
		pos = 3
	elif cl[i] == 23:
		pos = 4
	elif cl[i] == 42:
		pos = 5
	else:
		st = False
	if st:
		if pos == 0:
			queue[0] += 1
		elif queue[pos - 1] != 0:
			queue[pos - 1] -= 1
			queue[pos] += 1
print(n - queue[-1] * 6)


n = int(input())
a = list(map(int, input().split()))
nums = [4, 8, 15, 16, 23, 42]
aux = [n, 0, 0, 0, 0, 0, 0]
for i in range(len(a)):
	if a[i] in nums:
		j = nums.index(a[i]) + 1
		if aux[j - 1] != 0:
			aux[j] += 1
			aux[j - 1] -= 1
result = n - aux[6] * 6
print(result)


a = [4, 8, 15, 16, 23, 42]
n = int(input())
l = list(map(int, input().split()))
for i in range(len(l)):
	l[i] = a.index(l[i])
count = [0] * 6
for i in range(len(l)):
	if l[i] == 0:
		count[0] += 1
	elif count[l[i] - 1] > 0:
		count[l[i] - 1] -= 1
		count[l[i]] += 1
print(n - 6 * count[5])


n = int(input())
arr = list(map(int, input().split(' ')))
count = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
res = 0
for num in arr:
	done = False
	if num == 4:
		count[num] += 1
		done = True
	elif num == 8:
		if count[4] > 0:
			count[num] += 1
			count[4] -= 1
			done = True
	elif num == 15:
		if count[8] > 0:
			count[num] += 1
			count[8] -= 1
			done = True
	elif num == 16:
		if count[15] > 0:
			count[num] += 1
			count[15] -= 1
			done = True
	elif num == 23:
		if count[16] > 0:
			count[num] += 1
			count[16] -= 1
			done = True
	elif num == 42:
		if count[23] > 0:
			count[num] += 1
			count[23] -= 1
			done = True
	if not done:
		res += 1
t = {4, 8, 15, 16, 23}
for (idx, num) in enumerate(t):
	res += (idx + 1) * count[num]
print(res)


n = int(input())
a = list(map(int, input().split()))
cnt = [n, 0, 0, 0, 0, 0, 0]
dig = [4, 8, 15, 16, 23, 42]
for x in a:
	ind = dig.index(x) + 1
	if cnt[ind - 1] > cnt[ind]:
		cnt[ind] += 1
ans = n - cnt[6] * 6
print(ans)


from collections import defaultdict, deque

def main():
	n = int(input())
	a = list(map(int, input().split()))
	d = defaultdict(deque)
	for (ind, elem) in enumerate(a):
		d[elem].append(ind)
	answer = 0
	while all((k for k in d.values())):
		next_ = -1
		carry = 0
		for k in sorted(d.keys()):
			while 1:
				if d[k]:
					q = d[k].popleft()
					if q > next_:
						carry += 1
						next_ = q
						break
					answer += 1
				else:
					break
		if carry != 6:
			answer += carry
	for k in d:
		answer += len(d[k])
	print(answer)
main()


n = int(input())
a = list(map(int, input().split()))
c = [0, 0, 0, 0, 0, 0]
r = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
for x in a:
	if r.get(x, -1) != -1:
		y = r.get(x)
		if y == 0:
			c[0] += 1
		elif c[y - 1] != 0:
			c[y - 1] -= 1
			c[y] += 1
print(len(a) - c[-1] * 6)


a = [4, 8, 15, 16, 23, 42]
dic = {}
for i in range(6):
	dic[a[i]] = i
num = int(input())
data = [int(i) for i in input().split()]
count = [0] * 6
for d in data:
	i = dic[d]
	if i == 0:
		count[0] += 1
	elif count[i - 1] > count[i]:
		count[i] += 1
print(num - 6 * count[5])


n = int(input())
a = list(map(int, input().split()))
arr = [0] * 43
rem = 0
for i in range(n):
	if a[i] == 4:
		arr[4] += 1
	elif a[i] == 8:
		if arr[4] >= 1:
			arr[8] += 1
			arr[4] -= 1
		else:
			rem += 1
	elif a[i] == 15:
		if arr[8] >= 1:
			arr[15] += 1
			arr[8] -= 1
		else:
			rem += 1
	elif a[i] == 16:
		if arr[15] >= 1:
			arr[16] += 1
			arr[15] -= 1
		else:
			rem += 1
	elif a[i] == 23:
		if arr[16] >= 1:
			arr[23] += 1
			arr[16] -= 1
		else:
			rem += 1
	elif arr[23] >= 1:
		arr[42] += 1
		arr[23] -= 1
	else:
		rem += 1
print(n - 6 * arr[42])


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import deque

def main():
	n = int(input())
	rem = n
	dict1 = {}
	arr = [4, 8, 15, 16, 23, 42]
	for num in arr:
		dict1[num] = []
	vals = list(map(int, input().split()))
	for s in range(n):
		dict1[vals[s]].append(s)
	for num in arr:
		dict1[num] = deque(dict1[num])
	while len(dict1[4]) > 0:
		count = 1
		cur = dict1[4].popleft()
		for i in range(1, 6):
			while len(dict1[arr[i]]) > 0:
				v0 = dict1[arr[i]].popleft()
				if v0 > cur:
					count += 1
					cur = v0
					break
		if count == 6:
			rem -= 6
		else:
			break
	print(rem)
main()


n = int(input())
a = list(map(int, input().split()))
b = [4, 8, 15, 16, 23, 42]
dicsub = {8: 4, 15: 8, 16: 15, 23: 16, 42: 23}
ans = 0
s = {}
for i in b:
	s[i] = 0
for i in a:
	if i == 4:
		s[i] += 1
		continue
	if s[i] == s[dicsub[i]]:
		ans += 1
	else:
		s[i] += 1
for i in s:
	ans += s[i] - s[42]
print(ans)


from sys import stdin, setrecursionlimit
import heapq

def refine(arr):
	aux = []
	for i in range(len(arr)):
		if arr[i] in [4, 8, 15, 16, 23, 42]:
			aux.append(arr[i])
	return aux
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().split()))
arr = refine(arr)
mydict = dict()
mydict[4] = 0
mydict[8] = 0
mydict[15] = 0
mydict[16] = 0
mydict[23] = 0
mydict[42] = 0
for i in range(len(arr)):
	if arr[i] == 4:
		mydict[4] += 1
	elif arr[i] == 8:
		if mydict[4] >= mydict[8] + 1:
			mydict[8] += 1
	elif arr[i] == 15:
		if mydict[8] >= mydict[15] + 1:
			mydict[15] += 1
	elif arr[i] == 16:
		if mydict[15] >= mydict[16] + 1:
			mydict[16] += 1
	elif arr[i] == 23:
		if mydict[16] >= mydict[23] + 1:
			mydict[23] += 1
	elif arr[i] == 42:
		if mydict[23] >= mydict[42] + 1:
			mydict[42] += 1
print(n - mydict[42] * 6)


n = int(input())
a = list(map(int, input().split()))
c1 = 0
c2 = 0
c3 = 0
c4 = 0
c5 = 0
c6 = 0
ans = 0
for i in range(n):
	if a[i] == 4:
		c1 += 1
	elif a[i] == 8:
		c2 = min(c2 + 1, c1)
	elif a[i] == 15:
		c3 = min(c3 + 1, c2)
	elif a[i] == 16:
		c4 = min(c4 + 1, c3)
	elif a[i] == 23:
		c5 = min(c5 + 1, c4)
	elif a[i] == 42 and c5:
		ans += 1
		c5 -= 1
		c4 -= 1
		c3 -= 1
		c2 -= 1
		c1 -= 1
print(n - 6 * ans)


from sys import stdin
from bisect import bisect_right
inp = lambda : stdin.readline().strip()
n = int(inp())
a = [int(x) for x in inp().split()]
v = {8: 4, 15: 8, 16: 15, 23: 16, 42: 23}
d = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
for i in a:
	if i == 4 or d[v[i]] > d[i]:
		d[i] += 1
minimum = 10 ** 9
for i in d.values():
	minimum = min(i, minimum)
print(len(a) - minimum * 6)


import math as mt
import sys, string, bisect
input = sys.stdin.readline
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
n = I()
l = L()
d = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
for i in l:
	if i == 4:
		d[4] += 1
	elif i == 8 and d[8] < d[4]:
		d[8] += 1
	elif i == 15 and d[15] < d[8]:
		d[15] += 1
	elif i == 16 and d[16] < d[15]:
		d[16] += 1
	elif i == 23 and d[23] < d[16]:
		d[23] += 1
	elif i == 42 and d[42] < d[23]:
		d[42] += 1
print(n - 6 * d[42])


x = int(input())
a = list(map(int, input().split()))
b = [4, 8, 15, 16, 23, 42]
c = [0] * 6
l = 0
for i in a:
	if i == 4:
		c[0] += 1
	elif i == 8:
		if c[1] + 1 <= c[0]:
			c[1] += 1
		else:
			l += 1
	elif i == 15:
		if c[2] + 1 <= c[1]:
			c[2] += 1
		else:
			l += 1
	elif i == 16:
		if c[3] + 1 <= c[2]:
			c[3] += 1
		else:
			l += 1
	elif i == 23:
		if c[4] + 1 <= c[3]:
			c[4] += 1
		else:
			l += 1
	elif i == 42:
		if c[5] + 1 <= c[4]:
			c[5] += 1
		else:
			l += 1
p = min(c)
for i in c:
	l += i - p
print(l)


n = int(input())
numbers = list(map(int, input().split()))
bad_elements = 0
elements = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
count = {0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0}
for number in numbers:
	if number == 4:
		count[elements[4]] = count[elements[4]] + 1
	elif count[elements[number] - 1] <= count[elements[number]]:
		bad_elements += 1
	else:
		count[elements[number]] = count[elements[number]] + 1
sequences = min(count.values())
result = n - sequences * 6
print(result)


n = int(input())
y = list(map(int, input().split()))
if n == 0:
	print(0)
elif n < 6:
	print(n)
else:
	z = [0] * 6
	j = 0
	while j < n:
		if y[j] == 4:
			z[0] = z[0] + 1
		elif y[j] != 42:
			x = y[j] // 4 - 1
			if z[x] < z[x - 1]:
				z[x] = z[x] + 1
		elif z[5] < z[4]:
			z[5] = z[5] + 1
		j = j + 1
	t = min(z)
	print(n - t * 6)


n = int(input())
a = list(map(int, input().split()))
cnt = [0] * 7
cnt[0] = n
for b in a:
	idx = [4, 8, 15, 16, 23, 42].index(b)
	cnt[idx + 1] += cnt[idx + 1] < cnt[idx]
print(n - cnt[6] * 6)


def get_minimum_removals(n, seq, base, dic):
	for i in range(n):
		elem = seq[i]
		if dic[elem] == 0 or base[dic[elem] - 1] > base[dic[elem]]:
			base[dic[elem]] += 1
	return n - 6 * base[5]
n = int(input())
seq = [int(x) for x in input().split()]
base = [0] * 6
dic = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
print(get_minimum_removals(n, seq, base, dic))


n = int(input())
arr = list(map(int, input().split()))
cur = [4, 8, 15, 16, 23, 42]
gen = []
for el in arr:
	if el in cur:
		gen.append(el)
minus = n - len(gen)
ind_need = 0
added = 0
st = [0] * 6
D = dict()
D[4] = 0
D[8] = 1
D[15] = 2
D[16] = 3
D[23] = 4
D[42] = 5
for i in range(len(gen)):
	gen[i] = D[gen[i]]
st = [0] * 6
for i in range(len(gen)):
	if gen[i] == 0:
		st[0] += 1
	elif st[gen[i] - 1] > st[gen[i]]:
		st[gen[i]] += 1
	if st[5] == 1:
		for j in range(len(st)):
			st[j] -= 1
		added += 6
minus += len(gen) - added
print(minus)


from collections import Counter
n = int(input())
l = [int(i) for i in input().split(' ')]
cnt = Counter()
for i in [4, 8, 15, 16, 23]:
	cnt[i] = 0
ans = 0
for i in l:
	if i == 4:
		cnt[4] += 1
	elif i == 8:
		if cnt[4] > cnt[8]:
			cnt[8] += 1
		else:
			ans += 1
	elif i == 15:
		if cnt[8] > cnt[15]:
			cnt[15] += 1
		else:
			ans += 1
	elif i == 16:
		if cnt[15] > cnt[16]:
			cnt[16] += 1
		else:
			ans += 1
	elif i == 23:
		if cnt[16] > cnt[23]:
			cnt[23] += 1
		else:
			ans += 1
	elif cnt[23]:
		for j in [4, 8, 15, 16, 23]:
			cnt[j] -= 1
	else:
		ans += 1
print(ans + sum(cnt.values()))


n = int(input())
a = [int(i) for i in input().split()]
d = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
mi = 1000000000.0
for i in range(n):
	d[a[i]] += 1
	if a[i] == 8:
		if d[8] > d[4]:
			d[8] = d[4]
	elif a[i] == 15:
		if d[15] > d[8]:
			d[15] = d[8]
	elif a[i] == 16:
		if d[16] > d[15]:
			d[16] = d[15]
	elif a[i] == 23:
		if d[23] > d[16]:
			d[23] = d[16]
	elif a[i] == 42:
		if d[42] > d[23]:
			d[42] = d[23]
for x in d:
	mi = min(mi, d[x])
print(n - 6 * mi)


import sys
import os
from io import IOBase, BytesIO

def main():
	n = int(input())
	arr = get_array()
	di = {}
	for i in range(n):
		if arr[i] not in di:
			di[arr[i]] = []
		di[arr[i]].append(i)
	chk = [4, 8, 15, 16, 23, 42]
	for i in chk:
		if i not in di:
			print(n)
			return
	(a, b, c, d, e, f) = (0, 0, 0, 0, 0, 0)
	ans = 0
	while True:
		if a >= len(di[4]) or b >= len(di[8]) or c >= len(di[15]) or (d >= len(di[16])) or (e >= len(di[23])) or (f >= len(di[42])):
			break
		curr = b
		while curr < len(di[8]) and di[4][a] > di[8][curr]:
			curr += 1
		if curr == len(di[8]):
			break
		a += 1
		b = curr
		curr = c
		while curr < len(di[15]) and di[8][b] > di[15][curr]:
			curr += 1
		if curr == len(di[15]):
			break
		b += 1
		c = curr
		curr = d
		while curr < len(di[16]) and di[15][c] > di[16][curr]:
			curr += 1
		if curr == len(di[16]):
			break
		c += 1
		d = curr
		curr = e
		while curr < len(di[23]) and di[16][d] > di[23][curr]:
			curr += 1
		if curr == len(di[23]):
			break
		d += 1
		e = curr
		curr = f
		while curr < len(di[42]) and di[23][e] > di[42][curr]:
			curr += 1
		if curr == len(di[42]):
			break
		e += 1
		f = curr + 1
		ans += 6
	print(n - ans)
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		py2 = round(0.5)
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().strip()
main()


n = int(input())
a = list(map(int, input().split()))
c = 0
t = [4, 8, 15, 16, 23, 42]
ar = [0] * 6
for i in range(n):
	ind = t.index(a[i])
	if ind == 0:
		ar[ind] += 1
	elif ar[ind - 1] - ar[ind] >= 1:
		ar[ind] += 1
print(n - min(ar) * 6)


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
B = []
C = []
D = []
E = []
F = []
G = []
for i in range(n):
	if A[i] == 4:
		B.append(i)
	if A[i] == 8:
		C.append(i)
	if A[i] == 15:
		D.append(i)
	if A[i] == 16:
		E.append(i)
	if A[i] == 23:
		F.append(i)
	if A[i] == 42:
		G.append(i)
NOW = 0
Bi = 0
Ci = 0
Di = 0
Ei = 0
Fi = 0
Gi = 0
ANS = 0
while True:
	for b in range(Bi, len(B)):
		NOW = B[b]
		Bi = b + 1
		break
	else:
		break
	for c in range(Ci, len(C)):
		if C[c] >= NOW:
			NOW = C[c]
			Ci = c + 1
			break
	else:
		break
	for d in range(Di, len(D)):
		if D[d] >= NOW:
			NOW = D[d]
			Di = d + 1
			break
	else:
		break
	for e in range(Ei, len(E)):
		if E[e] >= NOW:
			NOW = E[e]
			Ei = e + 1
			break
	else:
		break
	for f in range(Fi, len(F)):
		if F[f] >= NOW:
			NOW = F[f]
			Fi = f + 1
			break
	else:
		break
	for g in range(Gi, len(G)):
		if G[g] >= NOW:
			NOW = G[g]
			Gi = g + 1
			break
	else:
		break
	ANS += 6
print(len(A) - ANS)


def teryi(lst):
	x = [4, 8, 15, 16, 23, 42]
	(count, result) = ([0] * 43, 0)
	for elem in lst:
		count[elem] += 1
		if elem == 8:
			count[8] = min(count[4], count[8])
		if elem == 15:
			count[15] = min(count[4], count[8], count[15])
		if elem == 16:
			count[16] = min(count[4], count[8], count[15], count[16])
		if elem == 23:
			count[23] = min(count[4], count[8], count[15], count[16], count[23])
		if elem == 42:
			count[42] = min(count[4], count[8], count[15], count[16], count[23], count[42])
		if elem == 42 and min((count[j] for j in x)) > 0:
			for j in range(6):
				count[x[j]] -= 1
			result += 1
	return len(lst) - result * 6
m = int(input())
arr = [int(y) for y in input().split()]
print(teryi(arr))


from collections import defaultdict

def go():
	n = int(input())
	keys = [4, 8, 15, 16, 23, 42]
	keep = defaultdict(list)
	for (i, e) in enumerate(input().split(' ')):
		keep[int(e)].append(i)
	for k in keys:
		keep[k].reverse()
	to_remove = 0
	current = []
	index = 0
	while True:
		if len(current) == 6:
			for i in range(5):
				while current[i] > current[i + 1]:
					if len(keep[keys[i + 1]]) > 0:
						current[i + 1] = keep[keys[i + 1]].pop()
						to_remove += 1
					else:
						break
			s_current = sorted(current)
			if s_current == current:
				current = []
				index = 0
			else:
				break
		if len(keep[keys[index]]) > 0:
			current.append(keep[keys[index]].pop())
			index += 1
		else:
			break
	return len(current) + sum((len(i) for i in keep.values())) + to_remove
print(go())


def f(x):
	return (4, 8, 15, 16, 23, 42).index(int(x))
n = int(input())
a = list(map(f, input().split()))
ans = 0
b = [0, 0, 0, 0, 0, 0]
for i in a:
	if i == 0:
		b[0] += 1
	elif b[i - 1]:
		b[i - 1] -= 1
		b[i] += 1
	else:
		ans += 1
print(ans + sum([(i + 1) * b[i] for i in range(5)]))


sample = [4, 8, 15, 16, 23, 42]
n = int(input())
d = [x for x in map(int, input().split())]
newN = n
index = 0
indexFound = [0, 0, 0, 0, 0, 0]
while index < n:
	found = 0
	for i in range(len(sample)):
		index = indexFound[i]
		while index < n:
			if d[index] == sample[i]:
				break
			index += 1
		if index >= n:
			break
		indexFound[i] = index + 1
		for j in range(i + 1, len(sample)):
			if indexFound[j] < index + 1:
				indexFound[j] = index + 1
		d[index] = -1
		found += 1
	if found == 6:
		newN -= 6
	else:
		break
print(newN)


n = int(input())
a = [int(s) for s in input().split(' ')]
col = 0
b = [0, 0, 0, 0, 0, 0]
for el in a:
	if el == 4:
		b[0] += 1
	elif el == 8:
		if b[0] > 0:
			b[0] -= 1
			b[1] += 1
		else:
			col += 1
	elif el == 15:
		if b[1] > 0:
			b[1] -= 1
			b[2] += 1
		else:
			col += 1
	elif el == 16:
		if b[2] > 0:
			b[2] -= 1
			b[3] += 1
		else:
			col += 1
	elif el == 23:
		if b[3] > 0:
			b[3] -= 1
			b[4] += 1
		else:
			col += 1
	elif el == 42:
		if b[4] > 0:
			b[4] -= 1
			b[5] += 1
		else:
			col += 1
	else:
		col += 1
col += b[0] + 2 * b[1] + 3 * b[2] + 4 * b[3] + 5 * b[4]
print(col)


R = lambda : map(int, input().split())
n = int(input())
L = list(R())
A = [0] * 6
B = [4, 8, 15, 16, 23, 42]
c = 0
for i in range(n):
	f = 1
	ind = B.index(L[i])
	for j in range(ind):
		if A[j] <= A[ind]:
			f = 0
			break
	if f:
		A[ind] += 1
print(n - 6 * A[5])


from collections import defaultdict
MEMBERS = (4, 8, 15, 16, 23, 42)
progress = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
n = int(input())
a = map(int, input().split())
idx = []
counts = defaultdict(int)
for num in a:
	if progress[num] == 0:
		counts[0] += 1
	elif counts[progress[num] - 1] > 0:
		counts[progress[num] - 1] -= 1
		counts[progress[num]] += 1
print(n - counts[5] * 6)


n = int(input())
kol = [0, 0, 0, 0, 0, 0]
ind = [4, 8, 15, 16, 23, 42]
delete = 0
for i in map(int, input().split()):
	for j in range(6):
		if ind[j] == i:
			cur = j
			break
	if cur == 0:
		kol[0] += 1
	elif kol[cur - 1] != 0:
		kol[cur - 1] -= 1
		kol[cur] += 1
	else:
		delete += 1
print(delete + kol[0] + kol[1] * 2 + kol[2] * 3 + kol[3] * 4 + kol[4] * 5)


n = int(input())
req = [4, 8, 15, 16, 23, 42]
check = [0, 0, 0, 0, 0, 0]
num = [0, 0, 0, 0, 0, 0]
a = list(map(int, input().split()))
for i in a:
	ind = req.index(i)
	if ind == 0:
		check[0] = 1
		num[0] += 1
	elif num[ind - 1]:
		num[ind - 1] -= 1
		num[ind] += 1
print(n - num[5] * 6)


n = int(input())
a = [int(x) for x in input().split()]
val = [4, 8, 15, 16, 23, 42]
d = {}
for i in val:
	d[i] = 0
mn = 0
i = 0
while i < n:
	id = val.index(a[i])
	if id > 0 and d[val[id - 1]] > d[val[id]]:
		d[a[i]] += 1
	elif id == 0:
		d[val[id]] += 1
	i += 1
	mn = min(d.values())
ans = n - 6 * mn
print(ans)


n = int(input())
a = list(map(int, input().split()))
good_nums = [4, 8, 15, 16, 23, 42]
seqs = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0}
for el in a:
	el_idx = good_nums.index(el)
	if el_idx == 0:
		seqs[1] += 1
	elif seqs[el_idx] > 0:
		seqs[el_idx] -= 1
		seqs[el_idx + 1] += 1
num_good = seqs[6]
print(n - 6 * num_good)


n = int(input())
s = list(map(int, input().split()))
count = [0] * 6
for temp in s:
	if temp == 4:
		count[0] += 1
	elif temp == 8 and count[0] > count[1]:
		count[1] += 1
	elif temp == 15 and count[1] > count[2]:
		count[2] += 1
	elif temp == 16 and count[2] > count[3]:
		count[3] += 1
	elif temp == 23 and count[3] > count[4]:
		count[4] += 1
	elif temp == 42 and count[4] > count[5]:
		count[5] += 1
	else:
		pass
out = n - 6 * min(count)
print(out)


NUMBERS = [4, 8, 15, 16, 23, 42]

def good_array(arr):
	count = [0 for i in range(6)]
	if len(arr) == 0:
		return 0
	for i in arr:
		n = 0
		while True:
			if i == NUMBERS[n]:
				if n == 0 or count[n] < count[n - 1]:
					count[n] += 1
				break
			n += 1
	return len(arr) - 6 * count[5]
n = int(input())
arr = list(map(int, input().split()))
print(good_array(arr))


y = int(input())
a = list(map(int, input().split()))
t = [4, 8, 15, 16, 23, 42]
ans = 0
d = {}
for i in t:
	d.setdefault(i, 0)
for i in a:
	indx = t.index(i)
	if indx > 0:
		if d[t[indx - 1]] > d[t[indx]]:
			d[t[indx]] += 1
		else:
			ans += 1
	elif indx == 0:
		d[4] += 1
mini = d[42]
for i in d.keys():
	ans = ans + d[i] - mini
print(ans)


def lost(arr):
	if len(arr) < 6:
		return len(arr)
	else:
		cons = [0, 0, 0, 0, 0, 0]
		for number in arr:
			if number == 4:
				cons[0] += 1
			elif number == 8 and cons[0] > 0:
				cons[0] -= 1
				cons[1] += 1
			elif number == 15 and cons[1] > 0:
				cons[1] -= 1
				cons[2] += 1
			elif number == 16 and cons[2] > 0:
				cons[2] -= 1
				cons[3] += 1
			elif number == 23 and cons[3] > 0:
				cons[3] -= 1
				cons[4] += 1
			elif number == 42 and cons[4] > 0:
				cons[4] -= 1
				cons[5] += 1
	return len(arr) - cons[5] * 6
n = int(input())
arr = list(map(int, input().split()))
print(lost(arr))


n = int(input())
numbers = list(map(int, input().split()))
dict_numbers = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
count = [0, 0, 0, 0, 0, 0]
for i in numbers:
	if dict_numbers.get(i) == 0:
		count[dict_numbers.get(i)] += 1
	elif count[dict_numbers.get(i) - 1] > 0:
		count[dict_numbers.get(i) - 1] -= 1
		count[dict_numbers.get(i)] += 1
print(n - 6 * count[5])


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac
from itertools import permutations as permu

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
n = int(z())
lst = zzz()
zrr = [4, 8, 15, 16, 23, 42]
ans = [0] + [n] * 6
for x in lst:
	i = zrr.index(x)
	if ans[i] < n:
		ans[i] += 6
		ans[i + 1] -= 6
print(ans[6])


import bisect
import os
import gc
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math
import statistics

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	s = set()
	for p in range(2, n + 1):
		if prime[p]:
			s.add(p)
	return s

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def main():
	n = iin()
	a = ain()
	l = [4, 8, 15, 16, 23, 42]
	if set(a) != set(l):
		print(n)
	else:
		d = {}
		flag = 0
		for i in l:
			d[i] = deque([])
		for i in range(n):
			d[a[i]].append(i)
		ans = 0
		x = -1
		flag = 0
		for i in d[4]:
			x = i
			for j in l[1:]:
				flag = 0
				k = 0
				ll = len(d[j])
				while k < ll:
					if d[j][0] < x:
						d[j].popleft()
						k += 1
					else:
						flag = 1
						x = d[j][0]
						d[j].popleft()
						break
				if flag == 0:
					break
			if flag == 0:
				break
			else:
				ans += 1
		print(n - ans * 6)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if os.getcwd() == 'D:\\code':
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
a = list(map(int, input().split()))
b = [4, 8, 15, 16, 23, 42]
ans = 0
y = 0
l = [[] for j in range(n // 6)]
t = [0] * 6
i = 0
while i < n:
	for j in range(6):
		if a[i] == b[j]:
			break
	if t[j] < n // 6 and len(l[t[j]]) == j:
		l[t[j]].append(b[j])
		y -= 1
		i += 1
		t[j] += 1
	else:
		i += 1
ans = len(a) + y
for i in range(len(l)):
	if len(l[i]) != 6:
		ans += len(l[i])
print(ans)


from math import *
from itertools import *
from collections import *
from bisect import *
seq = (4, 8, 15, 16, 23, 42)
cnt = [0] * 6
n = int(input())
lst = [int(x) for x in input().split()]
for i in lst:
	if i == 4:
		cnt[0] += 1
	elif i in seq:
		idx = seq.index(i)
		if cnt[idx - 1] > cnt[idx]:
			cnt[idx] += 1
result = n - min(cnt) * 6
print(result)


lis = [4, 8, 15, 16, 23, 42]
di = {}
for i in lis:
	di[i] = 0
n = int(input())
l = list(map(int, input().split()))
for i in l:
	if i == 4:
		di[4] += 1
	elif i == 8:
		if di[4] > di[8]:
			di[8] += 1
	elif i == 15:
		if di[8] > di[15]:
			di[15] += 1
	elif i == 16:
		if di[15] > di[16]:
			di[16] += 1
	elif i == 23:
		if di[16] > di[23]:
			di[23] += 1
	elif di[23] > di[42]:
		di[42] += 1
print(n - 6 * di[42])


n = int(input())
li = list(map(int, input().split()))
c = n
a = [0, 0, 0, 0, 0, 0]
b = [4, 8, 15, 16, 23, 42]
br = True
while br:
	for i in range(6):
		if a[i] >= n:
			br = False
			break
		if not br:
			break
		while li[a[i]] != b[i]:
			a[i] += 1
			if a[i] >= n:
				br = False
				break
		if i != 5:
			a[i + 1] = max(a[i], a[i + 1])
		a[i] += 1
	if br:
		c -= 6
print(c)


n = int(input())
al = list(map(int, input().split()))
rl = [4, 8, 15, 16, 23, 42]
cl = [0] * 6
for i in range(n):
	p = rl.index(al[i])
	if p == 0 or cl[p] < cl[p - 1]:
		cl[p] += 1
print(n - cl[-1] * 6)


from collections import Counter
t = int(input())
occurences = Counter()
nums = [4, 8, 15, 16, 23, 42]
array = [int(x) for x in input().split()]
new_array = []
for i in array:
	index = nums.index(i)
	to_add = True
	for j in nums[0:index]:
		if occurences[j] < occurences[i] + 1:
			to_add = False
	if to_add:
		occurences[i] += 1
		new_array.append(i)
new_occurences = Counter()
for i in new_array:
	new_occurences[i] += 1
if len(new_occurences) != len(nums):
	print(len(array))
else:
	min = min(new_occurences.items(), key=lambda x: x[1])[1]
	print(len(array) - min * len(nums))


from math import *
from collections import *
from itertools import *
from functools import *
from random import *

def getl(t=int):
	return [t(x) for x in input().split()]

def get(t=int):
	return t(input())
alphabet = [chr(x) for x in range(ord('a'), ord('z') + 1)]
alnum = lambda x: ord(x) - ord('a')
seq = [4, 8, 15, 16, 23, 42]

def main():
	n = get()
	l = getl()
	m = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
	discard = 0
	for x in l:
		if x not in seq:
			discard += 1
			continue
		d = seq.index(x)
		if d != 0:
			if m[seq[d - 1]] != 0:
				m[x] += 1
				m[seq[d - 1]] -= 1
			else:
				discard += 1
		else:
			m[x] += 1
	for (j, (i, k)) in enumerate(m.items()):
		if i != 42:
			discard += k * (j + 1)
	print(discard)
main()


n = int(input())
a = [int(a) for a in input().split()]
g4 = g8 = g15 = g16 = g23 = g42 = 0
for i in range(n):
	if a[i] == 4:
		g4 += 1
	elif a[i] == 8:
		g8 = min(g4, g8 + 1)
	elif a[i] == 15:
		g15 = min(g8, g15 + 1)
	elif a[i] == 16:
		g16 = min(g15, g16 + 1)
	elif a[i] == 23:
		g23 = min(g16, g23 + 1)
	elif a[i] == 42:
		g42 = min(g23, g42 + 1)
print(n - g42 * 6)


N = int(input())
arr = [int(x) for x in input().split()]
cnt = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
ans = 0
for i in arr:
	if i == 4:
		cnt[i] += 1
	elif i == 8:
		if cnt[i] >= cnt[4]:
			ans += 1
		else:
			cnt[i] += 1
	elif i == 15:
		if cnt[i] >= cnt[8]:
			ans += 1
		else:
			cnt[i] += 1
	elif i == 16:
		if cnt[i] >= cnt[15]:
			ans += 1
		else:
			cnt[i] += 1
	elif i == 23:
		if cnt[i] >= cnt[16]:
			ans += 1
		else:
			cnt[i] += 1
	elif i == 42:
		if cnt[i] >= cnt[23]:
			ans += 1
		else:
			cnt[i] += 1
temp = 0
for i in cnt.values():
	temp += i - cnt[42]
print(ans + temp)


import sys

class CLoseIt:

	def solve(self):
		elements = [4, 8, 15, 16, 23, 42]
		n = int(input())
		a = [int(item) for item in input().split()]
		cnt = {x: [] for x in elements}
		for i in range(n):
			cnt[a[i]] += [i]
		ans = 0
		if len(cnt[4]) == 0:
			print(n)
			return
		available = {x: 0 for x in elements}
		ids = {x: elements.index(x) for x in elements}
		to = {x: 0 for x in elements}
		for i in range(n):
			if a[i] == 4 or available[elements[ids[a[i]] - 1]]:
				available[a[i]] += 1
				if a[i] != 4:
					available[elements[ids[a[i]] - 1]] -= 1
		print(n - available[42] * 6)
solver = CLoseIt()
input = sys.stdin.readline
solver.solve()


d = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
n = int(input())
arr = [d[int(ele)] for ele in input().split()]
freq = [0] * 6
for ele in arr:
	if ele == 0:
		freq[ele] += 1
	elif freq[ele - 1]:
		freq[ele - 1] -= 1
		freq[ele] += 1
print(n - freq[-1] * 6)


nTest = 1
m = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}

def solution(l):
	N = len(l)
	dp = [0, 0, 0, 0, 0, 0]
	for n in l:
		cur = m[n]
		if cur == 0:
			dp[cur] += 1
		elif dp[cur - 1] != 0:
			dp[cur] += 1
			dp[cur - 1] -= 1
	return N - dp[5] * 6
for i in range(nTest):
	n = int(input())
	print(solution(list(map(int, input().split()))))


def main():
	n = int(input())
	a = [int(i) for i in input().split()]
	used = [0 for i in range(n)]
	sh = [4, 8, 15, 16, 23, 42]
	time = 0
	arr = [0 for i in range(6)]
	for i in range(n):
		if a[i] == sh[0]:
			arr[0] += 1
		elif a[i] == sh[1]:
			if arr[0] > 0:
				arr[0] -= 1
				arr[1] += 1
		elif a[i] == sh[2]:
			if arr[1] > 0:
				arr[1] -= 1
				arr[2] += 1
		elif a[i] == sh[3]:
			if arr[2] > 0:
				arr[2] -= 1
				arr[3] += 1
		elif a[i] == sh[4]:
			if arr[3] > 0:
				arr[3] -= 1
				arr[4] += 1
		elif a[i] == sh[5]:
			if arr[4] > 0:
				arr[4] -= 1
				arr[5] += 1
	print(n - arr[-1] * 6)
main()


n = int(input())
t = list(map(int, input().split()))
wyn = 0
el_4 = []
el_8 = []
el_15 = []
el_16 = []
el_23 = []
el_42 = []
ind_el_4 = 0
ind_el_8 = 0
ind_el_15 = 0
ind_el_16 = 0
ind_el_23 = 0
ind_el_42 = 0
curr_el = 0
for x in range(0, len(t), +1):
	if t[x] == 4:
		el_4.append(x)
	elif t[x] == 8:
		el_8.append(x)
	elif t[x] == 15:
		el_15.append(x)
	elif t[x] == 16:
		el_16.append(x)
	elif t[x] == 23:
		el_23.append(x)
	elif t[x] == 42:
		el_42.append(x)
el_4.append(999999999999)
el_8.append(999999999999)
el_15.append(999999999999)
el_16.append(999999999999)
el_23.append(999999999999)
el_42.append(999999999999)
el_4 = list(reversed(el_4))
el_8 = list(reversed(el_8))
el_15 = list(reversed(el_15))
el_16 = list(reversed(el_16))
el_23 = list(reversed(el_23))
el_42 = list(reversed(el_42))
if el_4[-1] == 999999999999 or el_8[-1] == 999999999999 or el_15[-1] == 999999999999 or (el_16[-1] == 999999999999) or (el_23[-1] == 999999999999) or (el_42[-1] == 999999999999):
	print(len(t))
	exit()
while True:
	curr_el = el_4[-1]
	if curr_el == 999999999999:
		break
	to_pop_8 = 1
	to_pop_15 = 1
	to_pop_16 = 1
	to_pop_23 = 1
	to_pop_42 = 1
	for x in range(len(el_8) - 1, -1, -1):
		if el_8[x] < curr_el:
			to_pop_8 += 1
			wyn += 1
		else:
			curr_el = el_8[x]
			break
	if curr_el == 999999999999:
		wyn -= len(el_8) - 1
		break
	for x in range(len(el_15) - 1, -1, -1):
		if el_15[x] < curr_el:
			to_pop_15 += 1
			wyn += 1
		else:
			curr_el = el_15[x]
			break
	if curr_el == 999999999999:
		wyn -= len(el_15) - 1
		break
	for x in range(len(el_16) - 1, -1, -1):
		if el_16[x] < curr_el:
			to_pop_16 += 1
			wyn += 1
		else:
			curr_el = el_16[x]
			break
	if curr_el == 999999999999:
		wyn -= len(el_16) - 1
		break
	for x in range(len(el_23) - 1, -1, -1):
		if el_23[x] < curr_el:
			to_pop_23 += 1
			wyn += 1
		else:
			curr_el = el_23[x]
			break
	if curr_el == 999999999999:
		wyn -= len(el_23) - 1
		break
	for x in range(len(el_42) - 1, -1, -1):
		if el_42[x] < curr_el:
			to_pop_42 += 1
			wyn += 1
		else:
			curr_el = el_42[x]
			break
	if curr_el == 999999999999:
		wyn -= len(el_42) - 1
		break
	el_4.pop()
	for x in range(to_pop_8):
		el_8.pop()
	for x in range(to_pop_15):
		el_15.pop()
	for x in range(to_pop_16):
		el_16.pop()
	for x in range(to_pop_23):
		el_23.pop()
	for x in range(to_pop_42):
		el_42.pop()
print(wyn + (len(el_4) - 1) + (len(el_8) - 1) + (len(el_15) - 1) + (len(el_23) - 1) + (len(el_42) - 1) + (len(el_16) - 1))


n = int(input())
l = list(map(int, input().split()))
x = [4, 8, 15, 16, 23, 42]
d = {}
for i in x:
	d[i] = 0
count = 0
for i in range(n):
	if l[i] == 4:
		d[4] += 1
	elif l[i] == 8:
		if d[4] == 0:
			count += 1
		else:
			d[4] -= 1
			d[8] += 1
	elif l[i] == 15:
		if d[8] == 0:
			count += 1
		else:
			d[8] -= 1
			d[15] += 1
	elif l[i] == 16:
		if d[15] == 0:
			count += 1
		else:
			d[15] -= 1
			d[16] += 1
	elif l[i] == 23:
		if d[16] == 0:
			count += 1
		else:
			d[16] -= 1
			d[23] += 1
	elif d[23] == 0:
		count += 1
	else:
		d[23] -= 1
		d[42] += 1
count += d[4] + 2 * d[8] + 3 * d[15] + 4 * d[16] + 5 * d[23]
print(count)


import sys
n = int(input())
l = list(map(int, input().split()))
val = [4, 8, 15, 16, 23, 42]
count = [0] * 6
p = [-1] * 6
wyn = 0
while True:
	for k in range(5):
		p[k] += 1
		while True:
			if p[k] == n:
				print(n - wyn * 6)
				sys.exit(0)
			if l[p[k]] != val[k]:
				p[k] += 1
			else:
				break
		p[k + 1] = max(p[k + 1], p[k])
	p[5] += 1
	while True:
		if p[5] == n:
			print(n - wyn * 6)
			sys.exit(0)
		if l[p[5]] != val[5]:
			p[5] += 1
		else:
			break
	wyn += 1


n = int(input())
ns = [int(i) for i in input().split()]
ans = [0] * 6
d = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
for c in ns:
	c = d[c]
	if c == 0:
		ans[0] += 1
	elif ans[c - 1] > 0:
		ans[c - 1] -= 1
		ans[c] += 1
print(n - 6 * ans[-1])


import sys
input = sys.stdin.readline
n = int(input())
a = [int(x) for x in input().strip().split()]
s = [0] * 6
req = [4, 8, 15, 16, 23, 42]
for elem in a:
	i = req.index(elem)
	if i == 0:
		s[i] += 1
	if s[i - 1] > s[i]:
		s[i] += 1
print(n - s[-1] * 6)


import collections
NUMS = [4, 8, 15, 16, 23, 42]
n = int(input())
a = [int(s) for s in input().split()]
pos = {x: 0 for x in NUMS}
indices = collections.defaultdict(list)
for (i, x) in enumerate(a):
	indices[x].append(i)
res = 0
done = False
while not done and all((pos[x] < len(indices[x]) for x in NUMS)):
	prev = -1
	for x in NUMS:
		while indices[x][pos[x]] <= prev:
			pos[x] += 1
			if pos[x] == len(indices[x]):
				done = True
				break
		else:
			prev = indices[x][pos[x]]
	if not done:
		res += 1
		for x in NUMS:
			pos[x] += 1
print(len(a) - 6 * res)


n = int(input())
v = list(map(int, input().split()))
d = {y: x for (x, y) in enumerate([4, 8, 15, 16, 23, 42], 1)}
seq = {x: 0 for x in range(1, 7)}
ans = 0
for i in v:
	if i == 4:
		seq[d[i]] = seq[d[i]] + 1
		continue
	if seq[d[i] - 1] <= 0:
		continue
	seq[d[i]] = seq[d[i]] + 1
	seq[d[i] - 1] = seq[d[i] - 1] - 1
print(n - seq[6] * 6)


n = int(input())
s = input()
arr = s.split(' ')
for i in range(n):
	arr[i] = int(arr[i])
arr4 = []
arr8 = []
arr15 = []
arr16 = []
arr23 = []
arr42 = []
maxm = 0
ans = 0
temp = n // 6
for i in range(n):
	if arr[i] == 4:
		if len(arr4) + 1 > temp:
			ans = ans + 1
		else:
			arr4.append(arr[i])
	if arr[i] == 8:
		if len(arr8) + 1 > temp:
			ans = ans + 1
		elif len(arr8) + 1 <= len(arr4):
			arr8.append(8)
		else:
			ans = ans + 1
	if arr[i] == 15:
		if len(arr15) + 1 > temp:
			ans = ans + 1
		elif len(arr15) + 1 <= len(arr8) and len(arr15) + 1 <= len(arr4):
			arr15.append(15)
		else:
			ans = ans + 1
	if arr[i] == 16:
		if len(arr16) + 1 > temp:
			ans = ans + 1
		elif len(arr16) + 1 <= len(arr15) and len(arr16) + 1 <= len(arr8) and (len(arr16) + 1 <= len(arr4)):
			arr16.append(16)
		else:
			ans = ans + 1
	if arr[i] == 23:
		if len(arr23) + 1 > temp:
			ans = ans + 1
		elif len(arr23) + 1 <= len(arr16) and len(arr23) + 1 <= len(arr15) and (len(arr23) + 1 <= len(arr8)) and (len(arr23) + 1 <= len(arr4)):
			arr23.append(23)
		else:
			ans = ans + 1
	if arr[i] == 42:
		if len(arr42) + 1 > temp:
			ans = ans + 1
		elif len(arr42) + 1 <= len(arr23) and len(arr42) + 1 <= len(arr16) and (len(arr42) + 1 <= len(arr15)) and (len(arr42) + 1 <= len(arr8)) and (len(arr42) + 1 <= len(arr4)):
			arr42.append(42)
		else:
			ans = ans + 1
minm = n
if len(arr4) < minm:
	minm = len(arr4)
if len(arr8) < minm:
	minm = len(arr8)
if len(arr15) < minm:
	minm = len(arr15)
if len(arr16) < minm:
	minm = len(arr16)
if len(arr23) < minm:
	minm = len(arr23)
if len(arr42) < minm:
	minm = len(arr42)
ans = ans + (len(arr4) - minm) + (len(arr8) - minm) + (len(arr15) - minm) + (len(arr16) - minm) + (len(arr23) - minm) + (len(arr42) - minm)
print(ans)


from collections import Counter
n = int(input().strip())
nums = list(map(int, input().strip().split()))
res = 0
state = []
counter = Counter()
prev = {8: 4, 15: 8, 16: 15, 23: 16, 42: 23}
good_nums = [4, 8, 15, 16, 23, 42]
for (i, num) in enumerate(nums):
	if num == 4:
		counter[num] += 1
	elif counter[num] < counter[prev[num]]:
		counter[num] += 1
		if num == 42:
			for good_num in good_nums:
				counter[good_num] -= 1
	else:
		res += 1
res += sum(counter.values())
print(res)


n = int(input())
l1 = list(map(int, input().split()))
x = [4, 8, 15, 16, 23, 42]
count = [0] * 6
for item in l1:
	if item == 4:
		count[0] += 1
	elif item == 8:
		if count[0] > count[1]:
			count[1] += 1
	elif item == 15:
		if count[1] > count[2]:
			count[2] += 1
	elif item == 16:
		if count[2] > count[3]:
			count[3] += 1
	elif item == 23:
		if count[3] > count[4]:
			count[4] += 1
	elif item == 42:
		if count[4] > count[5]:
			count[5] += 1
print(n - 6 * count[5])


import random
import math
from collections import defaultdict
import itertools
from sys import stdin, stdout
import sys
import operator

def main():
	z = ''
	d = defaultdict()
	t = 1
	n = int(input())
	a = list(map(int, input().split()))
	z = [0] * 6
	for i in range(n):
		if a[i] == 4:
			z[0] += 1
		elif a[i] == 8:
			if z[0] > z[1]:
				z[1] += 1
		elif a[i] == 15:
			if z[1] > z[2]:
				z[2] += 1
		elif a[i] == 16:
			if z[2] > z[3]:
				z[3] += 1
		elif a[i] == 23:
			if z[3] > z[4]:
				z[4] += 1
		elif z[4] > z[5]:
			z[5] += 1
	print(n - z[5] * 6)
main()


n = int(input())
ar = list(map(int, input().split()))
[count1, count2, count3, count4, count5, count6] = [0, 0, 0, 0, 0, 0]
for num in ar:
	if num == 4:
		count1 += 1
	elif num == 8 and count1 > 0:
		count1 -= 1
		count2 += 1
	elif num == 15 and count2 > 0:
		count2 -= 1
		count3 += 1
	elif num == 16 and count3 > 0:
		count3 -= 1
		count4 += 1
	elif num == 23 and count4 > 0:
		count4 -= 1
		count5 += 1
	elif num == 42 and count5 > 0:
		count5 -= 1
		count6 += 1
print(len(ar) - count6 * 6)


numOfEl = int(input())
arr = list(map(int, input().split()))
form = [0] * 45
for x in arr:
	if x == 4:
		form[4] += 1
	elif x == 8:
		if form[4] > form[8]:
			form[8] += 1
	elif x == 15:
		if form[8] > form[15]:
			form[15] += 1
	elif x == 16:
		if form[15] > form[16]:
			form[16] += 1
	elif x == 23:
		if form[16] > form[23]:
			form[23] += 1
	elif x == 42:
		if form[23] > form[42]:
			form[42] += 1
good = min(form[4], form[8], form[15], form[16], form[23], form[42])
if good == 0:
	print(numOfEl)
else:
	print(numOfEl - good * 6)


n = int(input())
b = [int(ai) for ai in input().split()]
a = [4, 8, 15, 16, 23, 42]
d = dict()
ind = 0
for ind in range(0, 6):
	d[a[ind]] = ind
L = [[], [], [], [], [], []]
for i in range(0, n):
	L[int(d[b[i]])].append(i)
prev = [0, 0, 0, 0, 0, 0]
ans = 0
flag = 1
while flag:
	for i in range(0, 6):
		if i > 0:
			while prev[i] < len(L[i]) and L[i][prev[i]] < L[i - 1][prev[i - 1] - 1]:
				prev[i] += 1
		if prev[i] >= len(L[i]):
			flag = 0
			break
		prev[i] += 1
		if i == 5:
			ans += 6
print(n - ans)


import collections
n = int(input())
arr = [int(x) for x in input().split(' ')]
mm = {}
for val in arr:
	if val == 4:
		mm[val] = mm.get(val, 0) + 1
	elif val == 8:
		mm[val] = min(mm.get(4, 0), mm.get(val, 0) + 1)
	elif val == 15:
		mm[val] = min(mm.get(8, 0), mm.get(val, 0) + 1)
	elif val == 16:
		mm[val] = min(mm.get(15, 0), mm.get(val, 0) + 1)
	elif val == 23:
		mm[val] = min(mm.get(16, 0), mm.get(val, 0) + 1)
	elif val == 42:
		mm[val] = min(mm.get(23, 0), mm.get(val, 0) + 1)
print(n - 6 * mm.get(42, 0))


n = int(input())
A = list(map(int, input().split()))
(n1, n2, n3, n4, n5, n6) = (0, 0, 0, 0, 0, 0)
for a in A:
	if a == 4:
		n1 += 1
	elif a == 8 and n1 > n2:
		n2 += 1
	elif a == 15 and n2 > n3:
		n3 += 1
	elif a == 16 and n3 > n4:
		n4 += 1
	elif a == 23 and n4 > n5:
		n5 += 1
	elif a == 42 and n5 > n6:
		n6 += 1
print(n - 6 * n6)


from sys import stdin, stdout
import bisect as bs

def fn(x):
	if x == 4:
		return 0
	if x == 8:
		return 4
	if x == 15:
		return 8
	if x == 16:
		return 15
	if x == 23:
		return 16
	if x == 42:
		return 23

def ind(x):
	if x == 0:
		return 0
	if x == 4:
		return 1
	if x == 8:
		return 2
	if x == 15:
		return 3
	if x == 16:
		return 4
	if x == 23:
		return 5
	if x == 42:
		return 0
for _ in range(1):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	l = [0] * n
	ans = 0
	for v in a:
		search = fn(v)
		pos = bs.bisect_right(l, search) - 1
		if search > l[-1] or l[pos] != search:
			ans += 1
		else:
			l[pos] = v
	for v in l:
		ans += ind(v)
	print(ans)


import sys
n = int(input())
a = list(map(int, input().split()))
index = [4, 8, 15, 16, 23, 42]
count = [0] * 6
numsDeleted = 0
for i in range(n):
	x = a[i]
	p = index.index(x)
	add = True
	j = p - 1
	while j >= 0:
		if count[j] <= count[p]:
			add = False
			break
		j -= 1
	if add:
		count[p] += 1
	else:
		numsDeleted += 1
times = min(count)
for i in range(6):
	numsDeleted += count[i] - times
print(numsDeleted)


n = int(input())
l = [4, 8, 15, 16, 23, 42]
enc = [0] * 7
enc[0] = n
for k in map(lambda j: l.index(int(j)), input().split()):
	if enc[k]:
		enc[k] -= 1
		enc[k + 1] += 1
print(n - 6 * enc[6])


_4 = 0
_8 = 0
_15 = 0
_16 = 0
_23 = 0
_42 = 0
n = int(input())
nums = list(map(int, input().split()))
for i in nums:
	if i == 4:
		_4 += 1
	elif i == 8 and _4 > 0:
		_4 -= 1
		_8 += 1
	elif i == 15 and _8 > 0:
		_8 -= 1
		_15 += 1
	elif i == 16 and _15 > 0:
		_15 -= 1
		_16 += 1
	elif i == 23 and _16 > 0:
		_16 -= 1
		_23 += 1
	elif i == 42 and _23 > 0:
		_23 -= 1
		_42 += 1
print(n - _42 * 6)


n = int(input())
posl = [4, 8, 15, 16, 23, 42]
teck = [0, 0, 0, 0, 0, 0]
remov = 0
a = [int(i) for i in input().split()]
for i in range(n):
	new = a[i]
	if new == posl[0]:
		teck[0] += 1
	else:
		k = posl.index(new)
		if teck[k - 1] != 0:
			teck[k - 1] -= 1
			teck[k] += 1
		else:
			remov += 1
for i in range(5):
	remov += (i + 1) * teck[i]
print(remov)


n = int(input())
arr = list(map(int, input().split()))
if n < 6:
	print(n)
	exit()
else:
	l = [4, 8, 15, 16, 23, 42]
	a1 = 0
	a2 = 0
	a3 = 0
	a4 = 0
	a5 = 0
	a6 = 0
	for i in arr:
		if i == l[0]:
			a1 += 1
		elif i == l[1]:
			a2 = min(a1, a2 + 1)
		elif i == l[2]:
			a3 = min(a2, a3 + 1)
		elif i == l[3]:
			a4 = min(a3, a4 + 1)
		elif i == l[4]:
			a5 = min(a4, a5 + 1)
		elif i == l[5]:
			a6 = min(a5, a6 + 1)
	print(n - a6 * 6)


f = [0] * 6
b = [4, 8, 15, 16, 23, 42]
n = int(input())
for x in map(int, input().split()):
	p = b.index(x)
	if p == 0:
		f[p] += 1
	elif f[p - 1]:
		f[p - 1] -= 1
		f[p] += 1
print(n - f[5] * 6)


n = int(input())
h = 6 * (n // 6)
l = [0] * h
(i4, i8, i15, i16, i23, i42) = (0, 1, 2, 3, 4, 5)
for i in map(int, input().split()):
	if i == 4 and i4 < h:
		l[i4] = 1
		i4 += 6
	if i == 8 and i8 < h and (l[i8 - 1] == 1):
		l[i8] = 1
		i8 += 6
	if i == 15 and i15 < h and (l[i15 - 1] == 1):
		l[i15] = 1
		i15 += 6
	if i == 16 and i16 < h and (l[i16 - 1] == 1):
		l[i16] = 1
		i16 += 6
	if i == 23 and i23 < h and (l[i23 - 1] == 1):
		l[i23] = 1
		i23 += 6
	if i == 42 and i42 < h and (l[i42 - 1] == 1):
		l[i42] = 1
		i42 += 6
count = 0
for i in range(5, len(l), 6):
	if l[i] == 1:
		count += 1
ans = n - 6 * count
print(ans)


n = int(input())
l = list(map(int, input().split()))
ansl = [4, 8, 15, 16, 23, 42]
c4 = 0
c8 = 0
c15 = 0
c16 = 0
c23 = 0
c42 = 0
j = 0
ans = 0
for i in range(n):
	if l[i] == 4:
		c4 += 1
	elif l[i] == 8:
		if c8 < c4:
			c8 += 1
	elif l[i] == 15:
		if c15 < c8:
			c15 += 1
	elif l[i] == 16:
		if c16 < c15:
			c16 += 1
	elif l[i] == 23:
		if c23 < c16:
			c23 += 1
	elif l[i] == 42:
		if c42 < c23:
			c42 += 1
ans = n - c42 * 6
print(ans)


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def min(a, b):
	if a < b:
		return a
	else:
		return b

def max(a, b):
	if a > b:
		return a
	else:
		return b
n = int(input())
m = list(map(int, input().split()))
min = 1000000
lost = [4, 8, 15, 16, 23, 42]
cnt = [0] * 6
for x in m:
	if x == 4:
		cnt[0] += 1
	elif (x == 8) & (cnt[1] < cnt[0]):
		cnt[1] += 1
	elif (x == 15) & (cnt[2] < cnt[1]):
		cnt[2] += 1
	elif (x == 16) & (cnt[3] < cnt[2]):
		cnt[3] += 1
	elif (x == 23) & (cnt[4] < cnt[3]):
		cnt[4] += 1
	elif (x == 42) & (cnt[5] < cnt[4]):
		cnt[5] += 1
print(n - 6 * cnt[5])


for _ in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	b = [4, 8, 15, 16, 23, 42]
	c = [0] * 50
	for i in a:
		if i == 4:
			c[i] += 1
		elif c[b[b.index(i) - 1]] > 0:
			c[b[b.index(i) - 1]] -= 1
			c[i] += 1
	print(n - c[42] * 6)


number_input = int(input())
a = list(map(int, input().split()))
(number_array, digit) = ([4, 8, 15, 16, 23, 42], [number_input, 0, 0, 0, 0, 0, 0])
for element in a:
	if element in number_array:
		j = number_array.index(element) + 1
		if digit[j - 1] != 0:
			digit[j] += 1
			digit[j - 1] -= 1
result = number_input - digit[6] * 6
print(result)


num_de_elementos = int(input())
elementos = list(map(int, input().split()))
dicionario = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
aux = []
for x in elementos:
	aux.append(dicionario.get(x))
pares = [0] * 6
for i in aux:
	if i == 0:
		pares[i] += 1
	elif pares[i - 1] > 0:
		pares[i - 1] -= 1
		pares[i] += 1
print(num_de_elementos - pares[5] * 6)


n = int(input())
a = [int(x) for x in input().split()]
counter = [0] * 6
for item in a:
	if item == 4:
		counter[0] += 1
	elif item == 8:
		if counter[0] > 0:
			counter[0] -= 1
			counter[1] += 1
	elif item == 15:
		if counter[1] > 0:
			counter[1] -= 1
			counter[2] += 1
	elif item == 16:
		if counter[2] > 0:
			counter[2] -= 1
			counter[3] += 1
	elif item == 23:
		if counter[3] > 0:
			counter[3] -= 1
			counter[4] += 1
	elif counter[4] > 0:
		counter[4] -= 1
		counter[5] += 1
print(n - counter[5] * 6)


n = int(input())
a = list(map(int, input().split()))
k = 0
posl = [0] * 6
for i in a:
	if i == 4:
		posl[0] += 1
	elif i == 8:
		if posl[0] > 0:
			posl[1] += 1
			posl[0] -= 1
		else:
			k += 1
	elif i == 15:
		if posl[1] > 0:
			posl[2] += 1
			posl[1] -= 1
		else:
			k += 1
	elif i == 16:
		if posl[2] > 0:
			posl[3] += 1
			posl[2] -= 1
		else:
			k += 1
	elif i == 23:
		if posl[3] > 0:
			posl[4] += 1
			posl[3] -= 1
		else:
			k += 1
	elif i == 42:
		if posl[4] > 0:
			posl[5] += 1
			posl[4] -= 1
		else:
			k += 1
for i in range(1, 6):
	k += posl[i - 1] * i
print(k)


l = int(input())
a = [int(x) for x in input().split(' ')]
b = [4, 8, 15, 16, 23, 42]
c = [0, 0, 0, 0, 0, 0]
t = 0
for i in a:
	if i in b:
		j = b.index(i)
		if j == 0:
			c[j] += 1
		elif c[j - 1] > c[j]:
			c[j] += 1
		else:
			t += 1
print(t + sum(c) - 6 * min(c))


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
x = [4, 8, 15, 16, 23, 42]
d = defaultdict(list)
for i in range(n):
	d[a[i]].append(i)
p = [0] * 6
f = 1
ans = 0
while f:
	for i in range(1, 6):
		if p[i] != len(d[x[i]]) and p[i - 1] != len(d[x[i - 1]]):
			while d[x[i]][p[i]] < d[x[i - 1]][p[i - 1]]:
				p[i] = p[i] + 1
				if p[i] == len(d[x[i]]):
					f = 0
					break
		else:
			f = 0
			break
	if f:
		for i in range(6):
			p[i] = p[i] + 1
		ans = ans + 1
print(n - ans * 6)


from collections import defaultdict
n = int(input())
l = list(map(int, input().split()))
index = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
di = [0 for i in range(6)]
count = 0
for i in l:
	val = index[i]
	if val == 0:
		di[0] += 1
	elif di[val - 1] > 0:
		di[val - 1] -= 1
		di[val] += 1
	else:
		count += 1
for i in range(5):
	count += di[i] * (i + 1)
print(count)


n = int(input())
a = list(map(int, input().split()))
seq = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
count = [0 for i in range(6)]
for i in a:
	if i == 4:
		count[seq[i]] += 1
		continue
	if count[seq[i]] < count[seq[i] - 1]:
		count[seq[i]] += 1
print(n - 6 * count[-1])


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

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

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	maxint = 10 ** 10
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def solve():
	count = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
	n = int(input())
	arr = list_input()
	for i in arr:
		if i == 4:
			count[4] += 1
		elif i == 8:
			if count[4] > 0:
				count[4] -= 1
				count[8] += 1
		elif i == 15:
			if count[8] > 0:
				count[8] -= 1
				count[15] += 1
		elif i == 16:
			if count[15] > 0:
				count[15] -= 1
				count[16] += 1
		elif i == 23:
			if count[16] > 0:
				count[16] -= 1
				count[23] += 1
		elif count[23] > 0:
			count[23] -= 1
			count[42] += 1
	print(n - 6 * count[42])
t = 1
for _ in range(t):
	solve()


from sys import stdin, stdout
a = int(stdin.readline())
b = [[], [], [], [], [], []]
for (i, j) in zip(stdin.readline().split(), range(a)):
	if i == '4':
		b[0] += [j]
	elif i == '8':
		b[1] += [j]
	elif i == '15':
		b[2] += [j]
	elif i == '16':
		b[3] += [j]
	elif i == '23':
		b[4] += [j]
	else:
		b[5] += [j]
for i in range(6):
	b[i] += '.'
s = 0
(i0, i1, i2, i3, i4, i5) = (0, 0, 0, 0, 0, 0)
for i in range(min(a // 6, len(b[0]))):
	p = 1
	j = b[0][i]
	while b[1][i1] != '.' and j > b[1][i1]:
		i1 += 1
	if b[1][i1] != '.':
		j = b[1][i1]
		i1 += 1
	else:
		p = 0
	while b[2][i2] != '.' and j > b[2][i2]:
		i2 += 1
	if b[2][i2] != '.':
		j = b[2][i2]
		i2 += 1
	else:
		p = 0
	while b[3][i3] != '.' and j > b[3][i3]:
		i3 += 1
	if b[3][i3] != '.':
		j = b[3][i3]
		i3 += 1
	else:
		p = 0
	while b[4][i4] != '.' and j > b[4][i4]:
		i4 += 1
	if b[4][i4] != '.':
		j = b[4][i4]
		i4 += 1
	else:
		p = 0
	while b[5][i5] != '.' and j > b[5][i5]:
		i5 += 1
	if b[5][i5] != '.':
		j = b[5][i5]
		i5 += 1
	else:
		p = 0
	if p:
		s += 6
stdout.write(str(a - s))


def solve(arr):
	M = {8: 4, 15: 8, 16: 15, 23: 16, 42: 23}
	res = 0
	D = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
	for c in arr:
		if c == 4:
			D[4] += 1
			continue
		if D[M[c]]:
			D[M[c]] -= 1
			D[c] += 1
		else:
			res += 1
	return res + D[4] * 1 + D[8] * 2 + D[15] * 3 + D[16] * 4 + D[23] * 5
input()
print(solve([*map(int, input().split(' '))]))


n = int(input())
l = list(map(int, input().split()))
d = [0] * 7
ans = 0
for i in range(n):
	if l[i] == 4:
		d[1] += 1
	elif l[i] == 8 and d[1] > d[2]:
		d[2] += 1
	elif l[i] == 15 and d[2] > d[3]:
		d[3] += 1
	elif l[i] == 16 and d[3] > d[4]:
		d[4] += 1
	elif l[i] == 23 and d[4] > d[5]:
		d[5] += 1
	elif l[i] == 42 and d[5] > d[6]:
		d[6] += 1
	else:
		ans += 1
for i in range(1, 6):
	ans += d[i] - d[6]
print(ans)


n = int(input())
A = [*map(int, input().split())]
R = {8: 4, 15: 8, 16: 15, 23: 16, 42: 23}
P = {4: [], 8: [], 15: [], 16: [], 23: [], 42: []}
ans = 0
for (i, a) in enumerate(A):
	if a == 4:
		P[4].append(a)
	elif a in R and R[a] in P:
		prev = R[a]
		if len(P[prev]) > 0:
			P[prev].pop()
			P[a].append(a)
		else:
			ans += 1
	else:
		ans += 1
for (i, n) in enumerate([4, 8, 15, 16, 23]):
	if len(P[n]) > 0:
		ans += len(P[n]) * (i + 1)
print(ans)


n = int(input(''))
a = list(map(int, input().split()))
r = [0, 0, 0, 0, 0, 0]
ans = 0
cnt = 0
b = [[], [], [], [], [], []]
if n < 6:
	print(n)
	exit()
for i in range(n):
	if a[i] == 4:
		b[0].append(i)
	elif a[i] == 8:
		b[1].append(i)
	elif a[i] == 15:
		b[2].append(i)
	elif a[i] == 16:
		b[3].append(i)
	elif a[i] == 23:
		b[4].append(i)
	elif a[i] == 42:
		b[5].append(i)
for i in range(len(b[0])):
	if ans != 0:
		break
	c = b[0][i]
	for j in range(1, 6):
		l = len(b[j])
		if ans == -1:
			break
		if r[j] == l:
			ans = 1
			break
		for k in range(l):
			if b[j][r[j]] > c:
				c = b[j][r[j]]
				r[j] += 1
				break
			else:
				r[j] += 1
				if len(b[j]) == r[j]:
					ans = -1
					break
		if j == 5 and ans == 0:
			cnt += 1
print(n - 6 * cnt)


a = int(input())
b = list(map(int, input().split()))
h = []
(p, q, r, s, t, u) = (0, 0, 0, 0, 0, 0)
for elelm in b:
	if elelm == 4:
		h.append([4])
		p += 1
	elif elelm == 8 and q < p:
		h[q].append(8)
		q += 1
	elif elelm == 15 and r < q:
		h[r].append(15)
		r += 1
	elif elelm == 16 and s < r:
		h[s].append(16)
		s += 1
	elif elelm == 23 and t < s:
		h[t].append(23)
		t += 1
	elif elelm == 42 and u < t:
		h[u].append(42)
		u += 1
if u == 0:
	print(a)
else:
	print(a - 6 * u)


n = int(input())
a = list(map(int, input().split()))
dp = [0, 0, 0, 0, 0, 0]
for k in range(n):
	if a[k] == 4:
		dp[0] += 1
	elif a[k] == 8:
		dp[1] = min(dp[0], dp[1] + 1)
	elif a[k] == 15:
		dp[2] = min(dp[1], dp[2] + 1)
	elif a[k] == 16:
		dp[3] = min(dp[2], dp[3] + 1)
	elif a[k] == 23:
		dp[4] = min(dp[3], dp[4] + 1)
	else:
		dp[5] = min(dp[4], dp[5] + 1)
print(n - 6 * dp[5])


input()
num = [4, 8, 15, 16, 23, 42]
prev = {i: j for (i, j) in zip(num[1:], num)}
c = {v: 0 for v in num}
n = 0
for a in map(int, input().split()):
	if a == num[0]:
		c[a] += 1
	elif c[prev[a]]:
		c[prev[a]] -= 1
		if a != num[-1]:
			c[a] += 1
	else:
		n += 1
for (i, v) in enumerate(num):
	n += (i + 1) * c[v]
print(n)


d = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
n = int(input())
c = 0
arr = list(map(int, input().split()))
count = [0, 0, 0, 0, 0, 0]
for i in arr:
	ele = i
	count[d[ele]] += 1
	flag = 0
	for j in range(1, 6):
		if count[j - 1] >= count[j]:
			pass
		else:
			flag = 1
			break
	if flag == 1:
		c += 1
		count[d[ele]] -= 1
for i in count:
	c += i - count[-1]
print(c)


n = eval(input())
str = input()
l = str.split()
cl = []
(a, b, c, d, e, f) = ('4', '8', '15', '16', '23', '42')
(p, q, r, s, t, u) = (0, 0, 0, 0, 0, 0)
sum = 0
for x in range(len(l)):
	if l[x] == a:
		cl.append([a])
	elif l[x] == b:
		if p < len(cl) and cl[p] == [a]:
			cl[p].append(b)
			p += 1
		else:
			sum += 1
	elif l[x] == c:
		if q < len(cl) and cl[q] == [a, b]:
			cl[q].append(c)
			q += 1
		else:
			sum += 1
	elif l[x] == d:
		if r < len(cl) and cl[r] == [a, b, c]:
			cl[r].append(d)
			r += 1
		else:
			sum += 1
	elif l[x] == e:
		if s < len(cl) and cl[s] == [a, b, c, d]:
			cl[s].append(e)
			s += 1
		else:
			sum += 1
	elif l[x] == f:
		if t < len(cl) and cl[t] == [a, b, c, d, e]:
			cl[t].append(f)
			t += 1
		else:
			sum += 1
	else:
		sum += 1
for x in range(len(cl)):
	if cl[x] != [a, b, c, d, e, f]:
		sum += len(cl[x])
print(sum)


n = int(input())
a = [int(x) for x in input().split()]
count = 0
w = [0, 0, 0, 0, 0]
for i in range(n):
	if a[i] == 4:
		w[0] = w[0] + 1
	elif a[i] == 8 and w[0] > 0:
		w[0] = w[0] - 1
		w[1] = w[1] + 1
	elif a[i] == 15 and w[1] > 0:
		w[1] = w[1] - 1
		w[2] = w[2] + 1
	elif a[i] == 16 and w[2] > 0:
		w[2] = w[2] - 1
		w[3] = w[3] + 1
	elif a[i] == 23 and w[3] > 0:
		w[3] = w[3] - 1
		w[4] = w[4] + 1
	elif a[i] == 42 and w[4] > 0:
		w[4] = w[4] - 1
		count = count + 1
print(len(a) - 6 * count)


def solve(length, subseq, remove):
	if subseq[length] > 0:
		subseq[length] -= 1
		subseq[length + 1] += 1
	else:
		remove += 1
	return remove
n = int(input())
subseq = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0}
remove = 0
array = list(map(int, input().split()))
for elem in array:
	if elem == 4:
		subseq[1] += 1
	elif elem == 8:
		remove = solve(1, subseq, remove)
	elif elem == 15:
		remove = solve(2, subseq, remove)
	elif elem == 16:
		remove = solve(3, subseq, remove)
	elif elem == 23:
		remove = solve(4, subseq, remove)
	elif elem == 42:
		remove = solve(5, subseq, remove)
for k in subseq:
	if k != 6:
		remove += k * subseq[k]
print(remove)


n = int(input())
lst = list(map(int, input().strip().split(' ')))
if n < 6:
	print(n)
else:
	c = [0] * (n // 6)
	k1 = n // 6
	k = 0
	(i1, i2, i3, i4, i5, i6) = (0, 0, 0, 0, 0, 0)
	for j in range(n):
		if lst[j] == 4:
			if i1 < k1 and c[i1] == 0:
				c[i1] = 4
				i1 += 1
			else:
				k += 1
		elif lst[j] == 8:
			if i2 < k1 and c[i2] == 4:
				c[i2] = 8
				i2 += 1
			else:
				k += 1
		elif lst[j] == 15:
			if i3 < k1 and c[i3] == 8:
				c[i3] = 15
				i3 += 1
			else:
				k += 1
		elif lst[j] == 16:
			if i4 < k1 and c[i4] == 15:
				c[i4] = 16
				i4 += 1
			else:
				k += 1
		elif lst[j] == 23:
			if i5 < k1 and c[i5] == 16:
				c[i5] = 23
				i5 += 1
			else:
				k += 1
		elif lst[j] == 42:
			if i6 < k1 and c[i6] == 23:
				c[i6] = 42
				i6 += 1
			else:
				k += 1
	for j in range(k1):
		if c[j] == 42:
			continue
		elif c[j] == 4:
			k += 1
		elif c[j] == 8:
			k += 2
		elif c[j] == 15:
			k += 3
		elif c[j] == 16:
			k += 4
		elif c[j] == 23:
			k += 5
	print(k)


from collections import defaultdict
from sys import stdin

def solve():
	stdin.readline().strip()
	a = [int(i) for i in stdin.readline().strip().split()]
	nums = [4, 8, 15, 16, 23, 42]
	previous = {4: None, 8: 4, 15: 8, 16: 15, 23: 16, 42: 23}
	sizes = {4: 1, 8: 2, 15: 3, 16: 4, 23: 5, 42: 0}
	counts = defaultdict(int)
	cost = 0
	for e in a:
		if e not in previous:
			cost += 1
		else:
			p = previous.get(e)
			if e == 4:
				counts[e] += 1
			elif counts[p]:
				counts[p] -= 1
				counts[e] += 1
			else:
				cost += 1
	for n in nums:
		cost += counts[n] * sizes[n]
	print(cost)
solve()


import math
import collections
import bisect

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

def cstr():
	return list(map(str, input().split(' ')))

def solve():
	n = int(input())
	lst = cint()
	stk = [[] for i in range(6)]
	for i in range(n):
		if lst[i] == 4:
			stk[0].append(i)
		elif lst[i] == 8 and len(stk[0]) > len(stk[1]):
			stk[1].append(i)
		elif lst[i] == 15:
			isempty = 0
			for j in range(2):
				if len(stk[j]) <= len(stk[2]):
					isempty = 1
					break
			if isempty == 0:
				stk[2].append(i)
		elif lst[i] == 16:
			isempty = 0
			for j in range(3):
				if len(stk[j]) <= len(stk[3]):
					isempty = 1
					break
			if isempty == 0:
				stk[3].append(i)
		elif lst[i] == 23:
			isempty = 0
			for j in range(4):
				if len(stk[j]) <= len(stk[4]):
					isempty = 1
					break
			if isempty == 0:
				stk[4].append(i)
		elif lst[i] == 42:
			isempty = 0
			for j in range(5):
				if len(stk[j]) <= len(stk[5]):
					isempty = 1
					break
			if isempty == 0:
				stk[5].append(i)
	minlst = []
	for s in stk:
		minlst.append(len(s))
	print(n - 6 * min(minlst))
t = 1
while t != 0:
	solve()
	t -= 1


n = int(input())
m = list(map(int, input().split()))
k = [4, 8, 15, 16, 23, 42]
c = [0] * 6
for i in range(n):
	d = n
	for j in range(6):
		if m[i] == k[j]:
			if c[j] < d:
				c[j] += 1
			break
		d = min(d, c[j])
print(n - min(c) * 6)


C = [4, 8, 15, 16, 23, 42]
n = int(input())
s = [n] + [0] * 6
for i in input().split():
	k = C.index(int(i))
	s[k + 1] += s[k + 1] < s[k]
print(n - min(s[1:]) * 6)


n = int(input())
A = list(map(int, input().split()))
nb = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
count = [0 for _ in range(6)]
for ai in A:
	if nb[ai] == 0:
		count[0] += 1
	elif count[nb[ai] - 1] > count[nb[ai]]:
		count[nb[ai]] += 1
	else:
		pass
print(n - min(count) * 6 if n >= 6 else n)


dummy = [4, 8, 15, 16, 42, 23]
n = int(input())
l = [int(i) for i in input().split()]
from collections import Counter
c = Counter(l)
m = 10 ** 9
a1 = 0
a2 = 0
a3 = 0
a4 = 0
a5 = 0
a6 = 0
for i in l:
	if i == 4:
		a1 += 1
	if i == 8:
		a2 = min(a1, a2 + 1)
	if i == 15:
		a3 = min(a2, a3 + 1)
	if i == 16:
		a4 = min(a3, a4 + 1)
	if i == 23:
		a5 = min(a4, a5 + 1)
	if i == 42:
		a6 = min(a5, a6 + 1)
print(n - a6 * 6)


n = int(input())
l = list(map(int, input().split()))

def cnt(l):
	l1 = []
	c1 = 0
	c2 = 0
	c3 = 0
	c4 = 0
	c5 = 0
	c6 = 0
	for i in range(len(l)):
		if l[i] == 4:
			c1 += 1
		elif l[i] == 8 and c2 < c1:
			c2 += 1
		elif (l[i] == 15 and c3 < c2) and c3 < c1:
			c3 += 1
		elif (l[i] == 16 and c4 < c3) and (c4 < c2 and c4 < c1):
			c4 += 1
		elif ((l[i] == 23 and c5 < c4) and (c5 < c3 and c5 < c2)) and c5 < c1:
			c5 += 1
		elif ((l[i] == 42 and c6 < c5) and (c6 < c4 and c6 < c3)) and (c6 < c2 and c6 < c1):
			c6 += 1
	l1.append(c1)
	l1.append(c2)
	l1.append(c3)
	l1.append(c4)
	l1.append(c5)
	l1.append(c6)
	return l1
l2 = cnt(l)
print(n - 6 * min(l2))


n = int(input())
arr = list(map(int, input().split()))
ans = 0
counter = [0] * 6
d = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
for a in arr:
	index = d[a]
	counter[index] += 1
	if index > 0 and counter[index] > counter[index - 1]:
		counter[index] -= 1
		ans += 1
ans += sum(counter) - counter[5] * 6
print(ans)


from collections import defaultdict

def find(li):
	k = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
	temp = li.count(4)
	stacks = []
	for i in range(5 * 10 ** 5):
		stacks.append([])
	d = defaultdict(int)
	for i in range(len(li)):
		temp = d[li[i]]
		potentialStack = stacks[temp]
		index = k[li[i]]
		if index == 0:
			potentialStack.append(li[i])
			d[li[i]] += 1
		elif len(potentialStack) != 0 and k[potentialStack[-1]] == index - 1:
			potentialStack.append(li[i])
			d[li[i]] += 1
	ans = 0
	for i in stacks:
		if len(i) == 6:
			ans += 6
	return len(li) - ans
x = int(input())
li = list(map(int, input().split()))
print(find(li))


n = int(input())
a = list(map(int, input().split()))
(sum4, sum8, sum15, sum16, sum23, sum42) = (0, 0, 0, 0, 0, 0)
for i in a:
	if i == 4:
		sum4 += 1
	if i == 8 and sum4 > sum8:
		sum8 += 1
	if i == 15 and sum8 > sum15:
		sum15 += 1
	if i == 16 and sum15 > sum16:
		sum16 += 1
	if i == 23 and sum16 > sum23:
		sum23 += 1
	if i == 42 and sum23 > sum42:
		sum42 += 1
ans = n - sum42 * 6
print(ans)


n = int(input())
l = list(map(int, input().strip().split()))
ct = [0, 0, 0, 0, 0, 0]
ans = 0
for i in l:
	num = -1
	if i == 4:
		num = 0
	if i == 8:
		num = 1
	if i == 15:
		num = 2
	if i == 16:
		num = 3
	if i == 23:
		num = 4
	if i == 42:
		num = 5
	ct[num] += 1
	if num != 0 and ct[num] > ct[num - 1]:
		ct[num] -= 1
mn = 100000000
for i in ct:
	mn = min(mn, i)
print(n - 6 * mn)


from sys import stdin
from bisect import *
Input = []

def Out(x):
	stdout.write(str(x) + '\n')

def In():
	return stdin.readline().strip()

def inputGrab():
	for line in stdin:
		Input.extend(map(str, line.strip().split()))
inputIDX = 0

def hasNext():
	global inputIDX
	return inputIDX < len(Input)

def nextInt():
	global inputIDX
	inputIDX += 1
	return int(Input[inputIDX - 1])

def nextString():
	global inputIDX
	inputIDX += 1
	return Input[inputIDX - 1]
a = [4, 8, 15, 16, 23, 42]
l = [0, 0, 0, 0, 0, 0]
d = [[] for _ in range(100)]

def recur(aIdx, lastPos):
	if aIdx >= 6:
		return 1
	x = a[aIdx]
	pos = bisect_left(d[x], lastPos, lo=l[aIdx])
	if pos >= len(d[x]):
		return 0
	if d[x][pos] < lastPos:
		return 0
	l[aIdx] = pos + 1
	return recur(aIdx + 1, d[x][pos])

def main():
	n = nextInt()
	for i in range(n):
		x = nextInt()
		d[x].append(i)
	ans = 0
	for idx in d[4]:
		ans += recur(1, idx)
	ans = n - 6 * ans
	print(ans)
inputGrab()
main()


cont = [0] * 6
to_index = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}

def solve(a):
	for val in a:
		ind = to_index[val]
		if ind == 0:
			cont[ind] += 1
		elif cont[ind - 1]:
			cont[ind - 1] -= 1
			cont[ind] += 1

def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	solve(a)
	res = n - 6 * cont[5]
	print(res)
main()


from collections import defaultdict
hash = defaultdict(int)
n = int(input())
ans = []
for i in range(10 ** 5):
	k = []
	ans.append(k)
l = list(map(int, input().split()))
count = 0
for i in l:
	if i == 4:
		if ans[hash[i]] != []:
			count += 1
		else:
			ans[hash[i]].append(4)
			hash[i] += 1
	if i == 8:
		if ans[hash[i]] != [4]:
			count += 1
		else:
			ans[hash[i]].append(8)
			hash[i] += 1
	if i == 15:
		if ans[hash[i]] != [4, 8]:
			count += 1
		else:
			ans[hash[i]].append(15)
			hash[i] += 1
	if i == 16:
		if ans[hash[i]] != [4, 8, 15]:
			count += 1
		else:
			ans[hash[i]].append(16)
			hash[i] += 1
	if i == 23:
		if ans[hash[i]] != [4, 8, 15, 16]:
			count += 1
		else:
			ans[hash[i]].append(23)
			hash[i] += 1
	if i == 42:
		if ans[hash[i]] != [4, 8, 15, 16, 23]:
			count += 1
		else:
			ans[hash[i]].append(42)
			hash[i] += 1
z = [4, 8, 15, 16, 23, 42]
for i in ans:
	if i != []:
		if i != z:
			count += len(i)
print(count)


a = [0] + [int(input())] * 13
for x in input().split():
	i = '4 8 15162342'.find(x)
	a[i + 2] -= a[i] < a[i + 2] and 6
print(a[12])


aux = [4, 8, 15, 16, 23, 42]
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	for j in range(6):
		if a[i] == aux[j]:
			a[i] = j
			break
s = [0] * 6
for i in range(n):
	if a[i] == 0:
		s[0] += 1
	elif s[a[i] - 1] > 0:
		s[a[i] - 1] -= 1
		s[a[i]] += 1
print(n - s[5] * 6)


n = int(input())
a = list(map(int, input().split()))
ans = 0
chk = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
ct = [0] * 6
for i in a:
	if i not in [4, 8, 15, 16, 23, 42]:
		ans += 1
for i in a:
	if i in [4, 8, 15, 16, 23, 42]:
		if i == 4:
			ct[0] += 1
		elif ct[chk[i] - 1] > ct[chk[i]]:
			ct[chk[i]] += 1
		else:
			ans += 1
ans1 = ct[5]
for i in ct:
	ans += i - ans1
print(ans)


from math import *
from collections import *
n = int(input())
a = list(map(int, input().split()))
l = [4, 8, 15, 16, 23, 42]
d = [[] for i in range(6)]
indd = [0, 0, 0, 0, 0, 0]
for i in range(n):
	ind = l.index(a[i])
	d[ind].append(i)
ct = 0
szz = len(d[0])
while indd[0] < szz:
	ind = d[0][indd[0]]
	flag = 0
	for i in range(1, 6):
		sz = len(d[i])
		while indd[i] < sz and d[i][indd[i]] < ind:
			indd[i] += 1
		if indd[i] >= sz:
			flag = 1
			break
		ind = d[i][indd[i]]
		indd[i] += 1
	else:
		ct += 1
	if flag == 1:
		break
	indd[0] += 1
print(n - ct * 6)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = 1
	rr = []
	for _ in range(t):
		n = I()
		a = LI()
		t = [4, 8, 15, 16, 23, 42]
		u = [inf] + [0] * 6
		d = {}
		for (i, c) in enumerate(t):
			d[c] = i
		r = 0
		for c in a:
			i = d[c]
			if u[i] < 1:
				r += 1
				continue
			u[i] -= 1
			u[i + 1] += 1
		for i in range(1, 6):
			r += u[i] * i
		rr.append(r)
	return JA(rr, '\n')
print(main())


n = int(input())
a = list(map(int, input().split()))
d = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
for i in range(0, n):
	if a[i] == 4:
		d[4] += 1
	if a[i] == 8 and d[8] < d[4]:
		d[8] += 1
	if a[i] == 15 and d[15] < d[8]:
		d[15] += 1
	if a[i] == 16 and d[16] < d[15]:
		d[16] += 1
	if a[i] == 23 and d[23] < d[16]:
		d[23] += 1
	if a[i] == 42 and d[42] < d[23]:
		d[42] += 1
ans = d[42] * 6
ans = n - ans
print(ans)


def loseit(lista, n):
	values = [4, 8, 15, 16, 23, 42]
	counts = [0] * 6
	for i in range(n):
		for j in range(6):
			if lista[i] == values[j]:
				lista[i] = j
				break
	for i in range(n):
		if lista[i] == 0:
			counts[0] += 1
		elif counts[lista[i] - 1] > 0:
			counts[lista[i] - 1] -= 1
			counts[lista[i]] += 1
	return n - counts[5] * 6
n = int(input())
lista = list(map(int, input().split()))
result = loseit(lista, n)
print(result)


n = int(input())
l = list(map(int, input().split()))
shtyki = 0
prav = [4, 8, 15, 16, 23, 42]
pol = [0, 0, 0, 0, 0, 0]
for i in l:
	if i != 4:
		o = prav.index(i)
		g = min(pol[:o])
		if g != pol[o]:
			pol[o] += 1
	else:
		pol[0] += 1
print(n - 6 * pol[5])


ll = lambda : list(map(int, input().split()))
testcases = 1
for testcase in range(testcases):
	[n] = ll()
	arr = ll()
	index = [[] for i in range(6)]
	freq = [0, 0, 0, 0, 0, 0]
	ref = [4, 8, 15, 16, 23, 42]
	ind = {}
	for i in range(6):
		ind[ref[i]] = i
	for (indic, i) in enumerate(arr):
		index[ind[i]].append(indic)
		freq[ind[i]] += 1
	for i in range(6):
		index[i] = index[i][::-1]
	ans = 0
	f = 1
	while f == 1:
		temp = []
		for i in range(6):
			if index[i] != []:
				temp.append(index[i][-1])
			else:
				f = 0
				break
		if temp == list(sorted(temp)) and len(temp) == 6:
			for j in range(6):
				index[j].pop()
			ans += 1
		elif len(temp) == 6:
			i = 0
			for i in range(1, len(temp)):
				if temp[i] < temp[i - 1]:
					index[i].pop()
					break
	print(n - 6 * ans)


n = int(input())
counts = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
prev = {4: -1, 8: 4, 15: 8, 16: 15, 23: 16, 42: 23}
for x in input().split():
	a = int(x)
	if a == 4 or counts[a] < counts[prev[a]]:
		counts[a] += 1
ans = n - counts[42] * 6
print(ans)


input()
numbers = map(int, input().split())
has = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
var = 0
for i in numbers:
	if i == 4:
		has[4] += 1
	if i == 8:
		if has[4] > 0:
			has[8] += 1
			has[4] -= 1
		else:
			var += 1
	if i == 15:
		if has[8] > 0:
			has[15] += 1
			has[8] -= 1
		else:
			var += 1
	if i == 16:
		if has[15] > 0:
			has[16] += 1
			has[15] -= 1
		else:
			var += 1
	if i == 23:
		if has[16] > 0:
			has[23] += 1
			has[16] -= 1
		else:
			var += 1
	if i == 42:
		if has[23] > 0:
			has[42] += 1
			has[23] -= 1
		else:
			var += 1
var += has[4] * 1 + has[8] * 2 + has[15] * 3 + has[16] * 4 + has[23] * 5
print(var)


n = int(input())
a = list(map(int, input().split()))
val = [0, 0, 0, 0, 0, 0]
for i in a:
	if i == 4:
		val[0] += 1
	elif i == 8 and val[0] > val[1]:
		val[1] += 1
	elif i == 15 and val[1] > val[2]:
		val[2] += 1
	elif i == 16 and val[2] > val[3]:
		val[3] += 1
	elif i == 23 and val[3] > val[4]:
		val[4] += 1
	elif i == 42 and val[4] > val[5]:
		val[5] += 1
print(n - val[5] * 6)


size = int(input())
enter = list(map(int, input().split()))
elements = [4, 8, 15, 16, 23, 42]
occurrences = [0, 0, 0, 0, 0, 0]
index_element = 0
index_enter = 0
while len(enter) > index_enter:
	if enter[index_enter] == elements[index_element]:
		occurrences[elements.index(enter[index_enter])] += 1
		index_element = (index_element + 1) % 6
	elif enter[index_enter] < elements[index_element] and (enter[index_enter] == elements[0] or occurrences[elements.index(enter[index_enter])] < min(occurrences[:elements.index(enter[index_enter])])):
		occurrences[elements.index(enter[index_enter])] += 1
	elif enter[index_enter] > elements[index_element] and occurrences[elements.index(enter[index_enter])] < min(occurrences[:elements.index(enter[index_enter])]):
		occurrences[elements.index(enter[index_enter])] += 1
	index_enter += 1
print(len(enter) - min(occurrences) * 6)


n = int(input())
a = list(map(int, input().split()))
g = [0 for i in range(43)]
ans = 0
for i in a:
	if i == 4:
		g[4] += 1
	elif i == 8:
		if g[4] > 0:
			g[4] -= 1
			g[8] += 1
		else:
			ans += 1
	elif i == 15:
		if g[8] > 0:
			g[8] -= 1
			g[15] += 1
		else:
			ans += 1
	elif i == 16:
		if g[15] > 0:
			g[15] -= 1
			g[16] += 1
		else:
			ans += 1
	elif i == 23:
		if g[16] > 0:
			g[16] -= 1
			g[23] += 1
		else:
			ans += 1
	elif i == 42:
		if g[23] > 0:
			g[23] -= 1
		else:
			ans += 1
	else:
		ans += 1
ans += g[4] + 2 * g[8] + 3 * g[15] + 4 * g[16] + 5 * g[23]
print(ans)


n = int(input())
li = list(map(int, input().split()))
a = []
b = []
c = []
d = []
e = []
for i in range(n):
	if li[i] == 4:
		a.append(i)
	if li[i] == 8:
		b.append(i)
	if li[i] == 15:
		c.append(i)
	if li[i] == 16:
		d.append(i)
	if li[i] == 23:
		e.append(i)
for i in range(n - 1, -1, -1):
	if li[i] == 42:
		while len(e) > 0 and e[-1] > i:
			e.pop()
		if len(a) == 0 or len(b) == 0 or len(c) == 0 or (len(d) == 0) or (len(e) == 0):
			break
		while len(d) > 0 and d[-1] > e[-1]:
			d.pop()
		if len(a) == 0 or len(b) == 0 or len(c) == 0 or (len(d) == 0) or (len(e) == 0):
			break
		while len(c) > 0 and c[-1] > d[-1]:
			c.pop()
		if len(a) == 0 or len(b) == 0 or len(c) == 0 or (len(d) == 0) or (len(e) == 0):
			break
		while len(b) > 0 and b[-1] > c[-1]:
			b.pop()
		if len(a) == 0 or len(b) == 0 or len(c) == 0 or (len(d) == 0) or (len(e) == 0):
			break
		while len(a) > 0 and a[-1] > b[-1]:
			a.pop()
		if len(a) == 0 or len(b) == 0 or len(c) == 0 or (len(d) == 0) or (len(e) == 0):
			break
		li[a[-1]] = -1
		li[b[-1]] = -1
		li[c[-1]] = -1
		li[d[-1]] = -1
		li[e[-1]] = -1
		a.pop()
		b.pop()
		c.pop()
		d.pop()
		e.pop()
		li[i] = -1
print(len(list(filter(lambda a: a != -1, li))))


n = int(input())
a = list(map(int, input().split()))
val = [0, 0, 0, 0, 0, 0]
ans = 0
for i in a:
	if i == 4:
		val[0] += 1
	elif i == 8:
		val[1] += 1
		if val[1] > val[0]:
			val[1] -= 1
			ans += 1
	elif i == 15:
		val[2] += 1
		if val[2] > val[1]:
			val[2] -= 1
			ans += 1
	elif i == 16:
		val[3] += 1
		if val[3] > val[2]:
			val[3] -= 1
			ans += 1
	elif i == 23:
		val[4] += 1
		if val[4] > val[3]:
			val[4] -= 1
			ans += 1
	elif i == 42:
		val[5] += 1
		if val[5] > val[4]:
			val[5] -= 1
			ans += 1
temp = val[5]
for i in range(4, -1, -1):
	ans += val[i] - temp
print(ans)


n = int(input())
a = list(map(int, input().split()))
p = [4, 8, 15, 16, 23]
m = dict(zip([4, 8, 15, 16, 23, 42], [0] * 6))
ans = 0
for elem in a:
	if elem != 42:
		if p.index(elem) == 0 or m[p[p.index(elem) - 1]] > m[elem]:
			m[elem] += 1
	else:
		check = 1
		for num in p:
			if m[num] == 0:
				check = 0
		if check == 1:
			for elem in p:
				m[elem] -= 1
			ans += 1
print(n - ans * 6)


n = 0
Arr = []
n = int(input())
Arr = list(map(int, input().split()))
t1 = 0
t2 = 0
t3 = 0
t4 = 0
t5 = 0
t6 = 0
for i in range(n):
	if Arr[i] == 4:
		t1 += 1
	if Arr[i] == 8:
		if t2 < t1:
			t2 += 1
	if Arr[i] == 15:
		if t3 < t1 and t3 < t2:
			t3 += 1
	if Arr[i] == 16:
		if t4 < t1 and t4 < t2 and (t4 < t3):
			t4 += 1
	if Arr[i] == 23:
		if t5 < t1 and t5 < t2 and (t5 < t3) and (t5 < t4):
			t5 += 1
	if Arr[i] == 42:
		if t6 < t1 and t6 < t2 and (t6 < t3) and (t6 < t4) and (t6 < t5):
			t6 += 1
Min = t1
Min = min(Min, t2)
Min = min(Min, t3)
Min = min(Min, t4)
Min = min(Min, t5)
Min = min(Min, t6)
print(n - Min * 6)


n = int(input())
arr = list(map(int, input().split()))
dict1 = {}
dict1[4] = []
dict1[8] = []
dict1[15] = []
dict1[16] = []
dict1[23] = []
dict1[42] = []
for i in range(n):
	dict1[arr[i]].append(i)
count = 0
indexes = [0] * 6
turn = 0
numarr = [4, 8, 15, 16, 23, 42]
flag = 0
prev = -1
while flag == 0:
	num = numarr[turn]
	if len(dict1[num]) <= indexes[turn]:
		flag = 1
		break
	else:
		while indexes[turn] < len(dict1[num]) and dict1[num][indexes[turn]] < prev:
			indexes[turn] += 1
		if len(dict1[num]) == indexes[turn]:
			flag = 1
			break
		else:
			prev = dict1[num][indexes[turn]]
			indexes[turn] += 1
			turn = (turn + 1) % 6
			if turn == 0:
				count += 6
				prev = -1
print(n - count)


n = int(input())
z = [0] * 6
l = list(map(int, input().split()))
a = [0, 0, 0, 0, 0, 0]
counter = 0
f = []
c2 = 0
for x in range(n):
	if l[x] == 4:
		a[0] += 1
	if l[x] == 8 and a[0] > a[1]:
		a[1] += 1
	if l[x] == 15 and a[1] > a[2]:
		a[2] += 1
	if l[x] == 16 and a[2] > a[3]:
		a[3] += 1
	if l[x] == 23 and a[3] > a[4]:
		a[4] += 1
	if l[x] == 42 and a[4] > a[5]:
		a[5] += 1
		counter += 6
print(n - counter)


n = int(input())
a = list(map(int, input().split()))
per = [4, 8, 15, 16, 23, 42]
tmp = [0] * 6
for i in range(n):
	j = per.index(a[i])
	if j == 0:
		tmp[0] += 1
	elif tmp[j] < tmp[j - 1]:
		tmp[j] += 1
print(n - tmp[5] * 6)


q = int(input())
a = 0
b = 0
c = 0
d = 0
e = 0
f = 0
for j in map(int, input().split()):
	if j == 4:
		a += 1
	elif j == 8 and b < a:
		b += 1
	elif j == 15 and c < b:
		c += 1
	elif j == 16 and d < c:
		d += 1
	elif j == 23 and e < d:
		e += 1
	elif j == 42 and f < e:
		f += 1
print(q - f * 6)


n = int(input())
list1 = list(map(int, input().split()))
dp = [0] * 6
arr = [4, 8, 15, 16, 23, 42]
for i in range(n):
	if list1[i] == 4:
		dp[0] += 1
	elif list1[i] == 8:
		dp[1] = min(dp[0], dp[1] + 1)
	elif list1[i] == 15:
		dp[2] = min(dp[1], dp[2] + 1)
	elif list1[i] == 16:
		dp[3] = min(dp[2], dp[3] + 1)
	elif list1[i] == 23:
		dp[4] = min(dp[3], dp[4] + 1)
	elif list1[i] == 42:
		dp[5] = min(dp[4], dp[5] + 1)
print(n - dp[5] * 6)


from collections import defaultdict
import sys

def find(ol, s):
	if len(ol) < 5:
		return straight_search(ol, s)
	else:
		return bin_search(ol, s)

def straight_search(ol, s):
	for i in ol:
		if i >= s:
			return i
	return None

def bin_search(ol, k):
	s = 0
	e = len(ol) - 1
	while e - s > 6:
		m = (s + e) // 2
		if ol[m] > k:
			e = m
		elif ol[m] < k:
			s = m
		else:
			s = m
	return straight_search(ol[s:e + 1], k)

def build_index(a):
	index = defaultdict(list)
	for (pos, e) in enumerate(a):
		index[e].append(pos)
	for k in [4, 8, 15, 16, 23, 42]:
		if k not in index:
			index[k] = []
	index_pointer = dict([(k, v[0] if v else 99999999999999999) for (k, v) in index.items()])
	return (index, index_pointer)

def find_pattern(index, index_pointer):
	pt = [4, 8, 15, 16, 23, 42]
	last = None
	for e in pt:
		ol = index[e]
		pointer = index_pointer[e]
		if last:
			pointer = max(pointer, last)
		r = find(ol, pointer)
		if r is None:
			return None
		index_pointer[e] = r + 1
		last = r + 1
	return 'ok'

def solve(a):
	(index, index_pointer) = build_index(a)
	n = 0
	while True:
		if find_pattern(index, index_pointer) == 'ok':
			n += 1
		else:
			break
	return len(a) - n * 6
sys.stdin.readline()
print(solve([int(i) for i in sys.stdin.readline().strip().split()]))


sample = [4, 8, 15, 16, 23, 42]
n = int(input())
a = list(map(int, input().split()))
last_digit = {}
to_delete = 0
for item in a:
	if item == 4:
		if item in last_digit:
			last_digit[item] += 1
		else:
			last_digit[item] = 1
	else:
		prev = sample[sample.index(item) - 1]
		if prev in last_digit and last_digit[prev] > 0:
			last_digit[prev] -= 1
			if item in last_digit:
				last_digit[item] += 1
			else:
				last_digit[item] = 1
		else:
			to_delete += 1
for key in last_digit.keys():
	if key != 42:
		to_delete += last_digit[key] * (sample.index(key) + 1)
print(to_delete)


n = int(input())
a = list(map(int, input().split()))
b = [4, 8, 15, 16, 23, 42]
c = [0] * 6
i = 0
x = 0
while len(a) > x:
	if a[x] == b[i]:
		c[b.index(a[x])] += 1
		i = (i + 1) % 6
	elif a[x] < b[i] and (a[x] == b[0] or c[b.index(a[x])] < min(c[:b.index(a[x])])):
		c[b.index(a[x])] += 1
	elif a[x] > b[i] and c[b.index(a[x])] < min(c[:b.index(a[x])]):
		c[b.index(a[x])] += 1
	x += 1
print(len(a) - min(c) * 6)


n = int(input())
a = [int(i) for i in input().split()]
seq = [4, 8, 15, 16, 23, 42]
co = [0] * 6
hm = {}
for i in range(6):
	hm[seq[i]] = i
for i in range(n):
	if hm[a[i]] == 0:
		co[hm[a[i]]] += 1
	elif co[hm[a[i]] - 1] > co[hm[a[i]]]:
		co[hm[a[i]]] += 1
print(n - co[5] * 6)


n = int(input())
l = list(map(int, input().split()))
s = [0, 0, 0, 0, 0, 0]
d = 0
for i in range(n):
	if l[i] == 4:
		s[0] += 1
	if l[i] == 8 and s[0] > s[1]:
		s[1] += 1
	elif l[i] == 8:
		d += 1
	if l[i] == 15 and s[0] > s[2] and (s[1] > s[2]):
		s[2] += 1
	elif l[i] == 15:
		d += 1
	if l[i] == 16 and s[0] > s[3] and (s[1] > s[3]) and (s[2] > s[3]):
		s[3] += 1
	elif l[i] == 16:
		d += 1
	if l[i] == 23 and s[0] > s[4] and (s[1] > s[4]) and (s[2] > s[4]) and (s[3] > s[4]):
		s[4] += 1
	elif l[i] == 23:
		d += 1
	if l[i] == 42 and s[0] > s[5] and (s[1] > s[5]) and (s[2] > s[5]) and (s[3] > s[5]) and (s[4] > s[5]):
		s[5] += 1
	elif l[i] == 42:
		d += 1
	if s[0] > 0 and s[1] > 0 and (s[2] > 0) and (s[3] > 0) and (s[4] > 0) and (s[5] > 0):
		s[0] -= 1
		s[1] -= 1
		s[2] -= 1
		s[3] -= 1
		s[4] -= 1
		s[5] -= 1
print(d + s[0] + s[1] + s[2] + s[3] + s[4] + s[5])


n = int(input())
a = [int(i) for i in input().split()]
b = [4, 8, 15, 16, 23, 42]
d = {i: 0 for i in b}
g = 0
for i in a:
	if i in d:
		m = d[i] + 1
		for j in b:
			if j == i:
				break
			m = min(m, d[j])
		d[i] = m
		m = min(d.values())
		for j in d:
			d[j] -= m
		g += m
	else:
		n -= 1
print(n - g * 6)


def rank(x):
	if x == 4:
		return 0
	if x == 8:
		return 1
	if x == 15:
		return 2
	if x == 16:
		return 3
	if x == 23:
		return 4
	return 5
n = int(input())
a = list(map(int, input().split()))
curr = [0, 0, 0, 0, 0, 0]
for guy in a:
	b = rank(guy)
	if b == 0:
		curr[b] += 1
	elif curr[b - 1] > curr[b]:
		curr[b] += 1
print(n - 6 * min(curr))


n = int(input())
a = map(int, input().split())
x = [4, 8, 15, 16, 23, 42]
dp = [0] * 6
for i in a:
	t = x.index(i)
	if t == 0:
		dp[t] += 1
	elif dp[t - 1] > 0:
		dp[t] += 1
		dp[t - 1] -= 1
print(n - dp[-1] * 6)


NUMBERS = [4, 8, 15, 16, 23, 42]
n = int(input())
a = [int(x) for x in input().split(' ')]
chains = []
for i in range(n):
	if a[i] == 4:
		chains.append([i])
for (exp_len, number) in enumerate(NUMBERS[1:], 1):
	chain_index = 0
	for i in range(n):
		if a[i] == number:
			while chain_index < len(chains) and len(chains[chain_index]) != exp_len and (chains[chain_index][-1] > i):
				chain_index += 1
			if chain_index < len(chains) and len(chains[chain_index]) == exp_len and (chains[chain_index][-1] < i):
				chains[chain_index].append(i)
				chain_index += 1
good_chains = 0
for chain in chains:
	if len(chain) == 6:
		good_chains += 1
print(n - good_chains * 6)


import heapq
n = int(input())
lst = list(map(int, input().split()))
Dict = {4: [], 8: [], 15: [], 16: [], 23: [], 42: []}
given = [4, 8, 15, 16, 23, 42]
for i in Dict:
	heapq.heapify(Dict[i])
count = 1
ans = 0
for i in lst:
	if i == 4:
		heapq.heappush(Dict[4], count)
		count += 1
	else:
		try:
			cur_index = given.index(i)
			temp = heapq.heappop(Dict[given[cur_index - 1]])
			heapq.heappush(Dict[i], temp)
		except IndexError:
			continue
ans = len(Dict[42])
print(n - 6 * ans)


n = int(input())
a = list(map(int, input().split()))
good = [4, 8, 15, 16, 23, 42]
mp = {4: 0, 8: 4, 15: 8, 16: 15, 23: 16, 42: 23}
count = {0: 10 ** 6, 4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
ans = 0
for i in range(n):
	find = mp[a[i]]
	if count[find] < 1:
		ans += 1
	else:
		count[a[i]] += 1
		count[mp[a[i]]] -= 1
print(n - 6 * count[42])


n = int(input())
array = list(map(int, input().split()))
good_m = {4, 8, 15, 16, 23, 42}
good_a = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
p_arrays = [0, 0, 0, 0, 0]
count = 0
for e in array:
	x = good_a[e]
	if x == 0:
		p_arrays[0] += 1
	elif x == 5 and p_arrays[4] != 0:
		p_arrays[4] -= 1
	elif p_arrays[x - 1] != 0:
		p_arrays[x - 1] -= 1
		p_arrays[x] += 1
	else:
		count += 1
for i in range(5):
	count += (i + 1) * p_arrays[i]
print(count)


from collections import deque
n = int(input())
arr = [int(p) for p in input().split()]
p4 = deque()
p8 = deque()
p15 = deque()
p16 = deque()
p23 = deque()
p42 = deque()
count = 0
for i in range(len(arr)):
	if arr[i] == 4:
		p4.append(i)
	elif arr[i] == 8:
		p8.append(i)
	elif arr[i] == 15:
		p15.append(i)
	elif arr[i] == 16:
		p16.append(i)
	elif arr[i] == 23:
		p23.append(i)
	elif arr[i] == 42:
		p42.append(i)
while True:
	temp = []
	if p4:
		temp.append(p4.popleft())
	else:
		break
	if p8:
		i = p8.popleft()
		while i < temp[-1] and p8:
			i = p8.popleft()
		if i > temp[-1]:
			temp.append(i)
		else:
			break
	else:
		break
	if p15:
		i = p15.popleft()
		while i < temp[-1] and p15:
			i = p15.popleft()
		if i > temp[-1]:
			temp.append(i)
		else:
			break
	else:
		break
	if p16:
		i = p16.popleft()
		while i < temp[-1] and p16:
			i = p16.popleft()
		if i > temp[-1]:
			temp.append(i)
		else:
			break
	else:
		break
	if p23:
		i = p23.popleft()
		while i < temp[-1] and p23:
			i = p23.popleft()
		if i > temp[-1]:
			temp.append(i)
		else:
			break
	else:
		break
	if p42:
		i = p42.popleft()
		while i < temp[-1] and p42:
			i = p42.popleft()
		if i > temp[-1]:
			temp.append(i)
		else:
			break
	else:
		break
	if len(temp) == 6:
		count += 1
print(n - count * 6)


import sys
n = int(input())
a = [int(x) for x in input().split()]
d = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
cnt = [0] * 6
for x in a:
	if x == 4:
		cnt[0] += 1
	elif cnt[d[x] - 1] > 0:
		cnt[d[x] - 1] -= 1
		cnt[d[x]] += 1
print(n - cnt[5] * 6)


n = int(input())
d = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
c = [0 for _ in d]
k = 0
for x in input().split():
	i = d[int(x)]
	if i > 0 and c[i] == c[i - 1]:
		k += 1
	else:
		c[i] += 1
m = c[5]
k += sum([x - m for x in c])
print(k)


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
D = {4: 1, 8: 2, 15: 3, 16: 4, 23: 5, 42: 6}
A = [D[a] for a in A]
C = Counter()
C[0] = INF
for a in A:
	if C[a - 1] > C[a]:
		C[a] += 1
ans = N - C[6] * 6
print(ans)


def read(t=int):
	return list(map(t, input().strip().split(' ')))
n = read()[0]
a = read()
from collections import defaultdict
d = defaultdict(int)
last = [4, 4, 8, 15, 16, 23, 42]
for i in a:
	index = last.index(i) - 1
	if i == 4:
		d[i] += 1
	else:
		d[i] = min(d[i] + 1, d[last[index]])
remove = n - min(d.values()) * 6
if remove < 0:
	remove = n
print(remove)


def filtra_array(n, array):
	div4 = 0
	div8 = 0
	div15 = 0
	div16 = 0
	div23 = 0
	div42 = 0
	for i in range(n):
		if array[i] == 4:
			div4 += 1
		elif array[i] == 8:
			if div4 > 0:
				div4 -= 1
				div8 += 1
		elif array[i] == 15:
			if div8 > 0:
				div8 -= 1
				div15 += 1
		elif array[i] == 16:
			if div15 > 0:
				div15 -= 1
				div16 += 1
		elif array[i] == 23:
			if div16 > 0:
				div16 -= 1
				div23 += 1
		elif array[i] == 42:
			if div23 > 0:
				div23 -= 1
				div42 += 1
	return n - div42 * 6
n = int(input())
array = list(map(int, input().rstrip().split()))
array_bom = filtra_array(n, array)
print(array_bom)


n = int(input())
lst = list(map(int, input().split()))
d = {4: 1, 8: 2, 15: 3, 16: 4, 23: 5, 42: 6}
res = [n] + [0] * 6
for (i, x) in enumerate(lst):
	if res[d[x] - 1]:
		res[d[x]] += 1
		res[d[x] - 1] -= 1
print(n - 6 * res[-1])


q = int(input())
a = list(map(int, input().split()))
(k4, k8, k15, k16, k23, k42) = (0, 0, 0, 0, 0, 0)
delete = 0
for i in range(q):
	if a[i] == 4:
		k4 += 1
		continue
	if a[i] == 8:
		if k4 > k8:
			k8 += 1
		continue
	if a[i] == 15:
		if k8 <= k4 and k15 < k8:
			k15 += 1
		continue
	if a[i] == 16:
		if k8 <= k4 and k15 <= k8 and (k16 < k15):
			k16 += 1
		continue
	if a[i] == 23:
		if k8 <= k4 and k15 <= k8 and (k16 <= k15) and (k23 < k16):
			k23 += 1
		continue
	if a[i] == 42:
		if k8 <= k4 and k15 <= k8 and (k16 <= k15) and (k23 <= k16) and (k42 < k23):
			k42 += 1
		continue
print(len(a) - k42 * 6)


n = int(input())
a = [int(j) for j in input().split()]
l = [0, 0, 0, 0, 0, 0]
c = 0
for i in range(n):
	if a[i] == 4:
		l[0] += 1
	elif a[i] == 8 and l[1] < l[0]:
		l[1] += 1
	elif a[i] == 15 and l[1] > l[2]:
		l[2] += 1
	elif a[i] == 16 and l[3] < l[2]:
		l[3] += 1
	elif a[i] == 23 and l[4] < l[3]:
		l[4] += 1
	elif a[i] == 42 and l[5] < l[4]:
		l[5] += 1
	else:
		c += 1
c = c + sum(l) - l[5] * 6
print(c)


n = int(input())
arr = [x for x in input().split(' ')]
myMap = {'0': 999999, '4': 0, '8': 0, '15': 0, '16': 0, '23': 0, '42': 0}
beforeItem = {'4': '0', '8': '4', '15': '8', '16': '15', '23': '16', '42': '23'}
bad = 0
for item in arr:
	if myMap[beforeItem[item]] > myMap[item]:
		myMap[item] += 1
	else:
		bad += 1
print(bad + (sum(myMap.values()) - min(myMap.values()) * 6) - 999999)


n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
cnt = [4, 8, 15, 16, 23, 42]
temp = [0] * 6
for i in a:
	k = cnt.index(i)
	if k == 0:
		temp[k] += 1
	elif temp[k - 1]:
		temp[k] += 1
		temp[k - 1] -= 1
print(n - temp[5] * 6)


R = lambda : map(int, input().split())
n = int(input())
cnts = [0] * 50
arr = [8, 15, 16, 23, 42, 4]
for x in R():
	if x == 4:
		cnts[x] += 1
	elif x in arr:
		idx = arr.index(x)
		cnts[arr[idx]] = min(cnts[arr[idx]] + 1, cnts[arr[idx - 1]])
print(n - 6 * cnts[42])


import sys

def main():
	n = int(sys.stdin.readline())
	a = sys.stdin.readline().split(' ')
	c = [0, 0, 0, 0, 0, 0]
	l = [4, 8, 15, 16, 23, 42]
	for e in a:
		i = l.index(int(e))
		if i == 0:
			c[0] += 1
		elif c[i - 1] > c[i]:
			c[i] += 1
	print(n - c[5] * 6)
main()


n = int(input())
a = list(map(int, input().split()))
s = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
d = 0
for i in range(n):
	if a[i] == 4:
		s[4] += 1
	else:
		m = s[4]
		for j in s:
			if j < a[i]:
				m = min(m, s[j])
		s[a[i]] = min(m, s[a[i]] + 1)
print(n - min(s.values()) * 6)


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def dinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def main():
	n = int(input())
	aleonov = list(rinput())
	rt = [4, 8, 15, 16, 23, 42]
	leonov = []
	for i in range(6):
		leonov.append(0)
	for i in range(n):
		if aleonov[i] == rt[0]:
			leonov[0] += 1
		elif aleonov[i] == rt[1]:
			if leonov[0] > 0:
				leonov[0] -= 1
				leonov[1] += 1
		elif aleonov[i] == rt[2]:
			if leonov[1] > 0:
				leonov[1] -= 1
				leonov[2] += 1
		elif aleonov[i] == rt[3]:
			if leonov[2] > 0:
				leonov[2] -= 1
				leonov[3] += 1
		elif aleonov[i] == rt[4]:
			if leonov[3] > 0:
				leonov[3] -= 1
				leonov[4] += 1
		elif aleonov[i] == rt[5]:
			if leonov[4] > 0:
				leonov[4] -= 1
				leonov[5] += 1
	print(n - leonov[-1] * 6)
main()


from sys import stdin
n = int(stdin.readline().strip('\n'))
arr = [int(x) for x in stdin.readline().split()]
good = [4, 8, 15, 16, 23, 42]
ans = 0
s = [0, 0, 0, 0, 0, 0]
for ptr in range(n):
	pos = -1
	for (i, val) in enumerate(good):
		if arr[ptr] == val:
			pos = i
	if pos == -1 or (pos != 0 and s[pos - 1] == 0):
		ans += 1
	else:
		if pos != 0:
			s[pos - 1] -= 1
		s[pos] += 1
for i in range(5):
	ans += s[i] * (i + 1)
print(ans)


n = int(input())
l = list(map(int, input().split()))
d = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
l1 = [0, 4, 8, 15, 16, 23, 42]
counter = 0
for i in l:
	if i == 4:
		d[4] += 1
	if i == 8:
		if d[4] > 0:
			d[4] -= 1
			d[8] += 1
		else:
			counter += 1
	if i == 15:
		if d[8] > 0:
			d[8] -= 1
			d[15] += 1
		else:
			counter += 1
	if i == 16:
		if d[15] > 0:
			d[15] -= 1
			d[16] += 1
		else:
			counter += 1
	if i == 23:
		if d[16] > 0:
			d[16] -= 1
			d[23] += 1
		else:
			counter += 1
	if i == 42:
		if d[23] > 0:
			d[23] -= 1
		else:
			counter += 1
for j in d.keys():
	counter += d[j] * l1.index(j)
print(counter)


import math
n = int(input())
a = list(map(int, input().split()))
b = [0] * 6
for i in range(n):
	if a[i] == 4:
		b[0] += 1
	elif a[i] == 8 and b[0] > b[1]:
		b[1] += 1
	elif a[i] == 15 and b[1] > b[2]:
		b[2] += 1
	elif a[i] == 16 and b[2] > b[3]:
		b[3] += 1
	elif a[i] == 23 and b[3] > b[4]:
		b[4] += 1
	elif a[i] == 42 and b[4] > b[5]:
		b[5] += 1
print(n - b[5] * 6)


n = int(input())
d = [0] * 6
m = {8: 1, 15: 2, 16: 3, 42: 5, 23: 4}
for i in map(int, input().split()):
	if i == 4:
		d[0] += 1
	elif d[m[i] - 1]:
		d[m[i] - 1] -= 1
		d[m[i]] += 1
print(n - d[5] * 6)


n = int(input())
a = [int(i) for i in input().split()]
b = [0, 0, 0, 0, 0, 0]
ans = 0
for i in range(n):
	if a[i] == 4:
		b[0] += 1
	elif a[i] == 8:
		if b[1] < b[0]:
			b[1] += 1
		else:
			ans += 1
	elif a[i] == 15:
		if b[2] < b[1]:
			b[2] += 1
		else:
			ans += 1
	elif a[i] == 16:
		if b[3] < b[2]:
			b[3] += 1
		else:
			ans += 1
	elif a[i] == 23:
		if b[4] < b[3]:
			b[4] += 1
		else:
			ans += 1
	elif b[5] < b[4]:
		b[5] += 1
	else:
		ans += 1
ans += sum(b) - b[5] * 6
print(ans)


n = int(input())
s = input()
s1 = s.split()
l = [int(i) for i in s1]
d = {4: 1, 8: 2, 15: 3, 16: 4, 23: 5, 42: 6}
dp = [100000000.0, 0, 0, 0, 0, 0, 0]
for i in range(len(l)):
	if l[i] in d and dp[d[l[i]]] < dp[d[l[i]] - 1]:
		dp[d[l[i]]] = dp[d[l[i]]] + 1
print(len(l) - dp[6] * 6)


n = int(input())
xs = [int(x) for x in input().split()]
stages = [10000000, 0, 0, 0, 0, 0, 0]
stage = {4: 1, 8: 2, 15: 3, 16: 4, 23: 5, 42: 6}
removes = 0
for x in xs:
	s = stage[x]
	if stages[s - 1] > 0:
		stages[s - 1] -= 1
		stages[s] += 1
	else:
		removes += 1
for i in range(1, 6):
	removes += stages[i] * i
print(removes)


from collections import defaultdict
from bisect import bisect_left
from sys import stdin

def solve():
	N = int(stdin.readline())
	A = [int(k) for k in stdin.readline().split()]
	indexes = defaultdict(list)
	for i in range(N):
		indexes[A[i]].append(i)
	cnt = 0
	last = [0] * 5
	nums = (8, 15, 16, 23, 42)
	cur = [0] * 6
	for i in range(len(indexes[4])):
		flag = 0
		cur[0] = indexes[4][i]
		for j in range(5):
			if cur[j + 1] > cur[j]:
				continue
			k = nums[j]
			pos = bisect_left(indexes[k], last[j] + 1)
			n = len(indexes[k])
			while pos < n and indexes[k][pos] < cur[j]:
				pos += 1
			if pos >= n:
				flag = 1
				break
			cur[j + 1] = indexes[k][pos]
		if flag:
			break
		for j in range(5):
			last[j] = cur[j + 1]
		cnt += 6
		cur = [0] * 6
	print(N - cnt)
solve()


num = int(input())
numbers = list(map(int, input().split()))
if len(numbers) < 6:
	print(len(numbers))
else:
	myDic = {'4': 0, '8': 1, '15': 2, '16': 3, '23': 4, '42': 5}
	remove = 0
	occ = [0, 0, 0, 0, 0, 0]
	for n in numbers:
		s = str(n)
		if myDic[s] == 0:
			occ[myDic[s]] += 1
		elif occ[myDic[s] - 1] > occ[myDic[s]]:
			occ[myDic[s]] += 1
		else:
			remove += 1
	for o in reversed(occ[:-1]):
		remove += o - occ[-1]
	print(remove)


n = int(input())
lis = [int(x) for x in input().split()]
count = [0 for _ in range(6)]
map = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
removed = 0
for i in lis:
	if i in map:
		if map[i] == 0:
			count[0] += 1
		elif count[map[i] - 1] > 0:
			count[map[i] - 1] -= 1
			count[map[i]] += 1
		else:
			removed += 1
	else:
		removed += 1
for (i, j) in enumerate(count[:-1]):
	removed += (i + 1) * j
print(removed)


n = int(input())
l = list(map(int, input().split()))
one = []
two = []
three = []
four = []
five = []
six = []
for i in range(n):
	if l[i] == 4:
		one.append(i)
	elif l[i] == 8:
		two.append(i)
	elif l[i] == 15:
		three.append(i)
	elif l[i] == 16:
		four.append(i)
	elif l[i] == 23:
		five.append(i)
	else:
		six.append(i)
one = one[::-1]
two = two[::-1]
three = three[::-1]
four = four[::-1]
five = five[::-1]
six = six[::-1]
if not one or not two or (not three) or (not four) or (not five) or (not six):
	print(n)
	quit()
ans = 0
while one and two and three and four and five and six:
	if not one:
		break
	lst = one[-1]
	one.pop()
	while two and two[-1] < lst:
		two.pop()
	if not two:
		break
	lst = two[-1]
	two.pop()
	while three and three[-1] < lst:
		three.pop()
	if not three:
		break
	lst = three[-1]
	three.pop()
	while four and four[-1] < lst:
		four.pop()
	if not four:
		break
	lst = four[-1]
	four.pop()
	while five and five[-1] < lst:
		five.pop()
	if not five:
		break
	lst = five[-1]
	five.pop()
	while six[-1] < lst:
		six.pop()
	six.pop()
	ans += 1
	if not one or not two or (not three) or (not four) or (not five) or (not six):
		break
print(n - 6 * ans)


C = [4, 8, 15, 16, 23, 42]
n = int(input())
(*a,) = map(int, input().split())
s = [n + 1] + [0] * 6
for i in a:
	if s[C.index(i) + 1] < s[C.index(i)]:
		s[C.index(i) + 1] += 1
print(n - min(s[1:]) * 6)


import sys
inf = float('inf')
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
(mod, MOD) = (1000000007, 998244353)
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
n = int(input())
Arr = get_array()
mydict = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
for i in Arr:
	if i == 4:
		mydict[4] += 1
	elif i == 8 and mydict[4] > mydict[8]:
		mydict[8] += 1
	elif i == 15 and mydict[8] > mydict[15]:
		mydict[15] += 1
	elif i == 16 and mydict[15] > mydict[16]:
		mydict[16] += 1
	elif i == 23 and mydict[16] > mydict[23]:
		mydict[23] += 1
	elif i == 42 and mydict[23] > mydict[42]:
		mydict[42] += 1
print(n - 6 * mydict[42])


pos = [4, 8, 15, 16, 23, 42]
size = int(input())
inp = list(map(int, input().split()))
last = [0 for x in range(6)]
if size < 6:
	print(size)
else:
	ret = 0
	for val in inp:
		val_idx = pos.index(val)
		if val == 4:
			last[val_idx] += 1
		elif last[val_idx - 1] > 0:
			last[val_idx - 1] -= 1
			last[val_idx] += 1
		else:
			ret += 1
	for i in range(5):
		ret += (i + 1) * last[i]
	print(ret)


from sys import stdin, stdout

def main():
	n = int(input())
	rem = 0
	count = [0] * 6
	for x in map(int, stdin.readline().rstrip().split()):
		nextIx = toIndex(x)
		if any((count[nextIx] + 1 > count[x] for x in range(0, nextIx))):
			rem += 1
		else:
			count[nextIx] += 1
	low = min(count)
	for x in count:
		rem += x - low
	print(rem)

def toIndex(x):
	return {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}[x]
main()


n = int(input())
a = list(map(int, input().split()))
x = [4, 8, 15, 16, 23, 42]
d = {}
for i in x:
	d[i] = [-1, []]
for i in range(n):
	if a[i] == 4:
		d[4][0] += 1
		d[4][1].append(i)
	else:
		ix = x.index(a[i])
		if d[x[ix - 1]][0] > d[a[i]][0] and d[x[ix - 1]][1][d[x[ix - 1]][0]] < i:
			d[a[i]][0] += 1
			d[a[i]][1].append(i)
ans = n - (d[42][0] + 1) * 6
print(ans)


def solution():
	d = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
	n = int(input())
	a = list(map(int, input().split()))
	dp = [[0] * 7 for i in range(n + 1)]
	ans = n
	for i in range(n):
		num = a[i]
		if num == 4:
			dp[i + 1][1] = dp[i][1] + 1
			for j in range(2, 7):
				dp[i + 1][j] = dp[i][j]
		elif num == 8:
			if dp[i][1] > 0:
				dp[i + 1][1] = dp[i][1] - 1
				dp[i + 1][2] = dp[i][2] + 1
				for j in range(1, 7):
					if j != 1 and j != 2:
						dp[i + 1][j] = dp[i][j]
			else:
				dp[i + 1] = dp[i]
		elif num == 15:
			if dp[i][2] > 0:
				dp[i + 1][2] = dp[i][2] - 1
				dp[i + 1][3] = dp[i][3] + 1
				for j in range(1, 7):
					if j != 2 and j != 3:
						dp[i + 1][j] = dp[i][j]
			else:
				dp[i + 1] = dp[i]
		elif num == 16:
			if dp[i][3] > 0:
				dp[i + 1][3] = dp[i][3] - 1
				dp[i + 1][4] = dp[i][4] + 1
				for j in range(1, 7):
					if j != 3 and j != 4:
						dp[i + 1][j] = dp[i][j]
			else:
				dp[i + 1] = dp[i]
		elif num == 23:
			if dp[i][4] > 0:
				dp[i + 1][4] = dp[i][4] - 1
				dp[i + 1][5] = dp[i][5] + 1
				for j in range(1, 7):
					if j != 4 and j != 5:
						dp[i + 1][j] = dp[i][j]
			else:
				dp[i + 1] = dp[i]
		elif num == 42:
			if dp[i][5] > 0:
				dp[i + 1][5] = dp[i][5] - 1
				dp[i + 1][6] = dp[i][6] + 1
				for j in range(1, 7):
					if j != 5 and j != 6:
						dp[i + 1][j] = dp[i][j]
			else:
				dp[i + 1] = dp[i]
	print(ans - 6 * dp[n][6])
	return

def main():
	test = 1
	for i in range(test):
		solution()
	return
main()


from itertools import permutations
from collections import defaultdict
from math import *
import os
import sys
from io import BytesIO, IOBase
from heapq import nlargest
from bisect import *
import copy
import itertools
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
n = int(input())
arr = list(map(int, input().split()))
ans = 0
x = [4, 8, 15, 16, 23, 42]
d = defaultdict(int)
for i in range(n):
	d[arr[i]] += 1
	if arr[i] != 4:
		if d[x[x.index(arr[i]) - 1]] < d[arr[i]]:
			d[arr[i]] -= 1
			ans += 1
total = 0
mi = 10 ** 9
for i in range(6):
	total += d[x[i]]
	if d[x[i]] < mi:
		mi = d[x[i]]
print(ans + total - 6 * mi)


n = int(input())
arr = list(map(int, input().split()))
prev = {8: 4, 15: 8, 16: 15, 23: 16, 42: 23}
counts = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
for i in arr:
	if i == 4:
		counts[i] += 1
	elif counts[i] < counts[prev[i]]:
		counts[i] += 1
print(n - counts[42] * 6)


import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest

def STR():
	return list(input())

def INT():
	return int(input())

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

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def sortListWithIndex(listOfTuples, idx):
	return sorted(listOfTuples, key=lambda x: x[idx])

def sortDictWithVal(passedDic):
	temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))[::-1]
	toret = {}
	for tup in temp:
		toret[tup[0]] = tup[1]
	return toret

def sortDictWithKey(passedDic):
	return dict(OrderedDict(sorted(passedDic.items())))
INF = float('inf')
mod = 10 ** 9 + 7
n = INT()
a = LIST()
c = [0] * 7
pos = [0] * 43
pos[4] = 1
pos[8] = 2
pos[15] = 3
pos[16] = 4
pos[23] = 5
pos[42] = 6
for i in range(n):
	if a[i] == 4:
		c[1] += 1
	elif c[pos[a[i]] - 1] > 0:
		c[pos[a[i]]] += 1
		c[pos[a[i]] - 1] -= 1
print(n - c[6] * 6)


def lose(a):
	ref_arr = [4, 8, 15, 16, 23, 42]
	if a == []:
		return 0
	if len(a) < 6:
		return len(a)
	if len(a) == 6 and a != ref_arr:
		return len(a)
	temp = [0, 0, 0, 0, 0, 0]
	res = 0
	for i in a:
		x = ref_arr.index(i)
		if x == 0 or temp[x] < temp[x - 1]:
			temp[x] += 1
		else:
			res += 1
	res += sum((z - temp[-1] for z in temp))
	return res
n = int(input())
a = list(map(int, input().split()))
print(lose(a))


import sys
import math
import bisect

def main():
	n = int(input())
	A = list(map(int, input().split()))
	B = [4, 8, 15, 16, 23, 42]
	d = dict()
	for i in range(len(B)):
		d[B[i]] = i
	C = [0] * 6
	for a in A:
		val = d[a]
		if val == 0:
			C[val] += 1
		elif C[val - 1]:
			C[val - 1] -= 1
			C[val] += 1
	ans = n - C[-1] * 6
	print(ans)
main()


input()
arr = input().split(' ')
arr = [int(x) for x in arr]
options = [4, 8, 15, 16, 23, 42]
counts = [0, 0, 0, 0, 0, 0]
deleted = 0
for x in arr:
	ix = options.index(x)
	if x != 4 and counts[ix] + 1 > counts[ix - 1]:
		deleted += 1
	else:
		counts[ix] += 1
print(deleted + sum([x - min(counts) for x in counts]))


def compute(arr):
	cts = [0 for i in range(6)]
	di = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
	for i in range(len(arr)):
		pl = di[arr[i]]
		if pl == 0:
			cts[0] = cts[0] + 1
		elif cts[pl] < cts[pl - 1]:
			cts[pl] = cts[pl] + 1
	val = min(cts)
	return len(arr) - 6 * val

def main():
	n = int(input())
	arr = input().split(' ')
	for i in range(n):
		arr[i] = int(arr[i])
	print(compute(arr))
main()


from bisect import bisect_left
N = int(input())
ls = list(map(int, input().split()))
d4 = []
d8 = []
d15 = []
d16 = []
d23 = []
d42 = []
for i in range(len(ls)):
	if ls[i] == 4:
		d4.append(i)
	elif ls[i] == 8:
		d8.append(i)
	elif ls[i] == 15:
		d15.append(i)
	elif ls[i] == 16:
		d16.append(i)
	elif ls[i] == 23:
		d23.append(i)
	else:
		d42.append(i)
cnt = 0
j = 0
k = 0
l = 0
m = 0
n = 0
for i in d4:
	pos = bisect_left(d8, i, lo=j)
	if pos == len(d8):
		break
	i = d8[pos]
	j = pos + 1
	pos = bisect_left(d15, i, lo=k)
	if pos == len(d15):
		break
	i = d15[pos]
	k = pos + 1
	pos = bisect_left(d16, i, lo=l)
	if pos == len(d16):
		break
	i = d16[pos]
	l = pos + 1
	pos = bisect_left(d23, i, lo=m)
	if pos == len(d23):
		break
	i = d23[pos]
	m = pos + 1
	pos = bisect_left(d42, i, lo=n)
	if pos == len(d42):
		break
	n = pos + 1
	cnt += 1
print(N - 6 * cnt)


a = int(input())
b = list(map(int, input().split()))
l = [4, 8, 15, 16, 23, 42]
f = [0, 0, 0, 0, 0, 0]
c = b[::-1]
kk = 0
for j in range(a):
	if c[j] == 42:
		f[-1] += 1
	else:
		m = l.index(c[j])
		if f[m + 1] > f[m]:
			f[m] += 1
print(a - min(f) * 6)


from collections import Counter
n = int(input())
aa = map(int, input().split())
cnt = Counter()
l = 0
for a in aa:
	if a == 4:
		cnt.update({4: 1})
	elif a == 8:
		if cnt[4] > 0:
			cnt.subtract({4: 1})
			cnt.update({8: 1})
		else:
			l += 1
	elif a == 15:
		if cnt[8] > 0:
			cnt.subtract({8: 1})
			cnt.update({15: 1})
		else:
			l += 1
	elif a == 16:
		if cnt[15] > 0:
			cnt.subtract({15: 1})
			cnt.update({16: 1})
		else:
			l += 1
	elif a == 23:
		if cnt[16] > 0:
			cnt.subtract({16: 1})
			cnt.update({23: 1})
		else:
			l += 1
	elif a == 42:
		if cnt[23] > 0:
			cnt.subtract({23: 1})
			cnt.update({42: 1})
		else:
			l += 1
d = dict(cnt)
d[42] = 0
l += cnt[4]
l += cnt[8] * 2
l += cnt[15] * 3
l += cnt[16] * 4
l += cnt[23] * 5
print(l)


n = int(input())
data = [4, 8, 15, 16, 23, 42]
source = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
inpu = []
read_as = input().split()
for x in read_as:
	inpu.append(int(x))
bug = 0
for x in inpu:
	if x == 4:
		source[4] += 1
		source.get(x)
	else:
		mm = data.index(x) - 1
		if source[data[mm]] <= source[x]:
			bug = bug + 1
		else:
			source[x] += 1
mm = source[42]
for x in data:
	source[x] -= mm
print(sum(source.values()) + bug)


length = int(input())
array = list(map(int, input().split()))
pattern = [4, 8, 15, 16, 23, 42]
cnt = [0] * 6
for i in range(length):
	j = pattern.index(array[i])
	if j != 0 and cnt[j - 1] != 0:
		cnt[j] = cnt[j] + 1
		cnt[j - 1] = cnt[j - 1] - 1
	elif j == 0:
		cnt[j] = cnt[j] + 1
print(length - 6 * cnt[5])


D = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
N = int(input())
A = [D[int(a)] for a in input().split()]
X = [0] * 6
for a in A:
	if a == 0:
		X[a] += 1
	elif X[a - 1]:
		X[a - 1] -= 1
		X[a] += 1
print(N - X[5] * 6)


n = int(input())
a = list(map(int, input().split()))
D = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
d = [[] for i in range(6)]
for i in range(n):
	d[D[a[i]]].append(i)
P = [0] * 6
num = 0
while True:
	if P[0] < len(d[0]):
		k = d[0][P[0]]
	else:
		break
	while P[1] < len(d[1]) and k >= d[1][P[1]]:
		P[1] += 1
		num += 1
	if P[1] < len(d[1]):
		k = d[1][P[1]]
	else:
		break
	while P[2] < len(d[2]) and k >= d[2][P[2]]:
		P[2] += 1
		num += 1
	if P[2] < len(d[2]):
		k = d[2][P[2]]
	else:
		break
	while P[3] < len(d[3]) and k >= d[3][P[3]]:
		P[3] += 1
		num += 1
	if P[3] < len(d[3]):
		k = d[3][P[3]]
	else:
		break
	while P[4] < len(d[4]) and k >= d[4][P[4]]:
		P[4] += 1
		num += 1
	if P[4] < len(d[4]):
		k = d[4][P[4]]
	else:
		break
	while P[5] < len(d[5]) and k >= d[5][P[5]]:
		P[5] += 1
		num += 1
	flag = True
	for j in range(6):
		if P[j] >= len(d[j]):
			flag = False
			break
	else:
		for j in range(6):
			P[j] += 1
	if not flag:
		break
for i in range(6):
	num += len(d[i]) - P[i]
print(num)


from sys import stdin, stdout
read = lambda : map(int, stdin.readline().split())
I = lambda : stdin.readline()
alias = {'4': 0, '8': 1, '15': 2, '16': 3, '23': 4, '42': 5}

def f1(x):
	if x in alias:
		return alias[x]
	return -1
n = int(I())
counts = [0 for i in range(6)]
arr = tuple(map(f1, stdin.readline().split()))
for i in arr:
	if i == 0:
		counts[0] += 1
	elif i > 0 and counts[i] < counts[i - 1]:
		counts[i] += 1
print(n - counts[-1] * 6)


n = int(input())
arr = list(map(int, input().split()))
d = [0 for i in range(6)]
for i in arr:
	if i == 4:
		d[0] += 1
	elif i == 8:
		if d[1] < d[0]:
			d[1] += 1
	elif i == 15:
		if d[2] < d[1]:
			d[2] += 1
	elif i == 16:
		if d[3] < d[2]:
			d[3] += 1
	elif i == 23:
		if d[4] < d[3]:
			d[4] += 1
	elif i == 42:
		if d[5] < d[4]:
			d[5] += 1
d.sort()
print(n - d[0] * 6)


n = int(input())
t = input()
t = t.split()
t = [int(x) for x in t]
T = [0, 4, 8, 15, 16, 23, 42]
val = [10000000000.0, 0, 0, 0, 0, 0, 0]
for i in t:
	idx = T.index(i)
	if val[idx - 1] > val[idx]:
		val[idx] += 1
print(n - 6 * val[6])


n = int(input())
s = input().split()
count = [0] * 6
total = 0
for i in range(0, n):
	num = int(s[i])
	if num == 4:
		count[0] = count[0] + 1
	elif num == 8:
		if count[1] < count[0]:
			count[1] = count[1] + 1
		else:
			total = total + 1
	elif num == 15:
		if count[2] < count[1]:
			count[2] = count[2] + 1
		else:
			total = total + 1
	elif num == 16:
		if count[3] < count[2]:
			count[3] = count[3] + 1
		else:
			total = total + 1
	elif num == 23:
		if count[4] < count[3]:
			count[4] = count[4] + 1
		else:
			total = total + 1
	elif num == 42:
		if count[5] < count[4]:
			count[5] = count[5] + 1
		else:
			total = total + 1
total = total + count[0] + count[1] + count[2] + count[3] + count[4] - 5 * count[5]
print(total)


num = int(input())
lst = [int(i) for i in input().split()]
ans = [0] * 6
di = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
for n in lst:
	idx = di[n]
	if 0 == idx:
		ans[idx] += 1
	elif ans[idx - 1] > 0:
		ans[idx - 1] -= 1
		ans[idx] += 1
print(num - 6 * ans[-1])


n = int(input())
a = [*map(int, input().split())]
c = [0] * 6
d = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
deletions = 0
for i in a:
	if not d[i]:
		c[d[i]] += 1
	elif c[d[i] - 1] > c[d[i]]:
		c[d[i]] += 1
	else:
		deletions += 1
m = min(c)
if c == 0:
	print(n)
else:
	for i in c:
		deletions += i - m if i > m else 0
	print(deletions)


I = lambda : map(int, input().split())
n = int(input())
l = list(I())
a = [4, 8, 15, 16, 23, 42]
d = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
for i in range(n):
	if l[i] == 4:
		d[l[i]] += 1
	else:
		for j in range(1, 6):
			if l[i] == a[j]:
				if d[a[j]] < d[a[j - 1]]:
					d[a[j]] += 1
x = 10 ** 9
for i in d:
	if d[i] < x:
		x = d[i]
xs = x * 6
print(n - xs)


n = int(input())
a = list(map(int, input().split()))
b = [4, 8, 15, 16, 23, 42]
c = [0] * 6
flag = 0
tol = n - n // 6 * 6
counter = 0
for i in range(n):
	if a[i] == 4:
		c[0] += 1
		counter = 0
	elif a[i] == 8:
		c[1] += 1
		counter = 1
	elif a[i] == 15:
		c[2] += 1
		counter = 2
	elif a[i] == 16:
		c[3] += 1
		counter = 3
	elif a[i] == 23:
		c[4] += 1
		counter = 4
	elif a[i] == 42:
		c[5] += 1
		counter = 5
	if not c[0] >= c[1] >= c[2] >= c[3] >= c[4] >= c[5]:
		flag += 1
		c[counter] -= 1
print(n - min(c) * 6)


n = int(input())
arr = list(map(int, input().split()))
for i in range(n):
	if arr[i] == 4:
		arr[i] = 1
	elif arr[i] == 8:
		arr[i] = 2
	elif arr[i] == 15:
		arr[i] = 3
	elif arr[i] == 16:
		arr[i] = 4
	elif arr[i] == 23:
		arr[i] = 5
	elif arr[i] == 42:
		arr[i] = 6
ans = 0
f = [0] * 7
for i in range(n):
	if arr[i] == 1:
		f[arr[i]] += 1
	elif f[arr[i] - 1] > 0:
		f[arr[i] - 1] -= 1
		f[arr[i]] += 1
print(n - 6 * f[6])


n = int(input())
l4 = 0
l8 = 0
l15 = 0
l16 = 0
l23 = 0
l42 = 0
k = 0
s = input()
s = s.split()
for i in range(n):
	s[i] = int(s[i])
	if s[i] == 4:
		l4 += 1
	elif s[i] == 8 and l4 > 0:
		l8 += 1
		l4 -= 1
	elif s[i] == 15 and l8 > 0:
		l15 += 1
		l8 -= 1
	elif s[i] == 16 and l15 > 0:
		l16 += 1
		l15 -= 1
	elif s[i] == 23 and l16 > 0:
		l23 += 1
		l16 -= 1
	elif s[i] == 42 and l23 > 0:
		l42 += 1
		l23 -= 1
	else:
		k += 1
print(k + l4 + l8 * 2 + l15 * 3 + l16 * 4 + l23 * 5)


from sys import stdin
inp = lambda : stdin.readline().strip()
n = int(inp())
sad = [int(x) for x in inp().split()]
x = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
y = {8: 4, 15: 8, 16: 15, 23: 16, 42: 23}
for i in sad:
	if i == 4 or x[y[i]] > x[i]:
		x[i] += 1
print(n - x[42] * 6)


n = int(input())
l = list(map(int, input().split()))
l1 = [0] * 7
for i in l:
	if i == 4:
		l1[0] += 1
	elif i == 8:
		if l1[0] > l1[1]:
			l1[1] += 1
	elif i == 15:
		if l1[1] > l1[2]:
			l1[2] += 1
	elif i == 16:
		if l1[2] > l1[3]:
			l1[3] += 1
	elif i == 23:
		if l1[3] > l1[4]:
			l1[4] += 1
	elif i == 42:
		if l1[4] > l1[5]:
			l1[5] += 1
print(n - 6 * l1[5])


required = [4, 8, 15, 16, 23, 42]

def good(seq, n):
	current = before = 0
	count = 7 * [0]
	count[0] = n
	for i in range(len(seq)):
		if seq[i] in required:
			current = required.index(seq[i]) + 1
			before = current - 1
			if count[before] > 0:
				count[before] -= 1
				count[current] += 1
	return n - count[6] * 6
n = int(input())
seq = list(map(int, input().split()))
print(good(seq, n))


n = int(input())
a = input().split()
d = {'4': 0, '8': 0, '15': 0, '16': 0, '23': 0, '42': 0}
l = ['4', '8', '15', '16', '23', '42']
for i in a:
	if i in l:
		if i == '4':
			d[i] += 1
		elif d[l[l.index(i) - 1]] > d[i]:
			d[i] += 1
print(len(a) - min(d.values()) * 6)


n = int(input())
array = input()
array = [int(x) for x in array.split(' ')]
L = [4, 8, 15, 16, 23, 42]
fill_in = {}
for num in L:
	fill_in[num] = 0
fill_in[4] = 1
res = 0
for num in array:
	if fill_in[num]:
		if num == 4:
			fill_in[8] += 1
		if num == 8:
			fill_in[num] -= 1
			fill_in[15] += 1
		if num == 15:
			fill_in[num] -= 1
			fill_in[16] += 1
		if num == 16:
			fill_in[num] -= 1
			fill_in[23] += 1
		if num == 23:
			fill_in[num] -= 1
			fill_in[42] += 1
		if num == 42:
			fill_in[num] -= 1
	else:
		res += 1
for num in [8, 15, 16, 23, 42]:
	if fill_in[num]:
		if num == 8:
			res += 1 * fill_in[num]
		if num == 15:
			res += 2 * fill_in[num]
		if num == 16:
			res += 3 * fill_in[num]
		if num == 23:
			res += 4 * fill_in[num]
		if num == 42:
			res += 5 * fill_in[num]
print(res)


n = int(input())
if n == 0:
	print(0)
else:
	k = 0
	a = 0
	b = 0
	c = 0
	d = 0
	e = 0
	line = [int(x) for x in input().split()]
	for i in line:
		if i == 4:
			a += 1
		elif i == 8:
			if a > 0:
				a -= 1
				b += 1
			else:
				k += 1
		elif i == 15:
			if b > 0:
				b -= 1
				c += 1
			else:
				k += 1
		elif i == 16:
			if c > 0:
				c -= 1
				d += 1
			else:
				k += 1
		elif i == 23:
			if d > 0:
				d -= 1
				e += 1
			else:
				k += 1
		elif i == 42:
			if e > 0:
				e -= 1
			else:
				k += 1
	print(k + a + b * 2 + c * 3 + d * 4 + e * 5)


import sys
n = int(sys.stdin.readline())
array = [int(j) for j in sys.stdin.readline().split()]
match = [4, 8, 15, 16, 23, 42]
match_dict = {i: 0 for i in match}
last_val = {match[i]: match[i - 1] for i in range(1, len(match))}
for value in array:
	if value == 4:
		match_dict[4] += 1
	elif match_dict[last_val[value]] > match_dict[value]:
		match_dict[value] += 1
print(n - match_dict[42] * 6)


n = int(input())
a = list(map(int, input().split()))
(s, d, f) = ([], {}, [4, 8, 15, 16, 23, 42])
for q1 in a:
	q = f.index(q1)
	if q == 0:
		s.append([0])
		if len(s) == 1 or s[-2][-1] != 0:
			d[1] = len(s) - 1
	elif q in d:
		s[d[q]].append(q)
		if q != len(f) - 1 and q + 1 not in d:
			d[q + 1] = d[q]
		if len(s) == d[q] + 1 or len(s[d[q] + 1]) != q:
			del d[q]
		else:
			d[q] += 1
ans = 0
for q in s:
	if len(q) == 6:
		ans += 1
	else:
		break
print(n - ans * 6)


b = [int(i) for i in '4,8,15,16,23,42'.split(',')]
n = int(input())
a = [int(i) for i in input().split()]
pos = [0] * 6
for i in a:
	if i == 4:
		pos[0] += 1
	elif pos[b.index(i) - 1] > 0:
		pos[b.index(i) - 1] -= 1
		pos[b.index(i)] += 1
f = 0
f = n - 6 * pos[5]
print(f)


n = int(input())
a = list(map(int, input().split()))
f = [4, 8, 15, 16, 23, 42]
c = [0] * 43
cnt = 0
for i in range(n):
	c[a[i]] += 1
	for j in f:
		if j < a[i]:
			if c[j] < c[a[i]]:
				c[a[i]] -= 1
				cnt += 1
				break
print(len(a) - 6 * c[42])


RI = lambda : [int(x) for x in input().strip().split()]
rw = lambda : input().strip().split()
from collections import defaultdict as df
t = int(input())
l = RI()
d = df(int)
ans = 0
for i in l:
	if i == 4:
		d[4] += 1
	elif i == 8:
		if d[4] > 0:
			d[8] += 1
			d[4] -= 1
		else:
			ans += 1
	elif i == 15:
		if d[8] > 0:
			d[15] += 1
			d[8] -= 1
		else:
			ans += 1
	elif i == 16:
		if d[15] > 0:
			d[16] += 1
			d[15] -= 1
		else:
			ans += 1
	elif i == 23:
		if d[16] > 0:
			d[23] += 1
			d[16] -= 1
		else:
			ans += 1
	elif i == 42:
		if d[23] > 0:
			d[42] += 1
			d[23] -= 1
		else:
			ans += 1
ans += d[4] + 2 * d[8] + 3 * d[15] + 4 * d[16] + 5 * d[23]
print(ans)


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def min(a, b):
	if a < b:
		return a
	else:
		return b

def max(a, b):
	if a > b:
		return a
	else:
		return b
n = int(input())
m = list(map(int, input().split()))
lost = [42, 4, 8, 15, 16, 23, 42]
cnt = [0] * 7
cnt.insert(0, 100000000)
for x in m:
	i = 1
	while i < len(lost):
		if (x == lost[i]) & (cnt[i] < cnt[i - 1]):
			cnt[i] += 1
		i += 1
print(n - 6 * cnt[6])


n = int(input())
ans = 0
a = [int(k) for k in input().split()]
c = [0] * 6
rem = 0
if n < 6:
	n
else:
	for i in range(n):
		if a[i] == 4:
			c[0] += 1
		elif a[i] == 8:
			if c[0] > c[1]:
				c[1] += 1
			else:
				rem += 1
		elif a[i] == 15:
			if c[1] > c[2]:
				c[2] += 1
			else:
				rem += 1
		elif a[i] == 16:
			if c[2] > c[3]:
				c[3] += 1
			else:
				rem += 1
		elif a[i] == 23:
			if c[3] > c[4]:
				c[4] += 1
			else:
				rem += 1
		elif a[i] == 42:
			if c[4] > c[5]:
				c[5] += 1
			else:
				rem += 1
if n < 6:
	print(n)
else:
	m = min(c)
	for i in c:
		rem += i - m
	print(rem)


n = int(input())
arr = input()
arr = arr.split(' ')
arr = [int(i) for i in arr]
inp = [0, 0, 0, 0, 0, 0]
for i in range(n):
	a = arr[i]
	if a == 42:
		a = 25
	a //= 4
	a -= 1
	if a == 0:
		inp[a] += 1
	elif inp[a] < inp[a - 1]:
		inp[a] += 1
print(n - 6 * inp[5])


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
if n <= 5:
	print(n)
	exit()
arr = [4, 8, 15, 16, 23, 42]
v = [0] * 7
res = 0
for i in range(n):
	for k in range(6):
		if a[i] != arr[k]:
			continue
		if k > 0 and v[k] == 0:
			break
		v[k + 1] += 1
		v[k] -= 1
		break
print(n - v[6] * 6)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	n = int(inp())
	help = [4, 8, 15, 16, 23, 42]
	a = lis()
	cnt = {}
	for i in range(6):
		cnt[help[i]] = 0
	ans = 0
	for i in range(0, n):
		if a[i] == 4:
			cnt[a[i]] += 1
			continue
		f = False
		for j in range(6):
			if a[i] != help[j]:
				if cnt[a[i]] == cnt[help[j]]:
					f = True
					break
			else:
				break
		if f:
			ans += 1
		else:
			cnt[a[i]] += 1
	m = 10 ** 9
	for i in cnt:
		m = min(m, cnt[i])
	for i in cnt:
		ans += max(0, cnt[i] - m)
	print(ans)
testcase(1)


n = int(input())
a = [*map(int, input().split())]
if n < 6:
	print(n)
	exit()
COUNT = [0] * 6
complete = 0
for i in a:
	if i == 4:
		COUNT[0] += 1
	elif i == 8:
		if COUNT[1] < COUNT[0]:
			COUNT[1] += 1
	elif i == 15:
		if COUNT[2] < COUNT[1]:
			COUNT[2] += 1
	elif i == 16:
		if COUNT[3] < COUNT[2]:
			COUNT[3] += 1
	elif i == 23:
		if COUNT[4] < COUNT[3]:
			COUNT[4] += 1
	elif COUNT[5] < COUNT[4]:
		COUNT[5] += 1
		complete += 1
print(n - complete * 6)


n = int(input())
A = list(map(int, input().split()))
(num4, num8, num15, num16, num23, num42) = (0, 0, 0, 0, 0, 0)
for i in range(n):
	if A[i] == 4:
		num4 += 1
	elif A[i] == 8 and num4 > num8:
		num8 += 1
	elif A[i] == 15 and num8 > num15:
		num15 += 1
	elif A[i] == 16 and num15 > num16:
		num16 += 1
	elif A[i] == 23 and num16 > num23:
		num23 += 1
	elif A[i] == 42 and num23 > num42:
		num42 += 1
print(n - num42 * 6)


n = int(input())
l = [int(i) for i in input().split()]
d = {}
t = [4, 8, 15, 16, 23, 42]
for i in t:
	d[i] = 0
nb = 0
for i in l:
	if i == 4:
		d[4] += 1
	elif i == 8:
		if d[4] > 0:
			d[4] -= 1
			d[8] += 1
		else:
			nb += 1
	elif i == 15:
		if d[8] > 0:
			d[8] -= 1
			d[15] += 1
		else:
			nb += 1
	elif i == 16:
		if d[15] > 0:
			d[15] -= 1
			d[16] += 1
		else:
			nb += 1
	elif i == 23:
		if d[16] > 0:
			d[16] -= 1
			d[23] += 1
		else:
			nb += 1
	elif i == 42:
		if d[23] > 0:
			d[23] -= 1
			d[42] += 1
		else:
			nb += 1
for i in range(len(t) - 1):
	nb += d[t[i]] * (i + 1)
print(nb)


from sys import stdin, stdout, setrecursionlimit
import threading

class Tail_Recursion_Optimization:

	def __init__(self, RECURSION_LIMIT, STACK_SIZE):
		setrecursionlimit(RECURSION_LIMIT)
		threading.stack_size(STACK_SIZE)
		return None

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		n = int(R())
		a = [int(x) for x in R().split()]
		freq = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
		i = 0
		while i < n:
			freq[a[i]] += 1
			mn = freq[4]
			for x in freq:
				freq[x] = min(mn, freq[x])
				mn = freq[x]
			i += 1
		W('%d\n' % (n - 6 * freq[42]))
		return 0

def main():
	s = SOLVE()
	s.solve()
threading.Thread(target=main).start()


n = int(input())
if n == 0:
	ar = []
else:
	ar = list(map(int, input().split()))
ind = {}
ind[4] = []
ind[8] = []
ind[15] = []
ind[16] = []
ind[23] = []
ind[42] = []
for i in range(len(ar)):
	k = ar[i]
	if k in ind:
		ind[k].append(i)
ans = 0
a = 0
b = 0
c = 0
d = 0
e = 0
f = 0
g = ind[4]
h = ind[8]
i = ind[15]
j = ind[16]
k = ind[23]
l = ind[42]
while a < len(g) and b < len(h) and (c < len(i)) and (d < len(j)) and (e < len(k)) and (f < len(l)):
	if a == len(g) or b == len(h) or c == len(i) or (d == len(j)) or (e == len(k)) or (f == len(l)):
		break
	while b < len(h) and g[a] > h[b]:
		b += 1
	if a == len(g) or b == len(h) or c == len(i) or (d == len(j)) or (e == len(k)) or (f == len(l)):
		break
	while c < len(i) and h[b] > i[c]:
		c += 1
	if a == len(g) or b == len(h) or c == len(i) or (d == len(j)) or (e == len(k)) or (f == len(l)):
		break
	while d < len(j) and i[c] > j[d]:
		d += 1
	if a == len(g) or b == len(h) or c == len(i) or (d == len(j)) or (e == len(k)) or (f == len(l)):
		break
	while e < len(k) and j[d] > k[e]:
		e += 1
	if a == len(g) or b == len(h) or c == len(i) or (d == len(j)) or (e == len(k)) or (f == len(l)):
		break
	while f < len(k) and k[e] > l[f]:
		f += 1
	if a == len(g) or b == len(h) or c == len(i) or (d == len(j)) or (e == len(k)) or (f == len(l)):
		break
	if a < len(g) and b < len(h) and (c < len(i)) and (d < len(j)) and (e < len(k)) and (f < len(l)):
		ans += 1
		a += 1
		b += 1
		c += 1
		d += 1
		e += 1
		f += 1
print(len(ar) - 6 * ans)


n = int(input())
A = input().split()
S = [0 for j in range(6)]
for i in A:
	k = int(i)
	if k == 4:
		S[0] = S[0] + 1
	if k == 8:
		if S[1] < S[0]:
			S[1] = S[1] + 1
	if k == 15:
		if S[2] < S[1]:
			S[2] = S[2] + 1
	if k == 16:
		if S[3] < S[2]:
			S[3] = S[3] + 1
	if k == 23:
		if S[4] < S[3]:
			S[4] = S[4] + 1
	if k == 42:
		if S[5] < S[4]:
			S[5] = S[5] + 1
print(n - 6 * S[5])


t = int(input())
arr = list(map(int, input().split()))
sequences = {4: 0, 8: 0, 15: 0, 16: 0, 23: 0, 42: 0}
for elem in arr:
	if elem == 4:
		sequences[elem] += 1
	if elem == 8:
		if sequences[4] > 0:
			sequences[4] -= 1
			sequences[8] += 1
	if elem == 15:
		if sequences[8] > 0:
			sequences[8] -= 1
			sequences[15] += 1
	if elem == 16:
		if sequences[15] > 0:
			sequences[15] -= 1
			sequences[16] += 1
	if elem == 23:
		if sequences[16] > 0:
			sequences[16] -= 1
			sequences[23] += 1
	if elem == 42:
		if sequences[23] > 0:
			sequences[23] -= 1
			sequences[42] += 1
ans = len(arr) - sequences[42] * 6
print(ans)


n = int(input())
A = list(map(int, input().split()))
B = [4, 8, 15, 16, 23, 42]
(p1, p2, p3, p4, p5, p6) = (0, 0, 0, 0, 0, 0)
for i in A:
	if i == 4:
		p1 += 1
	elif i == 8:
		if p1:
			p1 -= 1
			p2 += 1
	elif i == 15:
		if p2:
			p2 -= 1
			p3 += 1
	elif i == 16:
		if p3:
			p3 -= 1
			p4 += 1
	elif i == 23:
		if p4:
			p4 -= 1
			p5 += 1
	elif i == 42:
		if p5:
			p5 -= 1
			p6 += 1
print(n - 6 * p6)


import sys, math, queue, bisect
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)
n = int(input())
a = list(map(int, input().split()))
d = {4: [], 8: [], 15: [], 16: [], 23: [], 42: []}
s = [4, 8, 15, 16, 23, 42]
for i in range(n):
	d[a[i]].append(i)
for k in d:
	d[k].reverse()
ans = 0
while True:
	last = None
	pop = 0
	for si in s:
		if last == None:
			if len(d[si]) == 0:
				for k in d:
					ans += len(d[k])
					d[k] = []
				break
			last = d[si].pop()
			pop += 1
		elif len(d[si]) == 0:
			ans += pop
			break
		else:
			while len(d[si]) > 0 and last > d[si][-1]:
				ans += 1
				d[si].pop()
			if len(d[si]) == 0:
				ans += pop
				break
			else:
				last = d[si].pop()
				pop += 1
	over = True
	for k in d:
		if len(d[k]) != 0:
			over = False
	if over:
		break
print(ans)


from collections import *
a2 = [4, 8, 15, 16, 23, 42]
(n, a, ans, arr, mem) = (int(input()), list(map(int, input().split())), 0, defaultdict(int, {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}), defaultdict(int))
for i in range(n):
	if a[i] == 4:
		mem[a[i]] += 1
	elif mem[a2[arr[a[i]] - 1]]:
		mem[a2[arr[a[i]] - 1]] -= 1
		mem[a[i]] += 1
	else:
		ans += 1
for (i, j) in enumerate(a2[:-1]):
	ans += (i + 1) * mem[j]
print(ans)


N = int(input())
a = list(map(int, input().split()))
x = [4, 8, 15, 16, 23, 42]
c = [0] * 6
cnt = 0
for i in range(N):
	for j in range(6):
		if a[i] == x[j]:
			if j - 1 >= 0:
				if c[j - 1] >= 1:
					c[j] += 1
				else:
					cnt += 1
			else:
				c[j] += 1
			if j >= 1:
				if c[j - 1] > 0:
					c[j - 1] -= 1
for i in range(5, 0, -1):
	cnt += c[i - 1] * i
print(cnt)


n = int(input())
mapp = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
nums = list(map(lambda x: mapp[int(x)], input().split()))
res = [0] * 6
for i in nums:
	if i == 0:
		res[0] += 1
	elif res[i - 1] > 0:
		res[i] += 1
		res[i - 1] -= 1
print(n - res[-1] * 6)


m = int(input())
arr = [int(x) for x in input().split()]
alreadyRid = 0
four = 0
feight = 0
fefifteen = 0
fefsixteen = 0
fefstwentythree = 0
for i in range(m):
	c = arr[i]
	if c == 4:
		four += 1
	elif c == 8:
		if four == 0:
			alreadyRid += 1
		else:
			four -= 1
			feight += 1
	elif c == 15:
		if feight == 0:
			alreadyRid += 1
		else:
			feight -= 1
			fefifteen += 1
	elif c == 16:
		if fefifteen == 0:
			alreadyRid += 1
		else:
			fefifteen -= 1
			fefsixteen += 1
	elif c == 23:
		if fefsixteen == 0:
			alreadyRid += 1
		else:
			fefsixteen -= 1
			fefstwentythree += 1
	elif fefstwentythree == 0:
		alreadyRid += 1
	else:
		fefstwentythree -= 1
print(alreadyRid + four + 2 * feight + 3 * fefifteen + 4 * fefsixteen + 5 * fefstwentythree)


import sys
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil
from itertools import combinations, permutations
input = sys.stdin.readline
flush = lambda : sys.stdout.flush
ip = lambda : input().rstrip()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
n = ii()
arr = rr()
x = [-1, 4, 8, 15, 16, 23, 42]
brr = {}
crr = [0] * 7
crr[0] = float('inf')
for (i, j) in enumerate(x):
	brr[j] = i
for i in arr:
	if crr[brr[i] - 1] > crr[brr[i]]:
		crr[brr[i]] += 1
can = min(crr) * 6
print(n - can)


from sys import stdin
n = int(stdin.readline().strip())
dp = [0 for i in range(6)]
d = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}
s = list(map(int, stdin.readline().strip().split()))
for i in range(n - 1, -1, -1):
	if s[i] == 42:
		dp[5] += 1
		continue
	elif dp[d[s[i]] + 1] > dp[d[s[i]]]:
		dp[d[s[i]]] += 1
print(n - 6 * dp[0])


def reformer(x):
	if x == 4:
		return 0
	if x == 8:
		return 1
	if x == 15:
		return 2
	if x == 16:
		return 3
	if x == 23:
		return 4
	if x == 42:
		return 5
n = int(input())
ch = input()
L = [int(i) for i in ch.split()]
L2 = [0] * 6
for i in range(n):
	if reformer(L[i]) == 0:
		L2[0] += 1
	elif L2[reformer(L[i])] < L2[reformer(L[i]) - 1]:
		L2[reformer(L[i])] += 1
print(n - 6 * L2[-1])


N = int(input())
A = list(map(int, input().split(' ')))
vals = [4, 8, 15, 16, 23, 42]
count = {}
prev = {}
for v in vals:
	count[v] = 0
for i in range(1, 6):
	prev[vals[i]] = vals[i - 1]
for a in A:
	if a not in prev:
		count[a] += 1
	elif count[prev[a]] > count[a]:
		count[a] += 1
print(N - 6 * count[42])


n = int(input())
massive = [int(i) for i in input().split()]
if n < 6:
	print(n)
else:
	numbers = [4, 8, 15, 16, 23, 42]
	results = [0] * 6
	for i in range(n):
		index = numbers.index(massive[i])
		if not index:
			results[index] += 1
		else:
			results[index] += results[index] < results[index - 1]
	print(n - results[5] * 6)


n = int(input())
arr = list(map(int, input().split()))
x = [4, 8, 15, 16, 23, 42]
(cnt, res) = ([0] * 43, 0)
for i in arr:
	cnt[i] += 1
	if i == 8:
		cnt[8] = min(cnt[4], cnt[8])
	if i == 15:
		cnt[15] = min(cnt[4], cnt[8], cnt[15])
	if i == 16:
		cnt[16] = min(cnt[4], cnt[8], cnt[15], cnt[16])
	if i == 23:
		cnt[23] = min(cnt[4], cnt[8], cnt[15], cnt[16], cnt[23])
	if i == 42:
		cnt[42] = min(cnt[4], cnt[8], cnt[15], cnt[16], cnt[23], cnt[42])
	if i == 42 and min((cnt[j] for j in x)) > 0:
		for j in range(6):
			cnt[x[j]] -= 1
		res += 1
print(n - res * 6)


n = int(input())
a = list(map(int, input().split(' ')))
res = 0
start = [0] * 50
if n < 6:
	print(n)
else:
	for i in range(n):
		start[a[i]] += 1
		if a[i] == 4:
			continue
		if a[i] == 8:
			if start[8] > start[4]:
				start[8] -= 1
				res += 1
		if a[i] == 15:
			if start[15] > start[8]:
				start[15] -= 1
				res += 1
		if a[i] == 16:
			if start[16] > start[15]:
				start[16] -= 1
				res += 1
		if a[i] == 23:
			if start[23] > start[16]:
				start[23] -= 1
				res += 1
		if a[i] == 42:
			if start[42] > start[23]:
				start[42] -= 1
				res += 1
	minelem = min(start[4], start[8], start[15], start[16], start[23], start[42])
	res += start[4] - minelem
	res += start[8] - minelem
	res += start[15] - minelem
	res += start[16] - minelem
	res += start[23] - minelem
	res += start[42] - minelem
	print(res)