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: Runtime Error)

#16
#1 2 4 6 3 5 6 7 2 1 1 2 3 4 4 5
ary=$stdin.readlines
odds=Array.new
evens=Array.new
ary.each do |i|
  i.chomp!
end
n = ary[0].to_i
array=ary[1].split(" ")

array.map!(&:to_i)
#p array
p=0
while p<n
  odds.push(array[p]) if p%2==0
  evens.push(array[p]) if p%2==1
  p+=1
end
#p "odd", odds
#p "evens", evens
num_i_odds=Hash.new
num_i_evens=Hash.new
num_odds=[]
num_evens=[]
odds.each do |i|
  num_i_odds[odds.count(i)] ||= Array.new
  num_i_odds[odds.count(i)].push(i)
  num_odds=num_i_odds.keys
end
evens.each do |i|
  num_i_evens[evens.count(i)] ||= Array.new
  num_i_evens[evens.count(i)].push(i)
  num_evens=num_i_evens.keys
end
#p "num_i_odds",num_i_odds
#p "num_i_evens",num_i_evens
max_num_odds=num_odds.max
max_num_evens=num_evens.max
#p max_num_odds
#p max_num_evens
answer=0
answer+=odds.count{|i| i!=num_i_odds[max_num_odds][0]}
answer+=evens.count{|i| i!=num_i_evens[max_num_evens][0]}

combined = num_i_odds[max_num_odds] + num_i_evens[max_num_evens]
#p combined.uniq

if combined.uniq.count == 1
    answer=0
elm_max_num_odds=elm_num_odds.max_by{|i| !i==max_num_odds}
elm_max_num_evens=elm_num_evens.max_by{|i| !i==max_num_evens}

  if elm_max_num_odds >= elm_max_num_evens
    answer+=odds.count{|i| i!=num_i_odds[elm_max_num_odds][0]}
    answer+=evens.count{|i| i!=num_i_evens[max_num_evens][0]}
  elsif elm_max_num_odds < elm_max_num_evens
    answer+=odds.count{|i| i!=num_i_odds[max_num_odds][0]}
    answer+=evens.count{|i| i!=num_i_evens[elm_max_num_evens][0]}
  end
end
puts answer