2017/12/05

0534
#include
#include
#include

using namespace std;

int n;


int ch(vector a){
int tans = n;
int f = 1;
int ren = 1,pre = 0;
while(f){
f = 0;
pre = 0,ren = 1;
for(int i = 0;i < tans;i++){
if(a[i] == pre){
ren++;
}else{
pre = a[i];
if(ren >= 4){
tans -= ren;
f = 1;
a.erase(a.begin()+i-ren,a.begin()+i);
i -= ren+1;
}
ren = 1;
}
}
}
return tans;
}

int main(){

while(1){

vector c;


scanf("%d",&n);

if(n == 0) break;

int ans = n;

for(int i = 0;i < n;i++){
int tmp;
scanf("%d",&tmp);
c.push_back(tmp);
}

for(int i = 0;i < n;i++){
int ttt = c[i];
for(int j = 1;j < 4;j++){
if(j == ttt) continue;
c[i] = j;
ans = min(ans,ch(c));
//printf("%d",ans);
}
c[i] = ttt;
}

printf("%d ",ans);

}

return 0;

}