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,p(2),q(2),r(2),s(2)
	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(i*2-1)
		b(i) = v(i*2)
	enddo
	
	call h1(a,n)
	call h1(b,n)
	
	p =0;q =0;r =0;s =0
	
	call a1(a,n,p,q)
	call a1(b,n,r,s)
	
	if(q(1) /= s(1))then
		print 101,2*n-p(1)-r(1)
		stop
	endif
	
	i = 2*n-p(1)-r(2)
	if(i > 2*n-p(2)-r(1)) i = 2*n-p(2)-r(1)
	
	print 101,i
	
101 format(i0)
end program main

subroutine h1(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 h1

subroutine a1(a,n,p,q)
Implicit None
integer(8)::n,p(2),q(2),i,t=1
integer(8)::a(n)
	do i = 2,n
		if(a(i) == a(i-1))then
			t = t+1
			else
			if (t > p(1))then
				p(2) = p(1)
				p(1) = t
				q(2) = q(1)
				q(1) = a(i-1)
				t = 1
				else if(t > p(2))then
				p(2) = t
				q(2) = a(i-1)
				t = 1
			endif
		endif
	enddo
	
	if (t > p(1))then
		p(2) = p(1)
		p(1) = t
		q(2) = q(1)
		q(1) = a(i-1)
		t = 1
		else if(t > p(2))then
		p(2) = t
		q(2) = a(i-1)
		t = 1
	endif
end subroutine a1