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)

'use strict';

function Main(input) {
  const N = Number(input.split("\n")[0]);
  const line = input.split("\n")[1].split(" ").map(x => Number(x));
  let lineA = [];
  let lineB = [];
  let lineA_counter = {};
  let lineB_counter = {};
  let counter = 0;

  for(let i=0; i<N; i+=2) {
    lineA.push(line[i]);
    lineB.push(line[i+1]);
  }

  for(let i=0; i<N/2; i++) {
    if(lineA_counter[String(lineA[i])] == null) {
      lineA_counter[String(lineA[i])] = 1;
    } else {
      lineA_counter[String(lineA[i])]++;
    }
    if(lineB_counter[String(lineB[i])] == null) {
      lineB_counter[String(lineB[i])] = 1;
    } else {
      lineB_counter[String(lineB[i])]++;
    }
  }

  const howmax = (list) => {
    let valuelist = [];
    for(let key in list) {
      valuelist.push(list[key]);
    }
    return  Math.max.apply(null, valuelist);
  }

  const wheremax = (list, max) => {
    for(let key in list) {
      if(list[key] === max) {
        return key;
      }
    }
  }

  let maxA = howmax(lineA_counter);
  let maxA_index = wheremax(lineA_counter, maxA); // 何にあわせるべきかわかる
  let maxB = howmax(lineB_counter);
  let maxB_index = wheremax(lineB_counter, maxB);

  const calc = () => {
    let lineA_counter_copy = {}
    let lineB_counter_copy = {}
    for(let key in lineA_counter) {
      lineA_counter_copy[key] = lineA_counter[key]
    }
    for(let key in lineB_counter) {
      lineB_counter_copy[key] = lineB_counter[key]
    }

    lineA_counter_copy[maxA_index] = 0;
    lineB_counter_copy[maxB_index] = 0;
    for(let key in lineA_counter_copy) {
      counter += lineA_counter_copy[key];
    }
    for(let key in lineB_counter_copy) {
      counter += lineB_counter_copy[key];
    }
    return counter;
  }


  if(maxA_index != maxB_index) {
    console.log(calc());
  } else if(maxA > maxB) {
    // Bは２番めに大きい数を探す必要がある
    let tmp1 = lineB_counter[maxB_index];
    lineB_counter[maxB_index] = 0;
    maxB = howmax(lineB_counter);
    maxB_index = wheremax(lineB_counter, maxB);
    console.log(calc() + tmp1);
  } else if(maxA < maxB) {
    let tmp2 = lineA_counter[maxA_index];
    lineA_counter[maxA_index] = 0;
    maxA = howmax(lineA_counter);
    maxA_index = wheremax(lineA_counter, maxA);
    console.log(calc() + tmp2);
  } else {
    let tmptmp1 = 0;
    let tmptmp2 = 0;

    let tmp1 = lineB_counter[maxB_index];
    lineB_counter[maxB_index] = 0;
    maxB = howmax(lineB_counter);
    const maxB_index_temp = maxB_index;
    maxB_index = wheremax(lineB_counter, maxB);
    tmptmp1 = calc() + tmp1;
    lineB_counter[maxB_index_temp] = tmp1;

    let tmp2 = lineA_counter[maxA_index];
    lineA_counter[maxA_index] = 0;
    maxA = howmax(lineA_counter);
    const maxA_index_temp = maxA_index;
    maxA_index = wheremax(lineA_counter, maxA);
    tmptmp2 = calc() + tmp2;

    console.log(Math.min(tmptmp1, tmptmp2));
  }


};

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());