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: Accepted)

'use strict'

const appear = arr => {
    let obj = {}
    arr.forEach(v => {
        if(obj[v] === undefined){
            obj[v] = 0
        }
        obj[v]++
    })
    return [maxObj(obj), obj]
}

const maxObj = (obj) => {
    let m = null
    let max = 0
    for(let key in obj){
        if(obj[key] > max){
            max = obj[key]
            m = key
        }
    }
    return m
}

const main = (input) => {
    const arr = input.split('\n')[1].split(' ').map(v => parseInt(v))
    const arr0 = arr.filter((v, i) => i % 2 === 0)
    const arr1 = arr.filter((v, i) => i % 2 !== 0)
    const m0d = appear(arr0)
    const m0 = m0d[0]
    const m0o = m0d[1]
    const m1d = appear(arr1)
    const m1 = m1d[0]
    const m1o = m1d[1]


    if(m0 === m1){
        // 最頻出の値をコピー
        const m0c = m0o[m0]
        const m1c = m1o[m1]

        // それぞれの最頻出を削除
        delete m0o[m0]
        delete m1o[m1]
        
        // 次に多く出てくるものの個数を取得
        const o0 = Object.keys(m0o).length === 0 ? 0 : m0o[maxObj(m0o)]
        const o1 = Object.keys(m1o).length === 0 ? 0 : m1o[maxObj(m1o)]

        // arr0は最頻出、arr1は次頻出を増やすパターンと
        // arr0は次頻出、arr1は最頻出を増やすパターンがある
        if(m0c + o1 > m1c + o0){
            console.log(arr.length - (m0c + o1))
        }else{
            console.log(arr.length - (m1c + o0))
        }
    }else{
        // 最頻出が同じでないとき
        console.log(arr.length - m0o[m0] - m1o[m1])
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))