Language: C++

#include <cstdio>
#include <algorithm>
#define INF (500000)
using namespace std;

int array[20000];

int main()
{
	int N;
	while (scanf("%d", &N), N){
		memset(array, 0, sizeof(array));
		
		for (int i = 1; i <= N; i++){
			scanf("%d", &array[i]);
		}
		
		int mini = INF;
		
		for (int i = 1; i <= N; i++){
			for (int j = 0; j < 2; j++){
				array[i] = array[i] % 3 + 1;
				
				int u = i;
				int d = i;
				int color = array[i];
				int cnt = 4;
				int sum = 0;
				
				while (cnt >= 4) {
					if (sum == 0){
						cnt = 1;
					}
					else {
						cnt = 0;
					}
					
					if (array[d + 1] == 0){
						break;
					}
					
					color = array[d + 1];
					
					while (array[u - 1] == color){
						u--;
						cnt++;
					}
					while (array[d + 1] == color){
						d++;
						cnt++;
					}
					
					if (cnt >= 4){
						sum += cnt;
					}
					else {
						break;
					}
				}
				
				mini = min(mini, N - sum);
			}
			
			array[i] = array[i] % 3 + 1;
		}
		
		printf("%d\n", mini);
	}
	
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:24: error: reference to 'array' is ambiguous
   12 |                 memset(array, 0, sizeof(array));
      |                        ^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:6:5: note:                 'int array [20000]'
    6 | int array[20000];
      |     ^~~~~
a.cc:12:41: error: reference to 'array' is ambiguous
   12 |                 memset(array, 0, sizeof(array));
      |                                         ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:6:5: note:                 'int array [20000]'
    6 | int array[20000];
      |     ^~~~~
a.cc:12:17: error: 'memset' was not declared in this scope
   12 |                 memset(array, 0, sizeof(array));
      |                 ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include <algorithm>
  +++ |+#include <cstring>
    3 | #define INF (500000)
a.cc:15:38: error: reference to 'array' is ambiguous
   15 |                         scanf("%d", &array[i]);
      |                                      ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:6:5: note:                 'int array [20000]'
    6 | int array[20000];
      |     ^~~~~
a.cc:22:33: error: reference to 'array' is ambiguous
   22 |                                 array[i] = array[i] % 3 + 1;
      |                                 ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:6:5: note:                 'int array [20000]'
    6 | int array[20000];
      |     ^~~~~
a.cc:22:44: error: reference to 'array' is ambiguous
   22 |                                 array[i] = array[i] % 3 + 1;
      |                                            ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:6:5: note:                 'int array [20000]'
    6 | int array[20000];
      |     ^~~~~
a.cc:26:45: error: reference to 'array' is ambiguous
   26 |                                 int color = array[i];
      |                                             ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:6:5: note:                 'int array [20000]'
    6 | int array[20000];
      |     ^~~~~
a.cc:38:45: error: reference to 'array' is ambiguous
   38 |                                         if (array[d + 1] == 0){
      |                                             ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:6:5: note:                 'int array [20000]'
    6 | int array[20000];
      |     ^~~~~
a.cc:42:49: error: reference to 'array' is ambiguous
   42 |                                         color = array[d + 1];
      |                                                 ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:6:5: note:                 'int array [20000]'
    6 | int array[20000];
      |     ^~~~~
a.cc:44:48: error: reference to 'array' is ambiguous
   44 |                                         while (array[u - 1] == color){
      |                                                ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:6:5: note:                 'int array [20000]'
    6 | int array[20000];
      |     ^~~~~
a.cc:48:48: error: reference to 'array' is ambiguous
   48 |                                         while (array[d + 1] == color){
      |                                                ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:6:5: note:                 'int array [20000]'
    6 | int array[20000];
      |     ^~~~~
a.cc:64:25: error: reference to 'array' is ambiguous
   64 |                         array[i] = array[i] % 3 + 1;
      |                         ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:6:5: note:                 'int array [20000]'
    6 | int array[20000];
      |     ^~~~~
a.cc:64:36: error: reference to 'array' is ambiguous
   64 |                         array[i] = array[i] % 3 + 1;
      |                                    ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:6:5: note:                 'int array [20000]'
    6 | int array[20000];
      |     ^~~~~