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
[{"code": "#!/usr/bin/env python\nn = int(input())\na = list(map(int, input().split()))\nk = [None, 4, 8, 15, 16, 23, 42]\ns = [n, 0, 0, 0, 0, 0, 0]\nfor ai in a:\n    for i in range(6, 0, -1):\n        if ai == k[i] and s[i - 1] > 0:\n            s[i] += 1; s[i - 1] -= 1\n            break\nprint(n - 6 * s[-1])\n", "passed": true, "time": 0.14, "memory": 14324.0, "status": "done"}, {"code": "from sys import stdin\nn=int(stdin.readline().strip())\ndp=[0 for i in range(6)]\nd={4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}\ns=list(map(int,stdin.readline().strip().split()))\nfor i in range(n-1,-1,-1):\n    if s[i]==42:\n        dp[5]+=1\n        continue\n    elif dp[d[s[i]]+1]>dp[d[s[i]]]:\n        dp[d[s[i]]]+=1\nprint(n-6*dp[0])\n", "passed": true, "time": 0.15, "memory": 14192.0, "status": "done"}, {"code": "n=int(input())\nl1=list(map(int,input().split()))\nx=[4,8,15,16,23,42]\ncount=[0]*6\nfor item in l1:\n    if item==4:\n        count[0]+=1\n    elif item==8:\n        if count[0]>count[1]:\n            count[1]+=1\n    elif item==15:\n        if count[1]>count[2]:\n            count[2]+=1\n    elif item==16:\n        if count[2]>count[3]:\n            count[3]+=1\n    elif item==23:\n        if count[3]>count[4]:\n            count[4]+=1\n    elif item==42:\n        if count[4]>count[5]:\n            count[5]+=1\nprint(n-6*count[5])\n", "passed": true, "time": 0.23, "memory": 14272.0, "status": "done"}, {"code": "n = int(input())\na = [int(s) for s in input().split(' ')]\ncol = 0\nb = [0, 0, 0, 0, 0, 0]\nfor el in a:\n    if el == 4:\n        b[0] += 1\n    elif el == 8:\n        if b[0] > 0:\n            b[0] -= 1\n            b[1] += 1\n        else:\n            col += 1\n    elif el == 15:\n        if b[1] > 0:\n            b[1] -= 1\n            b[2] += 1\n        else:\n            col += 1\n    elif el == 16:\n        if b[2] > 0:\n            b[2] -= 1\n            b[3] += 1\n        else:\n            col += 1\n    elif el == 23:\n        if b[3] > 0:\n            b[3] -= 1\n            b[4] += 1\n        else:\n            col += 1\n    elif el == 42:\n        if b[4] > 0:\n            b[4] -= 1\n            b[5] += 1\n        else:\n            col += 1\n    else:\n        col += 1\ncol += b[0] + 2*b[1] + 3*b[2] + 4*b[3] + 5*b[4]\nprint(col)", "passed": true, "time": 0.14, "memory": 14188.0, "status": "done"}, {"code": "from collections import Counter\n\nn = int(input().strip())\nnums = list(map(int, input().strip().split()))\n\nres = 0\nstate = []\ncounter = Counter()\nprev = {\n    8: 4,\n    15: 8,\n    16: 15,\n    23: 16,\n    42: 23,\n}\ngood_nums = [4, 8, 15, 16, 23, 42]\n\nfor i, num in enumerate(nums):\n    if num == 4:\n        counter[num] += 1\n    elif counter[num] < counter[prev[num]]:\n        counter[num] += 1\n        if num == 42:\n            for good_num in good_nums:\n                counter[good_num] -= 1\n    else:\n        res += 1\n\nres += sum(counter.values())\n\nprint(res)", "passed": true, "time": 1.67, "memory": 14260.0, "status": "done"}, {"code": "n = int(input())   \ncnt = {i: 0 for i in range(1, 7)}\ncnt[0] = float('inf')\nf = {x: i + 1 for i, x in enumerate((4, 8, 15, 16, 23, 42))}\nfor e in map(int, input().split()):\n    e = f[e]\n    if cnt[e - 1] > 0:\n        cnt[e] += 1\n        cnt[e - 1] -= 1\nprint(n - 6 * cnt[6])", "passed": true, "time": 0.22, "memory": 14432.0, "status": "done"}, {"code": "D = {4:0, 8:1, 15:2, 16:3, 23:4, 42:5}\nN = int(input())\nA = [D[int(a)] for a in input().split()]\nX = [0] * 6\nfor a in A:\n    if a == 0:\n        X[a] += 1\n    else:\n        if X[a-1]:\n            X[a-1] -= 1\n            X[a] += 1\nprint(N-X[5]*6)\n", "passed": true, "time": 0.16, "memory": 14368.0, "status": "done"}, {"code": "n = int(input())\nkol = [0, 0, 0, 0, 0, 0]\nind = [4, 8, 15, 16, 23, 42]\ndelete = 0\nfor i in map(int,input().split()):\n    for j in range(6):\n        if ind[j] == i:\n            cur = j\n            break\n    if cur == 0:\n        kol[0] += 1\n    else:\n        if kol[cur-1] != 0:\n            kol[cur-1] -= 1\n            kol[cur] += 1\n        else:\n            delete += 1\nprint(delete + kol[0] + kol[1]*2 + kol[2]*3 + kol[3]*4 + kol[4]*5)", "passed": true, "time": 0.14, "memory": 14192.0, "status": "done"}, {"code": "def main():\n    n = int(input())\n    a = [int(i) for i in input().split()]\n    used = [0 for i in range(n)]\n    sh = [4, 8, 15, 16, 23, 42]\n    time = 0\n    arr = [0 for i in range(6)]\n    for i in range(n):\n        if a[i] == sh[0]:\n            arr[0] += 1\n        elif a[i] == sh[1]:\n            if arr[0] > 0:\n                arr[0] -= 1\n                arr[1] += 1\n        elif a[i] == sh[2]:\n            if arr[1] > 0:\n                arr[1] -= 1\n                arr[2] += 1\n        elif a[i] == sh[3]:\n            if arr[2] > 0:\n                arr[2] -= 1\n                arr[3] += 1\n        elif a[i] == sh[4]:\n            if arr[3] > 0:\n                arr[3] -= 1\n                arr[4] += 1\n        elif a[i] == sh[5]:\n            if arr[4] > 0:\n                arr[4] -= 1\n                arr[5] += 1\n    print(n - (arr[-1] * 6))\n\n\nmain()\n", "passed": true, "time": 0.15, "memory": 14392.0, "status": "done"}, {"code": "n = int(input())\narr = list(map(int, input().split()))\n_4, _8, _15, _16, _23, _42 = 0, 0, 0, 0, 0, 0\n\nfor i in arr:\n  if i == 4:\n    _4 += 1\n  \n  if i == 8 and _4 > _8:\n    _8 += 1\n\n\n  elif i == 15 and _8 > _15:\n    _15 += 1\n\n  elif i == 16 and _15 > _16:\n    _16 += 1\n\n  elif i == 23 and _16 > _23:\n    _23 += 1\n\n  elif i == 42 and _23 > _42:\n    _42 += 1\n\nprint(n - _42 * 6)\n", "passed": true, "time": 0.18, "memory": 14288.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\n\nn=int(input())\nA=list(map(int,input().split()))\n\nB=[]\nC=[]\nD=[]\nE=[]\nF=[]\nG=[]\n\nfor i in range(n):\n    if A[i]==4:\n        B.append(i)\n\n    if A[i]==8:\n        C.append(i)\n\n    if A[i]==15:\n        D.append(i)\n\n    if A[i]==16:\n        E.append(i)\n\n    if A[i]==23:\n        F.append(i)\n\n    if A[i]==42:\n        G.append(i)\n\nNOW=0\nBi=0\nCi=0\nDi=0\nEi=0\nFi=0\nGi=0\n\nANS=0\n\nwhile True:\n    \n    for b in range(Bi,len(B)):\n        NOW=B[b]\n        Bi=b+1\n        break\n    else:\n        break\n\n    #print(\"!\")\n\n    for c in range(Ci,len(C)):\n        if C[c]>=NOW:\n            NOW=C[c]\n            Ci=c+1\n            break\n    else:\n        break\n\n    for d in range(Di,len(D)):\n        if D[d]>=NOW:\n            NOW=D[d]\n            Di=d+1\n            break\n    else:\n        break\n\n    for e in range(Ei,len(E)):\n        if E[e]>=NOW:\n            NOW=E[e]\n            Ei=e+1\n            break\n    else:\n        break\n\n    for f in range(Fi,len(F)):\n        if F[f]>=NOW:\n            NOW=F[f]\n            Fi=f+1\n            break\n    else:\n        break\n\n    for g in range(Gi,len(G)):\n        if G[g]>=NOW:\n            NOW=G[g]\n            Gi=g+1\n            break\n    else:\n        break\n\n    ANS+=6\n\nprint(len(A)-ANS)\n\n    \n", "passed": true, "time": 0.14, "memory": 14192.0, "status": "done"}, {"code": "input() # discard n\nnum = [4,8,15,16,23,42]\nprev = {i:j for i,j in zip(num[1:], num)}\nc = {v:0 for v in num}\nn = 0\nfor a in map(int, input().split()):\n    #print('before', a, c)\n    if a == num[0]: # first\n        c[a] += 1\n    else:\n        if c[prev[a]]:\n            c[prev[a]] -= 1\n            if a != num[-1]: c[a] += 1\n        else: n += 1 # waste\n    #print('after', a, c)\n\n#print(c)\nfor i,v in enumerate(num):\n    #print(i,v,c[v])\n    n += (i+1)*c[v]\n\nprint(n)\n", "passed": true, "time": 0.14, "memory": 14292.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\n\ng = [0 for i in range(43)]\nans = 0\n\nfor i in a:\n    if i == 4:\n        g[4] += 1\n    elif i == 8:\n        if g[4] > 0:\n            g[4] -= 1\n            g[8] += 1\n        else:\n            ans += 1\n    elif i == 15:\n        if g[8] > 0:\n            g[8] -= 1\n            g[15] += 1\n        else:\n            ans += 1\n    elif i == 16:\n        if g[15] > 0:\n            g[15] -= 1\n            g[16] += 1\n        else:\n            ans += 1\n    elif i == 23:\n        if g[16] > 0:\n            g[16] -= 1\n            g[23] += 1\n        else:\n            ans += 1\n    elif i == 42:\n        if g[23] > 0:\n            g[23]-=1\n        else:\n            ans += 1\n    else:\n        ans += 1\nans += (g[4] + 2*g[8] + 3*g[15] + 4*g[16]+ 5*g[23])\nprint(ans)", "passed": true, "time": 0.14, "memory": 14164.0, "status": "done"}, {"code": "n = int(input())\ns= list(map(int,input().split()))\ncount = [0]*6\nfor temp in s:\n    if temp==4:\n        count[0]+=1\n    elif temp==8 and count[0]>count[1]:\n        count[1]+=1\n    elif temp==15 and count[1]>count[2]:\n        count[2]+=1\n    elif temp==16 and count[2]>count[3]:\n        count[3]+=1\n    elif temp==23 and count[3]>count[4]:\n        count[4]+=1\n    elif temp==42 and count[4]>count[5]:\n        count[5]+=1\n    else:\n        pass\n#print(count)\nout = n - 6*min(count)\nprint(out)", "passed": true, "time": 0.15, "memory": 14356.0, "status": "done"}, {"code": "n = int(input())\na = [int(x) for x in input().split()]\nexist = [4,8,15,16,23,42]\ns = set(exist)\nwaiting = [0] * 6\nans = 0\nfor x in a:\n    if x not in s:\n        ans += 1\n        continue\n    if x == 4:\n        waiting[0] += 1\n        continue\n    pos = exist.index(x)\n    if waiting[pos - 1] == 0:\n        ans += 1\n        continue\n    waiting[pos - 1] -= 1\n    if x != 42:\n        waiting[pos] += 1\n# print(waiting)\nfor i in range(6):\n    ans += (i + 1) * waiting[i]\nprint(ans)\n    \n", "passed": true, "time": 0.15, "memory": 14148.0, "status": "done"}, {"code": "n = int(input())\nx = [4, 8, 15, 16, 23, 42]\nr = [0] * len(x)\nz = 0\nfor v in map(int, input().split()):\n    i = x.index(v)\n    if not i or r[i-1] > r[i]:\n        r[i] += 1\n    else:\n        z += 1\nz += sum(v-r[-1] for v in r)\nprint(z)\n", "passed": true, "time": 0.14, "memory": 14064.0, "status": "done"}, {"code": "n = int(input())\nl = list(map(int, input().split()))\nx = [4,8,15,16,23,42]\n# if(n == 0):\n# \tprint(0)\n# elif(n<6):\n# \tprint(n)\n# elif(n==6):\n# \tif(l==x):\n# \t\tprint(0)\n# \telse:\n# \t\tprint(n)\n# else:\nd = {}\nfor i in x:\n\td[i] = 0\ncount = 0\nfor i in range(n):\n\tif(l[i]==4):\n\t\td[4]+=1\n\telif(l[i]==8):\n\t\tif(d[4]==0):\n\t\t\tcount+=1\n\t\telse:\n\t\t\td[4]-=1\n\t\t\td[8]+=1\n\telif(l[i]==15):\n\t\tif(d[8]==0):\n\t\t\tcount+=1\n\t\telse:\n\t\t\td[8]-=1\n\t\t\td[15]+=1\n\telif(l[i]==16):\n\t\tif(d[15]==0):\n\t\t\tcount+=1\n\t\telse:\n\t\t\td[15]-=1\n\t\t\td[16]+=1\n\telif(l[i]==23):\n\t\tif(d[16]==0):\n\t\t\tcount+=1\n\t\telse:\n\t\t\td[16]-=1\n\t\t\td[23]+=1\n\telse:\n\t\tif(d[23]==0):\n\t\t\tcount+=1\n\t\telse:\n\t\t\td[23]-=1\n\t\t\td[42]+=1\ncount+= d[4] + (2*d[8]) + (3*d[15]) + (4*d[16]) + (5*d[23])\nprint(count)", "passed": true, "time": 0.14, "memory": 14292.0, "status": "done"}, {"code": "import sys\nfrom collections import Counter\n\ndef input():\n    return sys.stdin.readline().strip()\n\ndef dinput():\n    return int(input())\n\ndef tinput():\n    return input().split()\n\ndef rinput():\n    return map(int, tinput())\n\ndef main():\n    n = int(input())\n    aleonov = list(rinput())\n    rt = [4, 8, 15, 16, 23, 42]\n    leonov = []\n    for i in range(6):\n        leonov.append(0)\n    for i in range(n):\n        if aleonov[i] == rt[0]:\n            leonov[0] += 1\n        elif aleonov[i] == rt[1]:\n            if leonov[0] > 0:\n                leonov[0] -= 1\n                leonov[1] += 1\n        elif aleonov[i] == rt[2]:\n            if leonov[1] > 0:\n                leonov[1] -= 1\n                leonov[2] += 1\n        elif aleonov[i] == rt[3]:\n            if leonov[2] > 0:\n                leonov[2] -= 1\n                leonov[3] += 1\n        elif aleonov[i] == rt[4]:\n            if leonov[3] > 0:\n                leonov[3] -= 1\n                leonov[4] += 1\n        elif aleonov[i] == rt[5]:\n            if leonov[4] > 0:\n                leonov[4] -= 1\n                leonov[5] += 1\n    print(n - (leonov[-1] * 6))\n\n\nmain()", "passed": true, "time": 0.15, "memory": 14296.0, "status": "done"}, {"code": "for _ in range(1):\n    n=int(input())\n    a=list(map(int,input().split()))\n    d={}\n    b=[4,8,15,16,23,42]\n    c=[0]*50\n    for i in a:\n        if i==4:\n            c[i]+=1\n        elif c[b[b.index(i) - 1]]>0:\n            c[b[b.index(i) - 1]]-=1\n            c[i]+=1\n            \n    print(n- (c[42])*6)\n", "passed": true, "time": 0.15, "memory": 14148.0, "status": "done"}, {"code": "n = int(input())\narr = list(map(int,input().split()))\nans = 0\ncounter = [0] * 6\nd = {4:0,8:1,15:2,16:3,23:4,42:5}\n\nfor a in arr:\n    index = d[a]\n    counter[index] += 1\n    if index > 0 and counter[index] > counter[index-1]:\n        counter[index] -= 1\n        ans += 1\n        \nans += sum(counter) - counter[5] * 6\n\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14180.0, "status": "done"}, {"code": "'''input\n15\n4 8 4 8 15 16 8 16 23 15 16 4 42 23 42\n'''\n# its just a simulation\nfrom sys import stdin, setrecursionlimit\nimport heapq\n\n\n\ndef refine(arr):\n\taux = []\n\tfor i in range(len(arr)):\n\t\tif arr[i] in [4, 8, 15, 16, 23, 42]:\n\t\t\taux.append(arr[i])\n\treturn aux\n\n# main starts\nn = int(stdin.readline().strip())\narr = list(map(int, stdin.readline().split()))\narr = refine(arr)\nmydict = dict()\nmydict[4] = 0; mydict[8] = 0; mydict[15] = 0; mydict[16] = 0;\nmydict[23] = 0; mydict[42] = 0\n\nfor i in range(len(arr)):\n\tif arr[i] == 4:\n\t\tmydict[4] += 1\n\telif arr[i] == 8:\n\t\tif mydict[4] >= mydict[8] + 1:\n\t\t\tmydict[8] += 1\n\telif arr[i] == 15:\n\t\tif mydict[8] >= mydict[15] + 1:\n\t\t\tmydict[15] += 1\n\n\telif arr[i] == 16:\n\t\tif mydict[15] >= mydict[16] + 1:\n\t\t\tmydict[16] += 1\n\telif arr[i] == 23:\n\t\tif mydict[16] >= mydict[23] + 1:\n\t\t\tmydict[23] += 1\n\telif arr[i] == 42:\n\t\tif mydict[23] >= mydict[42] + 1:\n\t\t\tmydict[42] += 1\n\nprint(n - mydict[42] * 6 )\n", "passed": true, "time": 0.15, "memory": 14304.0, "status": "done"}, {"code": "from collections import defaultdict\n\nMEMBERS = (4, 8, 15, 16, 23, 42)\nprogress = {4: 0, 8: 1, 15: 2, 16: 3, 23: 4, 42: 5}\n\nn = int(input())\na = list(map(int, input().split()))\nidx = []\ncounts = defaultdict(int)\nfor num in a:\n    if progress[num] == 0:\n        counts[0] += 1\n    else:\n        if counts[progress[num] - 1] > 0:\n            counts[progress[num] - 1] -= 1\n            counts[progress[num]] += 1\nprint(n - counts[5] * 6)\n", "passed": true, "time": 0.14, "memory": 14148.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int,input().split()))\n\nans = 0\n\nchk = {4:0,8:1,15:2,16:3,23:4,42:5}\n\nct = [0]*6\nfor i in a:\n    if i not in [4,8,15,16,23,42]:\n       ans+=1\nfor i in a:\n    if i in [4,8,15,16,23,42]:\n       if i==4:\n          ct[0]+=1\n       else:\n           if ct[chk[i]-1]>ct[chk[i]]:\n              ct[chk[i]]+=1\n           else:\n              ans+=1\nans1 = ct[5]\nfor i in ct:\n    ans += (i-ans1)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14264.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int,input().split()))\ndp = [0,0,0,0,0,0]\nfor k in range(n):\n    if a[k] == 4:\n        dp[0] += 1\n    elif a[k] == 8:\n        dp[1] = min(dp[0],dp[1]+1)\n    elif a[k] == 15:\n        dp[2] = min(dp[1],dp[2]+1)\n    elif a[k] == 16:\n        dp[3] = min(dp[2],dp[3]+1)\n    elif a[k] == 23:\n        dp[4] = min(dp[3],dp[4]+1)\n    else:\n        dp[5] = min(dp[4],dp[5]+1)\n\nprint(n-6*dp[5])\n", "passed": true, "time": 0.14, "memory": 14120.0, "status": "done"}]