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;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace ARC103C
{
    class Program
    {
        static void Solve()
        {
            var n = Input.NextInt();
            var v = Input.NextInt(n);

            // 奇数か偶数番目の内でそれぞれ一番使用されている数を採用する
            var vodd = v
                .Select((x, i) => new { Value = x, Index = i })
                .Where(x => (x.Index) % 2 != 0)
                .ToList();
            var voddMax = vodd
                .GroupBy(x => x.Value)
                .Select(x => new { Key = x.Key, Count = x.Count() })
                .OrderByDescending(x => x.Count)
                .ToArray();

            var veven = v
                .Select((x, i) => new { Value = x, Index = i })
                .Where(x => (x.Index % 2) == 0)
                .ToList();
            var vevenMax = veven
                .GroupBy(x => x.Value)
                .Select(x => new { Key = x.Key, Count = x.Count() })
                .OrderByDescending(x => x.Count)
                .ToArray();

            if (n == 2)
            {
                if (v[0] == v[1])
                {
                    Console.WriteLine(1);
                }
                else
                {
                    Console.WriteLine(0);
                }
                return;
            }

            // 最大値がかぶっていたなら、次の値が大きい方を変える
            if (voddMax[0].Key == vevenMax[0].Key)
            {
                var vodd2 = voddMax.Count() > 1 ? voddMax[1].Count : 0;
                var veven2 = vevenMax.Count() > 1 ? vevenMax[1].Count : 0;

                if (veven2 < vodd2)
                {
                    // evenの方が2個目の数が小さいので、evenをそのまま採用する
                    Console.WriteLine(vodd.Count() - vodd2
                        + veven.Count() - vevenMax[0].Count);
                }
                else
                {
                    // oddの方をそのまま採用する
                    // 2個目のカウントが同じ場合はどっちでもよい
                    Console.WriteLine(vodd.Count() - voddMax[0].Count
                        + veven.Count() - veven2);
                }
            }
            else
            {
                Console.WriteLine(vodd.Count() - voddMax[0].Count
                    + veven.Count() - vevenMax[0].Count);
            }
        }

        #region Competitive Template
        public static void Main(string[] args)
        {
            var needsFlushOutput = true;
            if (needsFlushOutput)
            {
                // 細かく出力しないようにする
                var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
                Console.SetOut(sw);
            }

            // 仮想的に標準入力をセットする
            // NextLine系を使っていると使えない
            //Input.SetText("");

            Solve();

            Console.Out.Flush();
        }

        static class Input
        {
            static char[] separator = { ' ' };
            public static bool IsEof { get; set; }
            static Queue<string> q { get; set; }

            static Input()
            {
                IsEof = false;
                q = new Queue<string>();
            }

            /// <summary>
            /// 入力予約
            /// </summary>
            /// <param name="items"></param>
            public static void SetText(IEnumerable<string> items)
            {
                foreach (var item in items)
                {
                    SetText(item);
                }
            }

            /// <summary>
            /// 入力予約
            /// </summary>
            /// <param name="s"></param>
            /// <returns></returns>
            public static bool SetText(string s)
            {
                if (s == null) return false;

                foreach (var elem in s.Trim().Split(separator, StringSplitOptions.RemoveEmptyEntries))
                {
                    q.Enqueue(elem);
                }

                return true;
            }

            /// <summary>
            /// 内部queueに入力からの値をsplitして格納する
            /// </summary>
            /// <returns></returns>
            static bool read()
            {
                var s = Console.ReadLine();
                if (s == null) return false;

                foreach (var elem in s.Trim().Split(separator, StringSplitOptions.RemoveEmptyEntries))
                {
                    q.Enqueue(elem);
                }

                if (!q.Any()) return read();

                return true;
            }

            /// <summary>
            /// 次のstringを一つ読み込む
            /// </summary>
            /// <returns></returns>
            public static string Next()
            {
                if (!q.Any())
                {
                    if (!read())
                    {
                        IsEof = true;
                        return "";
                    }
                }

                return q.Dequeue();
            }

            public static int NextInt() => int.Parse(Next());
            public static long NextLong() => long.Parse(Next());
            public static double NextDouble() => double.Parse(Next());

            public static List<string> Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList();
            public static List<int> NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList();
            public static List<long> NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList();
            public static List<double> NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList();

            public static List<string> NextLine() => Console.ReadLine().Trim().Split(separator, StringSplitOptions.RemoveEmptyEntries).ToList();
            public static List<int> NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList();
            public static List<long> NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList();
            public static List<double> NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList();
        }
        #endregion
    }
}