Language: C++

#include <cstdio>
#include <vector>
#include <algorithm>

#pragma warning(disable : 4996)

using namespace std;

int main()
{
	while (true)
	{
		int N, A; unsigned MAX = 15000;

		vector<int> D;

		scanf("%d", &N);

		for (int i = 0; i < N; i++)
		{
			scanf("%d", &A);

			D.push_back(A);
		}

		for (int i = 0; i < N; i++)
		{
			for (int j = 1; j <= 3; j++)
			{
				if (D[i] != j)
				{
					vector<int> E(D.begin(), D.end());

					E[i] = j;

					for (int k = 0; k < E.size() - 3; k++)
					{

					loop:;

						if (E.size() <= 3)
						{
							break;
						}

						if (E[k] == E[k + 1] && E[k + 1] == E[k + 2] && E[k + 2] == E[k + 3])
						{
							for (int l = 0; l < 3; l++)
							{
								E.erase(E.begin() + k);
							}

							while (k < E.size() - 1)
							{
								if (E[k] == E[k + 1])
								{
									E.erase(E.begin() + k);
								}
								else
								{
									break;
								}
							}

							if (k < E.size())
							{
								E.erase(E.begin() + k);
							}

							k = 0;

							goto loop;
						}
					}

					MAX = min(E.size(), MAX);
				}
			}
		}

		printf("%d\n", MAX);
	}

	return 0;
}

// Time : O( 3n ^ 3 )

Compiler output:
a.cc: In function 'int main()':
a.cc:76:50: error: no matching function for call to 'min(std::vector<int>::size_type, unsigned int&)'
   76 |                                         MAX = min(E.size(), MAX);
      |                                               ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:62,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:76:50: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'unsigned int')
   76 |                                         MAX = min(E.size(), MAX);
      |                                               ~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:76:50: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
   76 |                                         MAX = min(E.size(), MAX);
      |                                               ~~~^~~~~~~~~~~~~~~