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: Wrong Answer)

using System;
using System.Linq;
using System.Collections.Generic;

public class Hello
{
    public static void Main()
    {
        // Your code here!
        int n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        
        int[] odd = new int[100010];
        int[] even = new int[100010];
        int oddMax1st = -1; //奇数列の最頻値
        int oddMax2nd = -2;
        int oddMode1st = -1;
        int oddMode2nd = -2;
        int evenMax1st = -1;
        int evenMax2nd = -2;
        int evenMode1st = -1;
        int evenMode2nd = -2;
        
        for(int i = 0; i < odd.Length; i++)
        {
            odd[i] = 0;
            even[i] = 0;
        }
        for(int i = 0; i < n; i++)//odd,evenに値を代入
        {
            if((i + 1) % 2 == 0)
            {
                even[a[i]] += 1;
            }
            else
            {
                odd[a[i]] += 1;
            }
        }
        
        for(int i = 0; i < odd.Length; i++)//配列oddのMax1stとMax2ndを求める
        {
            if(odd[i] > oddMax1st)
            {
                oddMax2nd = oddMax1st;
                oddMax1st = odd[i];
            }
            else if((odd[i] > oddMax2nd) && (odd[i] < oddMax1st))
            {
                oddMax2nd = odd[i];
            }
        }
        
        for(int i = 0; i < even.Length; i++)//配列evenのMax1stとMax2ndを求める
        {
            if(even[i] > evenMax1st)
            {
                evenMax2nd = evenMax1st;
                evenMax1st = even[i];
            }
            else if((even[i] > evenMax2nd) && (even[i] < evenMax1st))
            {
                evenMax2nd = even[i];
            }
        }
        
        for(int i = 0; i < odd.Length; i++)//配列oddのMax1stとMax2ndのときの番地を求める
        {
            if(odd[i] == oddMax1st)
            {
                oddMode1st = i;
            }
            if(odd[i] == oddMax2nd)
            {
                oddMode2nd = i;
            }
        }
        
        for(int i = 0; i < even.Length; i++)//配列evenのMax1stとMax2ndのときの番地を求める
        {
            if(even[i] == evenMax1st)
            {
                evenMode1st = i;
            }
            if(even[i] == evenMax2nd)
            {
                evenMode2nd = i;
            }
        }
        
        
        if(oddMode1st != evenMode1st)//最頻値が違う場合
        {
            int countOdd = 0;
            int countEven = 0;
            for(int i = 0; i < n - 1; i += 2)//奇数列をみる
            {
                if(a[i] != oddMode1st)
                {
                    countOdd++;
                }
            }
            for(int i = 1; i < n; i += 2)//偶数列をみる
            {
                if(a[i] != evenMode1st)
                {
                    countEven++;
                }
            }
            
            
            Console.WriteLine(countOdd + countEven);
        }
        else if(oddMode1st == evenMode1st)//最頻値が一緒の場合
        {
            //奇数列を最頻値で書き換えて，偶数列を2番目の数で書き換える場合
            int countOdd1 = 0;
            int countEven1 = 0;
            int count1 = 0;
            
            for(int i = 0; i < n - 1; i += 2)//奇数列をみる
            {
                if(a[i] != oddMode1st)
                {
                    countOdd1++;
                }
            }
            for(int i = 1; i < n; i += 2)//偶数列をみる
            {
                if(a[i] != evenMode2nd)
                {
                    countEven1++;
                }
            }
            count1 = countOdd1 + countEven1;
            
            //奇数列を2番目の数で書き換えて，偶数列を最頻値で書き換える場合
            int countOdd2 = 0;
            int countEven2 = 0;
            int count2 = 0;
            
            for(int i = 0; i < n - 1; i += 2)//奇数列をみる
            {
                if(a[i] != oddMode2nd)
                {
                    countOdd2++;
                }
            }
            for(int i = 1; i < n; i += 2)//偶数列をみる
            {
                if(a[i] != evenMode1st)
                {
                    countEven2++;
                }
            }
            count2 = countOdd2 + countEven2;
            
            Console.WriteLine(Math.Min(count1, count2));
            
            
        }
        
    }
}