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 PHP (5.6.30) (judge verdict: Accepted)

<?php
// 整数の入力
fscanf(STDIN, "%d", $n);
//n個の整数の入力
$format = "%d";
for ($i = 1; $i < $n; $i++) {
  $format .= " %d";
}
  //n個を配列に格納
$data = fscanf(STDIN, $format);

//２つに分ける
$even = array();
$odd = array();

for ($i = 0; $i < $n; $i++) {
  if ($i % 2 === 0) {
    $even[] = $data[$i];
  } else {
    $odd[] = $data[$i];
  }
}

//それぞれについて一番多く出た数字を探す
asort($even);

$count = 0; //何連でその数字が出たか
$max_even = 0; //何連のmax値
$pre_num = 0; //前の数字
$max_num = 0; //その数字
foreach ($even as $num) {
  if ($num === $pre_num) {
    //同じ数字出たから
    $count++;
  } else {
    if ($count > $max_even) {
      //何連続記録更新！！
      $max_even = $count;
      $max_num = $pre_num;
    }
    $count = 1;
    $pre_num = $num;
  }
}

//一番最後の数字が一番出てきた時
if ($count > $max_even) {
  $max_even = $count;
  $max_num = $pre_num;
}

//一番出てきた数字以外をその数字に変える
$change_even_first = $n / 2 - $max_even;

//同じことをもう１つの数列でもやる
asort($odd);

$count = 0; //何連でその数字が出たか
$max_odd = 0; //何連のmax値
$pre_num = 0; //前の数字
foreach ($odd as $num) {
  //evenと同じ数字に揃えてはだめ
  if ($num === $max_num) {
    continue;
  }
  if ($num === $pre_num) {
    //同じ数字出たから
    $count++;
  } else {
    if ($count > $max_odd) {
      //何連続記録更新！！
      $max_odd = $count;
    }
    $count = 1;
    $pre_num = $num;
  }
}

//一番最後の数字が一番出てきた時
if ($count > $max_odd) {
  $max_odd = $count;
}

//一番出てきた数字以外をその数字に変える
$change_even_first += $n / 2 - $max_odd;


//evenとoddの順番を入れ替える
//sortは済んでる
$count = 0; //何連でその数字が出たか
$max_odd = 0; //何連のmax値
$pre_num = 0; //その数字
$max_num = 0; //その数字
foreach ($odd as $num) {
  if ($num === $pre_num) {
    //同じ数字出たから
    $count++;
  } else {
    if ($count > $max_odd) {
      //何連続記録更新！！
      $max_odd = $count;
      $max_num = $pre_num;
    }
    $count = 1;
    $pre_num = $num;
  }
}

//一番最後の数字が一番出てきた時
if ($count > $max_odd) {
  $max_odd = $count;
  $max_num = $pre_num;
}

//一番出てきた数字以外をその数字に変える
$change_odd_first = $n / 2 - $max_odd;


$count = 0; //何連でその数字が出たか
$max_even = 0; //何連のmax値
$pre_num = 0; //前の数字
foreach ($even as $num) {
  //oddと同じ数字に揃えてはだめ
  if ($num === $max_num) {
    continue;
  }
  if ($num === $pre_num) {
    //同じ数字出たから
    $count++;
  } else {
    if ($count > $max_even) {
      //何連続記録更新！！
      $max_even = $count;
    }
    $count = 1;
    $pre_num = $num;
  }
}

//一番最後の数字が一番出てきた時
if ($count > $max_even) {
  $max_even = $count;
}

//一番出てきた数字以外をその数字に変える
$change_odd_first += $n / 2 - $max_even;

if ($change_even_first < $change_odd_first) {
  echo $change_even_first;
} else {
  echo $change_odd_first;
}

?>