You are given an array aa consisting of nn integers. Each aiai is one of the six following numbers: 4,8,15,16,23,424,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,424,8,15,16,23,42.

Examples of good arrays:

  • [4,8,15,16,23,42][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][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][4,8,15,16,42,23] (the order of elements should be exactly 4,8,15,16,23,424,8,15,16,23,42);
  • [4,8,15,16,23,42,4][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][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,424,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

Copy
5
4 8 15 16 23
output

Copy
5
input

Copy
12
4 8 4 15 16 8 23 15 16 42 23 42
output

Copy
0
input

Copy
15
4 8 4 8 15 16 8 16 23 15 16 4 42 23 42
output

Copy
3

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <xfunctional>
#define ll long long
#define mod 998244353
using namespace std;
int dir[][] = { {,},{,-},{-,},{,} };
const int maxn = 1e5 + ;
const long long inf = 0x7f7f7f7f7f7f7f7f; int main()
{
vector<int> p({ , , , , , }); int n;
cin >> n;
vector<int> a(n);
for (int i = ; i < n; ++i)
{
cin >> a[i];
a[i] = lower_bound(p.begin(), p.end(), a[i]) - p.begin();
} vector<int> seq();
for (int i = ; i < n; ++i)
{
if (a[i] == )
{
++seq[];
}
else
{
if (seq[a[i] - ] > )
{
--seq[a[i] - ];
++seq[a[i]];
}
}
} cout << n - seq[] * << endl;
return ;
}

Lose it!的更多相关文章

  1. etymon word write alb pain high alt increase large agency ag lose weight fat assist out~3

        1● alb   2● write =====>rait     1● alg 2● pain   痛,疼痛           1● alt 2● high   高         1 ...

  2. Spoken English Practice(not always estimating your status in other's hearts. you will lose yourself when you live in other's look. do your best and walk on you own way.)

    绿色:连读:                  红色:略读:               蓝色:浊化:               橙色:弱读     下划线_为浊化 口语蜕变(2017/7/8) 英 ...

  3. POJ 2521:How much did the businessman lose

    How much did the businessman lose Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9965 ...

  4. g/test/s/lose/won/g

    包含字符串test的任意行商,用lose代替won

  5. Baidu set to lose leading role in digital advertising _china daily

    advertising: n,广告 Online search giant Baidu Inc is set to loset its top spot in the nation's booming ...

  6. google chrome 32 升级变更找回user agent(google chrome lose user agent)

    chrome32中user agent 找不着了?没关系,看我画的图吧.为什么是英文的,国际化嘛...

  7. Mac环境下mysql初始化密码问题--If you lose this password, please consult the section How to Reset the Root Password in the MySQL reference manual.

    个人在Mac上操作数据库,遇到的启动数据库问题的简单记录 1.苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭mysql服务(点击stop mysql server) 2.进 ...

  8. .Net Core Package lose or not match

    错误.警告的说明: 示例一: 严重性:警告 代码:MSB3106 说明 :程序集强名称“C:\Users\$(computerName)\.nuget\packages\$(packageName)\ ...

  9. unity, editorWindow lose data when enter play mode

    我写了个editorWindow,其中有个成员变量m_x,在创建editorWindow的时候为m_x赋的值,而在editorWindow的OnGUI里把m_x显示出来. 当我开着这个editorWi ...

  10. SD 一轮集训 day1 lose

    神TM有是结论题,我讨厌结论题mmp. 杨氏矩阵了解一下(建议去维基百科). 反正就是推柿子,使劲推,最后写起来有一点小麻烦,但是在草稿纸(然鹅我木有啊)上思路清晰的话还是没问题的. #include ...

随机推荐

  1. Android开发菜单以及子菜单

    package com.example.androidtest; import android.app.Activity; import android.os.Bundle; import andro ...

  2. Genymotion下载及安装(安卓虚拟机)

    Genymotion下载及安装   一.注册\登录 打开Genymotion官网,https://www.genymotion.com/ ,首先点击右上角的Sign in进行登录操作.如何登录就不细讲 ...

  3. 在MATLAB R2018b中配置VLFeat

    在MATLAB R2018b中配置VLFeat 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ VLFeat官网:http://www.vlfeat.o ...

  4. springboot里面的缓存注解

    https://blog.csdn.net/u012240455/article/details/80844361 https://lfvepclr.gitbooks.io/spring-framew ...

  5. the first week

    一.2019我国软件产业调研 2019年1-11月,全国软件和信息技术服务业规模以上企业4.03万家,累计完成软件业务收入64616亿元,同比增长15.5%. 从收入便可以看出软件产业的发展前景还是十 ...

  6. [HAOI2011] Problem b - 莫比乌斯反演

    复习一下莫比乌斯反演 首先很显然用一下容斥把它转化成求 \(ans=\sum_{i=1}^a \sum_{j=1}^b [{gcd(i,j)=d}]\) 我们可以定义 f(d) 和 F(d) 如下: ...

  7. 《JavaScript ES6 函数式编程入门经典》--推荐指数⭐⭐⭐

    这本书比较基础认真看完再自己写点demo一个双休日就差不多, 总体来说看完还是有收获的,会激起一些你对函数编程的兴趣 主要目录如下: 第1章 函数式编程简介 11.1 什么是函数式编程?为何它重要 1 ...

  8. 风变编程笔记(二)-Python爬虫精进

    第0关  认识爬虫 1. 浏览器的工作原理首先,我们在浏览器输入网址(也可以叫URL),然后浏览器向服务器传达了我们想访问某个网页的需求,这个过程就叫做[请求]紧接着,服务器把你想要的网站数据发送给浏 ...

  9. linux常用命令和字符串乱码

    top :动态实时显示cpu.内存.进程等使用情况(类似windows下的任务管理器) ps aux 查看所有进程 ps aux|grep java 查看java进程 kill -9 进程号 :强制杀 ...

  10. tp3.2框架关闭日志记录

    在config.php中阿计入如下配置: 'LOG_RECORD' => false, // 默认不记录日志 'LOG_TYPE' => 'File', // 日志记录类型 默认为文件方式 ...