HTML & JS
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include <string>
#include <iomanip>

using namespace std;

#define f(i,x,n) for(i=x;i<n;i++)

typedef long long ll;


int main()
{
	// ios_base::sync_with_stdio(false); 
 //    cin.tie(NULL); cout.tie(NULL);
	ll i,j,t,n,a,b,c,d,e,f;
	cin>>n;
	if(n==0)
	{
		cout<<"0";
		return 0;
	}
		map<ll,vector<ll> >m;
		ll count=0;
		ll arr[n];
		f(i,0,n)
			cin>>arr[i];
		m[4] = {};
		m[8] = {};
		m[15] = {};
		m[16] = {};
		m[23] = {};
		m[42] = {};
		for(i=n-1;i>=0;i--)
			m[arr[i]].push_back(i);
		

		a=m[4].size()-1;
		b=m[8].size()-1;
		c=m[15].size()-1;
		d=m[16].size()-1;
		e=m[23].size()-1;
		f=m[42].size()-1;
		//cout<<a<<b<<c<<d<<e<<f<<"\n";
		while(a>=0 && b>=0 && c>=0 && d>=0 && e>=0 && f>=0 )
		{
			//cout<<"in\n";
			if(m[4][a]<m[8][b])
			{
				if(m[8][b]<m[15][c])
				{
					if(m[15][c]<m[16][d])
					{
						if(m[16][d]<m[23][e])
						{
							if(m[23][e]<m[42][f])
							{
								count++;
								a-=1;
								b-=1;
								c-=1;
								d-=1;
								e-=1;
								f-=1;
							}
							else
								f-=1;
						}
						else
							e-=1;
					}
					else
						d-=1;
				}
				else
					c-=1;
				
			}
			else
				b-=1;
		}
		n=n-count*6;
		cout<<n;

	
    

	return 0;
}

Generated URL:

Output:

5
Report Bug