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 C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program {
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
        int[] v = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        //偶数番目の要素を取り出した配列
        int[] odd = v.ToList().Where((name, index) => index % 2 == 0).ToArray();
        //奇数番目の要素を取り出した配列
        int[] even = v.ToList().Where((name, index) => index % 2 == 1).ToArray();

        //重複している数字の個数を出す
        var duplicationList_Odd = odd
                             .ToList()
                             .GroupBy(x => x)
                             .Where(g => g.Count() >= 1)
                             .Select(g => new { number = g.Key, duplicationCount = g.Count() })
                             .ToList();
        var duplicationList_Even = even
                             .ToList()
                             .GroupBy(x => x)
                             .Where(g => g.Count() >= 1)
                             .Select(g => new { number = g.Key, duplicationCount = g.Count() })
                             .ToList();

        //これらを、duplicdationCountが降順になるように並び替える
        var orderByDesList_Odd = duplicationList_Odd
                                       .OrderByDescending(g => g.duplicationCount);
        var orderByDesList_Even = duplicationList_Even
                                       .OrderByDescending(g => g.duplicationCount);

        //解答(数字がかぶっていて、変える必要のない数字の個数)
        int chofuku = 0;
        
        //奇数番目で一番よく使われている数字と、偶数番目で一番よく使われている数字が違うとき→カンタン！
        if (orderByDesList_Odd.First().number != orderByDesList_Even.First().number) {
            chofuku = orderByDesList_Odd.First().duplicationCount + orderByDesList_Even.First().duplicationCount;
            //Console.WriteLine("1");
        //奇数番目で一番よく使われている数字と、偶数番目で一番よく使われている数字が同じとき→場合分け複雑！
        } else {
            //奇数番目も偶数番目も、ともに一種類しかないとき
            if (orderByDesList_Even.ToArray().Length == 1 && orderByDesList_Odd.ToArray().Length == 1) {
                chofuku = odd.Length;
            //偶数番目のみが一種類のとき
            } else if (orderByDesList_Even.ToArray().Length == 1) {
                chofuku = orderByDesList_Odd.ToArray()[1].duplicationCount;
            //奇数番目のみが一種類のとき
            } else if (orderByDesList_Odd.ToArray().Length == 1) {
                chofuku = orderByDesList_Even.ToArray()[1].duplicationCount;
            //どちらも二種類以上あるとき
            } else {
                chofuku = Math.Max(orderByDesList_Even.ToArray()[0].duplicationCount + orderByDesList_Odd.ToArray()[1].duplicationCount, orderByDesList_Even.ToArray()[1].duplicationCount + orderByDesList_Odd.ToArray()[0].duplicationCount);
            }
        }
            
        //    (orderByDesList_Odd.First().number == orderByDesList_Even.First().number) {
        //    if (orderByDesList_Even.ToArray().Length >= 2) {
        //        choufuku = orderByDesList_Odd.First().duplicationCount + orderByDesList_Even.ToArray()[1].duplicationCount;
        //        //Console.WriteLine("2");
        //    } else {
        //        choufuku = orderByDesList_Odd.First().duplicationCount;
        //        //Console.WriteLine("3");
        //    }
        //} else if (orderByDesList_Odd.First().number < orderByDesList_Even.First().number) {
        //    if (orderByDesList_Odd.ToArray().Length >= 2) {
        //        choufuku = orderByDesList_Odd.ToArray()[1].duplicationCount + orderByDesList_Even.First().duplicationCount;
        //        //Console.WriteLine("4");
        //    } else {
        //        choufuku = orderByDesList_Even.First().duplicationCount;
        //        //Console.WriteLine("5");
        //    }
        //}

        //出力
        Console.WriteLine(n - chofuku);
    }
}