Language: C++

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

using namespace std;

#define PII pair<int,int>

int x[10020];
int N;

vector< PII > S;

void pa(){
	for(int i = 0; i < N; i++){
		printf("%s",x[i]==1?"Ô":x[i]==2?"Â":"©");
	}puts("");
}

int func(){
	int now = 1;
	int ret = 0;
	PII t;
	
	for(int i = 0; i < N ; i++){
		if(x[i] == x[i+1]){
			now++;
		}else{
			if(S.size() > 0){
//				printf("%sª%2dÂ\n", S.top().first==1?"Ô":S.top().first==2?"Â":"©", S.top().second);
				if(now > 3){
					
				}else if(S.top().first == x[i] && S.top().second + now > 3){
//					printf("popA\n");
					S.pop();
				}else{
					t.first = x[i];
					t.second = now;
					S.push(t);
				}
			}else{
				PII t;
				t.first = x[i];
				t.second = now;
				S.push(t);
			}
			now = 1;
		}
	}
	/*
	if(x[N-1] == S.top().first && S.top().second > 2){
		S.pop();
	}else {
		S.push(PII(x[N-1],1));
	}
	*/
//	printf("size() = %d\n",S.size());
	int size = S.size();
	for(int i = 0; i < size; i++){
//		printf("%sª%2dÂ\n", S.top().first==1?"Ô":S.top().first==2?"Â":"©", S.top().second);
		ret += S.top().second;
		S.pop();
	}
//	printf("return %2d\n",ret);
	return ret;
}
				

int main(void){
	while(scanf("%d", &N) && N != 0){
		int M=2000000000;
		
		for(int i = N-1; i >= 0; i--){
			scanf("%d", &x[i]);
		}
		x[N] = 0;
//		pa();
		for(int i = 0; i < N; i++){
			for(int j = 1; j < 4; j++){
				if(x[i] != j && ( x-1 > -1 && x[i-1] == x[i]) || (x[i] == x[i+1]) ){
					x[N+1] = x[i];
					x[i] = j;
//					puts("---");
//					pa();
					M = min(func(),M);
					x[i] = x[N+1];
				}
			}
		}
		printf("%d\n", M);
	}
	return 0;
}

Compiler output:
a.cc: In function 'int func()':
a.cc:34:44: error: 'class std::vector<std::pair<int, int> >' has no member named 'top'
   34 |                                 }else if(S.top().first == x[i] && S.top().second + now > 3){
      |                                            ^~~
a.cc:34:69: error: 'class std::vector<std::pair<int, int> >' has no member named 'top'
   34 |                                 }else if(S.top().first == x[i] && S.top().second + now > 3){
      |                                                                     ^~~
a.cc:36:43: error: 'class std::vector<std::pair<int, int> >' has no member named 'pop'
   36 |                                         S.pop();
      |                                           ^~~
a.cc:40:43: error: 'class std::vector<std::pair<int, int> >' has no member named 'push'
   40 |                                         S.push(t);
      |                                           ^~~~
a.cc:46:35: error: 'class std::vector<std::pair<int, int> >' has no member named 'push'
   46 |                                 S.push(t);
      |                                   ^~~~
a.cc:62:26: error: 'class std::vector<std::pair<int, int> >' has no member named 'top'
   62 |                 ret += S.top().second;
      |                          ^~~
a.cc:63:19: error: 'class std::vector<std::pair<int, int> >' has no member named 'pop'
   63 |                 S.pop();
      |                   ^~~
a.cc: In function 'int main()':
a.cc:81:55: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   81 |                                 if(x[i] != j && ( x-1 > -1 && x[i-1] == x[i]) || (x[i] == x[i+1]) ){
      |                                                   ~~~~^~~~