Problem: problem

There are the following games.

N characters are lined up in a vertical row. The color of these characters is red, blue, or yellow, and in the initial state, four or more characters of the same color are not lined up in a row. The player can select a character at a certain position and change it to another color. By this operation, if four or more characters of the same color are lined up in a row, those characters will disappear. When four or more characters of the same color are lined up in a row due to the disappearance of the characters, those characters also disappear, and this chain continues until there are no more places where four or more characters of the same color are lined up in a row. .. The purpose of this game is to reduce the number of characters remaining without disappearing.

For example, if the color of the sixth character from the top is changed from yellow to blue in the state at the left end of the figure below, five blue characters will disappear in a row, and finally three characters will remain without disappearing.

<image>


Given the color sequence of N characters in the initial state, create a program that finds the minimum value M of the number of characters that remain without disappearing when the color of the character is changed in only one place.



input

The input consists of multiple datasets. Each dataset is given in the following format.

The first line consists of only the number of characters N (1 ≤ N ≤ 10000). The following N lines contain one of 1, 2, and 3 integers, and the i + 1st line (1 ≤ i ≤ N) represents the color of the i-th character from the top in the initial state (1). Is red, 2 is blue, and 3 is yellow).

When N is 0, it indicates the end of input. The number of datasets does not exceed 5.

output

For each dataset, output the minimum value M of the number of characters remaining without disappearing on one line.

Examples

Input

12
3
2
1
1
2
3
2
2
2
1
1
3
12
3
2
1
1
2
3
2
1
3
2
1
3
0


Output

3
12


Input

None


Output

None

Solution (in JAVA):

Solution:
import java.awt.Point;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	
	public static class Segment{
		int length, color;

		public Segment(int length, int color) {
			super();
			this.length = length;
			this.color = color;
		}

		@Override
		public String toString() {
			return "Segment [length=" + length + ", color=" + color + "]";
		}
	}
	
	public static int remove(ArrayList<Segment> seg_list, int left, int right){
		int reduce = 0;
		
		while(left >= 0 && right < seg_list.size()){
			if(seg_list.get(left).color != seg_list.get(right).color){
				break;
			}
			
			final int len = seg_list.get(left).length + seg_list.get(right).length;
			if(len < 4){
				break;
			}
			
			left--;
			right++;
			reduce += len;
		}
		
		return reduce;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			ArrayList<Segment> seg_list = new ArrayList<Main.Segment>();
			for(int i = 0; i < n; i++){
				final int color = sc.nextInt();
				
				if(seg_list.isEmpty()){
					seg_list.add(new Segment(1, color));
				}else if(seg_list.get(seg_list.size() - 1).color == color){
					seg_list.get(seg_list.size() - 1).length++;
				}else{
					seg_list.add(new Segment(1, color));
				}
			}
			
			int min = n;
			
			for(int divide = 0; divide < seg_list.size(); divide++){
				if(seg_list.get(divide).length == 1){
					//
					//--xxxo---
					if(divide != 0 && seg_list.get(divide - 1).length >= 3){
						final int len = 1 + seg_list.get(divide - 1).length;
						min = Math.min(min, n - len - remove(seg_list, divide - 2, divide + 1));
					}
					
					//oxxx
					if(divide != seg_list.size() - 1 && seg_list.get(divide + 1).length >= 3){
						final int len = 1 + seg_list.get(divide + 1).length;
						min = Math.min(min, n - len - remove(seg_list, divide - 1, divide + 2));
					}
					
					//xxoxx
					if(divide != 0 && divide != seg_list.size() - 1 &&
							seg_list.get(divide - 1).color == seg_list.get(divide + 1).color){
						final int len = seg_list.get(divide - 1).length + seg_list.get(divide + 1).length + 1;
						
						if(len >= 4){
							min = Math.min(min, n - len - remove(seg_list, divide - 2, divide + 2));
						}
					}
				}else{
					//--xxxo---
					if(divide != 0 && seg_list.get(divide - 1).length >= 3){
						final int len = seg_list.get(divide - 1).length + 1;
						seg_list.get(divide).length--;
						min = Math.min(min, n - len - remove(seg_list, divide - 2, divide));
						seg_list.get(divide).length++;
					}
					
					//oxxx
					if(divide != seg_list.size() - 1 && seg_list.get(divide + 1).length >= 3){
						final int len = 1 + seg_list.get(divide + 1).length;
						seg_list.get(divide).length--;
						min = Math.min(min, n - len - remove(seg_list, divide, divide + 2));
						seg_list.get(divide).length++;
					}
				}
			}
			
			System.out.println(min);
		}
		
	}
}