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: Time Limit Exceeded)

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

namespace AtCoder
{
    class Pair
    {
        public int num;
        public int count;
    }

    class Program
    {
        static void Main()
        {
            //ここから
            int n = ReadLineToInt();
            int[] v = ReadLineToIntArray();

            List<Pair> pairs1 = new List<Pair>();
            List<Pair> pairs2 = new List<Pair>();

            pairs1.Add(new Pair { num = 0, count = 0 });
            pairs2.Add(new Pair { num = 0, count = 0 });

            for(int i = 0; i < n; i += 2)
            {
                if (pairs1.Any(p => p.num == v[i]))
                {
                    pairs1.First(p => p.num == v[i]).count++;
                }
                else
                {
                    Pair pair = new Pair
                    {
                        num = v[i], count = 1
                    };
                    pairs1.Add(pair);
                }
            }

            for (int i = 1; i < n; i += 2)
            {
                if (pairs2.Any(p => p.num == v[i]))
                {
                    pairs2.First(p => p.num == v[i]).count++;
                }
                else
                {
                    Pair pair = new Pair
                    {
                        num = v[i],
                        count = 1
                    };
                    pairs2.Add(pair);
                }
            }

            var pair1_temp = pairs1.OrderByDescending(p => p.count).ToList();
            var pair2_temp = pairs2.OrderByDescending(p => p.count).ToList();

            int tar;

            if (pair1_temp[0].num == pair2_temp[0].num)
            {
                tar = pair1_temp[0].count > pair2_temp[0].count ? pair1_temp[0].count + pair2_temp[1].count : pair1_temp[1].count + pair2_temp[0].count;
            }
            else
            {
                tar = pair1_temp[0].count + pair2_temp[0].count;
            }

            int ans = n - tar;

            //ここまで
            Console.WriteLine(ans);
            Console.ReadKey();
        }

        long mod = 1000000007;
        static public void Swap<T>(ref T a,ref T b) { T temp = a;a = b;b = temp; }
        static public long GCD(int a, int b){ return b != 0 ? GCD(b, a % b) : a;}
        static public long LCM(int a, int b){ return (long)a * b / GCD(a, b); }
        static public int Factorial(int a) { return a == 1 ? a : a * Factorial(a - 1); }
        static public int Conbin(int n,int m) { return Factorial(n) / (Factorial(n - m) * Factorial(m)); }


        
        static public string ReadLineToString(){return Console.ReadLine();}
        static public int ReadLineToInt(){return int.Parse(Console.ReadLine());}
        static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
        static public string[] ReadLineToStringArray(){return Console.ReadLine().Split(' ').ToArray();}
        static public int[] ReadLineToIntArray(){return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();}
        static public long[] ReadLineToLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<string> ReadLineToStringList(){return Console.ReadLine().Split(' ').ToList();}
        static public List<int> ReadLineToIntList(){return Console.ReadLine().Split(' ').Select(int.Parse).ToList();}
        static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
    }
    
}