当前位置:   article > 正文

ZCMU 暑期训练四---J题_you are given two arrays of integers a1,…,an and b

you are given two arrays of integers a1,…,an and b1,…,bm.your task is to f

You are given an array aa consisting of nn integers. Each aiai 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 kk is called good if kk is divisible by 66 and it is possible to split it into k6k6 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 66);
  • [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 nn (1≤n≤5⋅1051≤n≤5⋅105) — the number of elements in aa.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (each aiai is one of the following numbers: 4,8,15,16,23,42), where aiai is the ii-th element of aa.

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

【题解】

找到有几组4,8,15,16,23,42就可以了 然后总数减去组数*6;

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn=1e5+10;
  4. int main()
  5. {
  6. int n;
  7. scanf("%d",&n);
  8. vector<int>a(n);
  9. for(int i=0;i<n;i++)
  10. {
  11. int v;
  12. scanf("%d",&v);
  13. if(v==4)a[i]=1;
  14. if(v==8)a[i]=2;
  15. if(v==15)a[i]=3;
  16. if(v==16)a[i]=4;
  17. if(v==23)a[i]=5;
  18. if(v==42)a[i]=6;
  19. }
  20. vector<int>cur(7);
  21. cur[0]=n;
  22. for(int i=0;i<n;i++)
  23. {
  24. if(cur[a[i]-1]>0)
  25. {
  26. ++cur[a[i]];
  27. --cur[a[i]-1];
  28. }
  29. }
  30. int ans=n-6*cur[6];
  31. printf("%d",ans);
  32. return 0;
  33. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/745260
推荐阅读
相关标签
  

闽ICP备14008679号