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 JavaScript (node.js v5.12) (judge verdict: Wrong Answer)

var AnalyzeItems = function(Items){
  var Result = {};
  Items.forEach(function(value){
    if(Result[value] == undefined){
      Result[value] = 1;
    } else {
      ++Result[value];
    }
  });
  return Result;
}

var MapToObject = function(MyMap){
  var Result = [];
  Object.keys(MyMap).forEach(function(MyKey){
    Result.push({Item: MyKey, Count: MyMap[MyKey]});
  });
  return Result;
}

var Main = function(Input){
  // 行を分割
  var Lines = Input.split('\n');

  // 配列の要素数と、要素
  var Items = Number(Lines[0]);
  var ItemArr = Lines[1].split(' ').map(function (element){return Number(element);});
  
  // 奇数番目と偶数番目とで分ける
  var Odd = [];
  var Even = [];
  ItemArr.forEach(function(value, index){
    if(index % 2 == 0){
      Odd.push(value);
    } else {
      Even.push(value);
    }
  });
  var OddItems = AnalyzeItems(Odd);
  var EvenItems = AnalyzeItems(Even);

  var OddItems2 = MapToObject(OddItems).sort((a,b) => {
    if(a.Count < b.Count){
      return 1;
    }
    return -1;
  });
  var EvenItems2 = MapToObject(EvenItems).sort((a,b) => {
    if(a.Count < b.Count){
      return 1;
    }
    return -1;
  });

  if(OddItems2.length == 1){
    if(EvenItems2.length == 1){
      if(OddItems2[0].Item == EvenItems2[0].Item){
        console.log(OddItems2[0].Count);
        return;
      } else {
        console.log(0);
        return;
      }
    } else {
      // Oddの番号は1種類だが、Evenの番号が複数種ある場合
      var FirstNumberCount = EvenItems2[0].Count;
      console.log(Items / 2 - FirstNumberCount);
      return;
    }
  } else if(EvenItems2.length == 1){
    // Evenの番号は1種類だが、Oddの番号が複数種ある場合
    var FirstNumberCount = OddItems2[0].Count;
    console.log(Items / 2 - FirstNumberCount);
    return;
  }

  // OddもEvenも複数種の番号を含む場合
  if(OddItems2[0].Item != EvenItems2[0].Item){
    // OddもEvenも最頻出の数字が異なる場合
    var OddCount = Items / 2 - OddItems2[0].Count;
    var EvenCount = Items / 2 - EvenItems2[0].Count;
    console.log(OddCount + EvenCount);
    return;
  } else {
    // 同じ場合
    if(OddItems2[0].Count > EvenItems2[0].Count){
      var OddCount = Items / 2 - OddItems2[0].Count;
      var EvenCount = Items / 2 - EvenItems2[1].Count;
      console.log(OddCount + EvenCount);
      return;
    } else {
      var OddCount = Items / 2 - OddItems2[1].Count;
      var EvenCount = Items / 2 - EvenItems2[0].Count;
      console.log(OddCount + EvenCount);
      return;
    }
  }
}

// Main(require("fs").readFileSync('./180929C.txt', "utf8"));
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));