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 Ruby (2.3.3) (judge verdict: Accepted)

n = gets.to_i
vs = gets.split.map(&:to_i)

vs1 = []
vs2 = []
vs.length.times{|x|
    vs1.push(vs[x]) if x % 2 == 0
    vs2.push(vs[x]) if x % 2 != 0
}

vs1_h = Hash.new(0)
vs2_h = Hash.new(0)

vs.length.times{|x|
    vs1_h[vs[x]] = vs1_h[vs[x]] + 1 if x % 2 == 0
    vs2_h[vs[x]] = vs2_h[vs[x]] + 1 if x % 2 != 0
}

n1,n2 = vs1_h.sort_by{|_,v| v}.reverse
m1,m2 = vs2_h.sort_by{|_,v| v}.reverse

n1f,n1b = n1
m1f,m1b = m1

n2f,n2b = n2
m2f,m2b = m2

v1_count = 0
v2_count = 0

if (n2 == nil) && (m2 == nil)
    if n1f == m1f
        ans = vs.length / 2
    else
        ans = 0
    end
elsif (n2 != nil) && (m2 == nil)
    if n1f == m1f
        ans = vs.length / 2 - n2b
    else
        ans = vs.length / 2 - n1b
    end
elsif (n2 == nil) && (m2 != nil)
    if n1f == m1f
        ans = vs.length / 2 - m2b
    else
        ans = vs.length / 2 - m1b
    end
else
    if n1f == m1f
        ans = vs.length - [n1b+m2b,n2b+m1b].max
    else
        ans = vs.length - m1b - n1b
    end
end

puts ans