program main
Implicit None
	integer(8)::n,i,pa(2),pb(2),qa(2),qb(2),s,e
	integer(8),allocatable::v(:),a(:),b(:)
	
	read*,n
	allocate(v(n))
	read*,v
	n =n/2
	allocate(a(n),b(n))
	
	if(minval(v) == maxval(v))then
		print"(i0)",n
		stop
	endif
	
	do i =1,n
		a(i) = v(2*i-1)
		b(i) = v(2*i)
	enddo
	
	call h1(a,n)
	call h1(b,n)
	
	pa = 0
	pb = 0
	qa = 0
	qb = 0
	
	s =1
	do i = 1,n
		if(a(i+1)/=a(i))then
			if(i-s+1 > pa(1))then
				pa(2) = pa(1)
				qa(2) = qa(1)
				pa(1) = i-s+1
				qa(1) = a(i)
				else if(pa(2) < i-s+1)then
				pa(2) = i-s+1
				qa(2) = a(i)
			endif
			s = i+1
		endif
	enddo
	
	s =1
	do i = 1,n
		if(b(i+1)/=b(i))then
			if(i-s+1 > pb(1))then
				pb(2) = pb(1)
				qb(2) = qb(1)
				pb(1) = i-s+1
				qb(1) = b(i)
				else if(pb(2) < i-s+1)then
				pb(2) = i-s+1
				qb(2) = b(i)
			endif
			s = i+1
		endif
	enddo
	
	e = pa(1)+pb(1)
	if(qa(1) == qb(1))then
		if(pa(1)+pb(2) < pa(2)+pb(1) .or. pb(2) == 0)then
			e = pa(2)+pb(1)
			else
			e = pa(1)+pb(2)
		endif
	endif
	
	print"(i0)",2*n-e
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
