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.Diagnostics;
using System.IO;
using System.Linq;

namespace NAMINAMI
{
    class Program
    {
        public static void Main(string[] args)
        {
            using (var sc = new SetConsole())
            {
                int n = GetIntInput();
                var input = GetArrayIntInput();
                var edic = new Dictionary<int, int>();
                var odic = new Dictionary<int, int>();
                for (int i = 0; i < n; i++)
                {
                    if (i % 2 == 0)
                    {
                        if (edic.ContainsKey(input[i]))
                        {
                            edic[input[i]]++;
                        }
                        else
                        {
                            edic.Add(input[i], 1);
                        }
                    }
                    else
                    {
                        if (odic.ContainsKey(input[i]))
                        {
                            odic[input[i]]++;
                        }
                        else
                        {
                            odic.Add(input[i], 1);
                        }
                    }
                }
                var commonInE = edic.Aggregate((acc, e) => acc.Value < e.Value ? e : acc);
                var commonInO = odic.Aggregate((acc, e) => acc.Value < e.Value ? e : acc);

                if (commonInE.Key == commonInO.Key  && (edic.Count == 1 || odic.Count == 1))
                {
                    if (1 < edic.Count)
                    {
                        edic.Remove(commonInE.Key);
                        var secondCommonInE = edic.Aggregate((acc, e) => acc.Value < e.Value ? e : acc);
                        edic.Remove(secondCommonInE.Key);
                        edic.Add(commonInE.Key, commonInE.Value);
                        CWrite(edic.Sum(d => d.Value));
                    }
                    else if (1 < odic.Count)
                    {
                        odic.Remove(commonInE.Key);
                        var secondCommonInO = odic.Aggregate((acc, e) => acc.Value < e.Value ? e : acc);
                        odic.Remove(secondCommonInO.Key);
                        odic.Add(commonInO.Key, commonInO.Value);
                        CWrite(odic.Sum(d => d.Value));
                    }
                    else
                    {
                        CWrite(n / 2);
                    }
                }
                else if (commonInE.Key == commonInO.Key)
                {
                    var copiedEDic = new Dictionary<int, int>(edic);
                    var copiedODic = new Dictionary<int, int>(odic);
                    copiedEDic.Remove(commonInE.Key);
                    copiedODic.Remove(commonInO.Key);
                    var secondCommonInO = copiedODic.Aggregate((acc, e) => acc.Value < e.Value ? e : acc);
                    copiedODic.Remove(secondCommonInO.Key);
                    copiedODic.Add(commonInO.Key, commonInO.Value);
                    var sum1 = copiedEDic.Sum(d => d.Value) + copiedODic.Sum(d => d.Value);

                    copiedEDic = new Dictionary<int, int>(edic);
                    copiedODic = new Dictionary<int, int>(odic);
                    copiedEDic.Remove(commonInE.Key);
                    copiedODic.Remove(commonInO.Key);
                    var secondCommonInE = copiedEDic.Aggregate((acc, e) => acc.Value < e.Value ? e : acc);
                    copiedEDic.Remove(secondCommonInE.Key);
                    copiedEDic.Add(commonInE.Key, commonInE.Value);
                    var sum2 = copiedEDic.Sum(d => d.Value) + copiedODic.Sum(d => d.Value);
                    CWrite(sum1 < sum2 ? sum1 : sum2);
                }
                else
                {
                    edic.Remove(commonInE.Key);
                    odic.Remove(commonInO.Key);
                    CWrite(edic.Sum(d => d.Value) + odic.Sum(d => d.Value));
                }
            }
        }

        static string[] GetArrayCharInput() => Console.ReadLine().Split();
        static int[] GetArrayIntInput() => Console.ReadLine().StringToIntArray();
        static int GetIntInput() => Console.ReadLine().ToInt();
        static void CWrite<T>(T str) => Console.WriteLine(str);
    }

    class SetConsole : IDisposable
    {
        public SetConsole()
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
        }
        public void Dispose()
        {
            Console.Out.Flush();
        }
    }

    static class ExtentionsLibrary
    {
        public static int[] StringToIntArray(this string str) =>
            str.Split().Select(int.Parse).ToArray();
        public static int ToInt(this string str) => int.Parse(str);
    }
}