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. 图片选择并使用base64展示

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. gulp常用插件之gulp-filter使用

    更多gulp常用插件使用请访问:gulp常用插件汇总 gulp-filter这是一款可以把stream里的文件根据一定的规则进行筛选过滤. 更多使用文档请点击访问gulp-filter工具官网. 安装 ...

  3. 0012 基于DRF框架开发(04 序列化器的字段与选项)

    1 常用字段类型 字段 构造方式 BooleanField BooleanField() NullBooleanField NullBooleanField() CharField CharField ...

  4. IO流学习之字节流(一)

    IO流(Input/Output) 简介: 流是一种抽象概念,它代表了数据的无结构化传递.按照流的方式进行输入输出,数据被当成无结构的字节序或字符序列.从流中取得数据的操作称为提取操作,而向流中添加数 ...

  5. 字符串问题----去掉字符串中连续出现K个0的子串

    去掉字符串中连续出现K个0的子串 给定一个字符串str,和一个整数k, 如果str中正好有连续K 个'0'字符出现,把连续的 k 个 '0'去掉,返回处理后的子串. [解题思路] 1. 定义两个变量, ...

  6. 为什么重写equals方法,还必须要重写hashcode方法

    一.equals方法和hashcode的关系 根据Object.hashCode的通用约定: 如果两个对象相同(equals方法返回true),那么hashcode也相等.(图1) 如果两个对象的ha ...

  7. gitlab 备份和恢复

    前言 gitlab这个代码托管工具真是强大,很多东西都是做好了直接用的. 这里就包括备份和恢复功能. 正文 备份 我们可以直接运行此命令,来进行备份. sudo gitlab-rake gitlab: ...

  8. DFS-回溯与剪枝-C - N皇后问题

    C - N皇后问题 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上.你的任务是,对于给定的N,求出有多少种合法的放 ...

  9. ECMAScript规范中第六大基本类型 Symbol

    初步了解第六大基本类型Symbol 概述: 什么是Symbol.Symbol是一个标记,一个独一无二的记号. Symbol的出现主要是解决了以前ES5中两个问题 在属性中同名的属性会被覆盖 无法做到属 ...

  10. 通过ssh-copy-id免密码连接Linux主机

    Login Raspberry Pi without passcode via ssh-copy-id Generate public key $ ssh-keygen -t rsa Upload p ...