Problem:
Score : 300 points

Problem Statement

A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:

For each i = 1,2,..., n-2, a_i = a_{i+2}.

Exactly two different numbers appear in the sequence.

You are given a sequence v_1,v_2,...,v_n whose length is even.
We would like to make this sequence /\/\/\/ by replacing some of its elements.
Find the minimum number of elements that needs to be replaced.

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

Print the minimum number of elements that needs to be replaced.

Sample Input 1

4
3 1 3 2

Sample Output 1

1

The sequence 3,1,3,2 is not /\/\/\/, but we can make it /\/\/\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

The sequence 105,119,105,119,105,119 is /\/\/\/.

Sample Input 3

4
1 1 1 1

Sample Output 3

2

The elements of the sequence 1,1,1,1 are all the same, so it is not /\/\/\/.

Solution in Fortran (gfortran v4.8.4) (judge verdict: Wrong Answer)

program main
implicit None
	integer(8)::n,i,pa,qa,ra,sa,pb,qb,rb,sb,t
	integer(8),allocatable::v(:),a(:),b(:)
	
	read*,n
	allocate(v(n),a(n/2),b(n/2))
	
	read *,v
	
	n = n/2
	if(minval(v) == maxval(v))then
		print 101,n
		stop
	endif
	
	do i = 1,n
		a(i) = v(2*i-1)
		b(i) = v(2*i)
	enddo
	
	call a1(a,n,pa,qa,ra,sa)
	call a1(b,n,pb,qb,rb,sb)
	
	if(ra /= rb)then
		t = 2*n-pa-pb
		else if(pa-qa > pb-qb)then
		t = 2*n-pa-qb
		else
		t = 2*n-qa-pb
	endif
	
	print 101,t
101 format(i0)
end program main

subroutine h2(a,n)
implicit None
	integer(8)::a(n),x
	integer(8)::n,i,ie,i0,i1,i2
	
	do i = n/2,1,-1
		x = a(i);ie = n + 1; i0 = i; i1 = i0 * 2
		do while(i1 < ie)
			i2 = i1 + 1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
	do ie = n,2,-1
		x = a(ie)
		a(ie) = a(1)
		a(1) = x
		i0 =1;i1 =2
		do while(i1 <ie)
			i2 = i1 +1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
end subroutine h2

subroutine a1(a,n,p,q,r,s)
	integer(8)::n,p,q,r,s,t
	integer(8)::a(n)
	
	call h2(a,n)
	p =0
	q =0
	t =1
	r =0
	s =0
	do i = 2,n
		if(a(i) == a(i-1))then
			t = t + 1
			else
			if(t > p)then
				q = p
				p = t
				s = r
				r = a(i-1)
				t =1
				else if(t > q)then
					q = t
					s = a(i-1)
					t =1
			endif
		endif
	enddo
	
	if(t > p)then
		q = p
		p = t
		s = r
		r = a(i-1)
		else if(t > q)then
			q = t
			s = a(i-1)
	endif
end subroutine a1