///Bismillahir Rahmanir Rahim
///Author: Tanvir Ahmmad
///CSE,Islamic University,Bangladesh
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<iterator>
#include <functional> ///sort(arr,arr+n,greater<int>()) for decrement of array
/*every external angle sum=360 degree
angle find using polygon hand(n) ((n-2)*180)/n*/
///Floor[Log(b) N] + 1 = the number of digits when any number is represented in base b
using namespace std;
typedef long long ll;
int main()
{
ll n,check[]= {4,8,15,16,23,42},flag=0,base=0,num,last_8=0,last_15=0,last_16=0,last_23=0,last_42=0;
vector<ll>vec[8];
cin>>n;
for(ll i=0; i<n; i++)
{
cin>>num;
for(ll j=0; j<6; j++)
if(num==check[j])
vec[j].push_back(i);
}
for(ll i=0; i<vec[0].size() && flag==0; i++)
{
ll cur=vec[0][i],cnt=0;
for(ll j=last_8 ; j<vec[1].size(); j++)
{
if(cur<vec[1][j])
{
cur=vec[1][j];
last_8=j+1;
cnt++;
break;
}
if(j+1==vec[1].size())
flag=1;
}
for(ll j=last_15; j<vec[2].size(); j++)
{
if(cur<vec[2][j])
{
cur=vec[2][j];
last_15=j+1;
cnt++;
break;
}
if(j+1==vec[2].size())
flag=1;
}
for(ll j=last_16; j<vec[3].size(); j++)
{
if(cur<vec[3][j])
{
cur=vec[3][j];
last_16=j+1;
cnt++;
break;
}
if(j+1==vec[3].size())
flag=1;
}
for(ll j=last_23; j<vec[4].size(); j++)
{
if(cur<vec[4][j])
{
cur=vec[4][j];
last_23=j+1;
cnt++;
break;
}
if(j+1==vec[4].size())
flag=1;
}
for(ll j=last_42; j<vec[5].size(); j++)
{
if(cur<vec[5][j])
{
cur=vec[5][j];
last_42=j+1;
cnt++;
break;
}
if(j+1==vec[1].size())
flag=1;
}
if(cnt==5)
base++;
}
cout<<n-(base*6)<<endl;
return 0;
}
///Alhamdulillah
Problem Link:https://codeforces.com/problemset/problem/1176/C
Comments
Post a Comment