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 BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            //var line = consoleReader.SplitInt32();
            var N = consoleReader.Int32();
            var vs = consoleReader.SplitInt32();

            var evens = new Dictionary<int, int>();
            var odds = new Dictionary<int, int>();

            for (int i = 0; i < N; i += 2)
            {
                if (evens.ContainsKey(vs[i]))
                    evens[vs[i]]++;
                else
                    evens.Add(vs[i], 1);
                if (odds.ContainsKey(vs[i + 1]))
                    odds[vs[i + 1]]++;
                else
                    odds.Add(vs[i + 1], 1);
            }

            var sortedEvens = evens.OrderByDescending(p => p.Value).ToArray();
            var sortedOdds = odds.OrderByDescending(p => p.Value).ToArray();

            if (sortedEvens.Length == 1 && sortedOdds.Length == 1)
            {
                if (sortedEvens[0].Key == sortedOdds[0].Key)
                {
                    return sortedEvens[0].Value;
                }
                else return 0;
            }


            if (sortedEvens[0].Key == sortedOdds[0].Key)
            {
                if (sortedEvens.Length == 1)
                {
                    return N / 2 - sortedOdds[1].Value;
                }
                if (sortedOdds.Length == 1)
                {
                    return N / 2 - sortedEvens[1].Value;
                }
                if (sortedOdds[1].Value > sortedEvens[1].Value)
                    return N - sortedOdds[1].Value- sortedEvens[0].Value;
                else
                    return N - sortedOdds[0].Value - sortedEvens[1].Value;
            }

            return N - sortedOdds[0].Value - sortedEvens[0].Value;
        }

        public const int mod = 1000000007;
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
        public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
    }

    public class ConsoleReader { public virtual string String() => Console.ReadLine(); public int Int32() => int.Parse(String()); public long Int64() => long.Parse(String()); public ulong UInt64() => ulong.Parse(String()); public double Double() => double.Parse(String()); public string[] Split() => String().Split().ToArray(); public int[] SplitInt32() => String().Split().Select(int.Parse).ToArray(); public long[] SplitInt64() => String().Split().Select(long.Parse).ToArray(); public ulong[] SplitUInt64() => String().Split().Select(ulong.Parse).ToArray(); public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray(); public IEnumerable<string> Repeat(int count) { for (int i = 0; i < count; i++) yield return String(); } public IEnumerable<int> RepeatInt32(int count) { for (int i = 0; i < count; i++) yield return Int32(); } public IEnumerable<long> RepeatInt64(int count) { for (int i = 0; i < count; i++) yield return Int64(); } public IEnumerable<string[]> RepeatSplit(int count) { for (int i = 0; i < count; i++) yield return Split(); } public IEnumerable<int[]> RepeatSplitInt32(int count) { for (int i = 0; i < count; i++) yield return SplitInt32(); } }
}