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.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 前準備
            List<ClsPos> lst1C = new List<ClsPos>();
            List<ClsPos> lst2C = new List<ClsPos>();
            for (int i = 0; i <= 100000; i++) { lst1C.Add(new ClsPos(){ iV = i, iC = 0 }); lst2C.Add(new ClsPos() { iV = i, iC = 0 }); }

            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            sS = System.Console.ReadLine().Trim().Split(' ');
            //// Debug入力
            //int iN = 100000;

            // 解析
            List<int> lstV = new List<int>();
            for (int i = 0; i < sS.Length; i++)
            {
                int iV = int.Parse(sS[i]);
                lstV.Add(iV);                                                                           // 全部
                if (i % 2 == 0) { lst1C[iV].iC += 1; }                                                  // 奇数個目
                else { lst2C[iV].iC += 1; }                                                             // 偶数個目
            }
            //List<int> lstV = new List<int>();
            //for (int i = 0; i < iN; i++)
            //{
            //    int iV = i + 1;
            //    lstV.Add(iV);                                                                           // 全部
            //    if (i % 2 == 0) { lst1C[iV].iC += 1; }                                                  // 奇数個目
            //    else { lst2C[iV].iC += 1; }                                                             // 偶数個目
            //}

            int iOut = 0;
            if (lstV.Count(x => x == lstV[0]) == lstV.Count) { iOut = lstV.Count / 2; }                 // 全部同じ
            if (iOut == 0)
            {
                lst1C.Sort(delegate (ClsPos mca1, ClsPos mca2) { return (int)(mca2.iC - mca1.iC); });   // 個数で降順
                lst2C.Sort(delegate (ClsPos mca1, ClsPos mca2) { return (int)(mca2.iC - mca1.iC); });   // 個数で降順
                Boolean b1All = false, b2All = false;
                if (lst1C[0].iC == iN / 2) { b1All = true; }                                            // 奇数個目全部同じ？
                if (lst2C[0].iC == iN / 2) { b2All = true; }                                            // 偶数個目全部同じ？
                if (b1All && b2All) { iOut = 0; }                                                       // /\/\/\/ である。
                else if (b2All)                                                                         // 偶数個目だけ全て同じ
                {                                                                                       // 奇数個目だけ調整 → 一番多い項目以外を一番多い項目に変更する場合の操作数
                    for (int i = 1; i < lst1C.Count; i++)
                    {
                        if (lst1C[i].iC == 0) { break; }
                        iOut += lst1C[i].iC;
                    }
                }
                else if (b1All)                                                                         // 奇数個目だけ全て同じ
                {                                                                                       // 偶数個目だけ調整 → 一番多い項目以外を一番多い項目に変更する場合の操作数
                    for (int i = 1; i < lst2C.Count; i++)
                    {
                        if (lst2C[i].iC == 0) { break; }
                        iOut += lst2C[i].iC;
                    }
                }
                else                                                                                    // 奇数個目、偶数個目共に違う
                {                                                                                       // 両方調整 → 一番多い項目以外を一番多い項目に変更する場合の操作数
                    if (lst1C[0].iV == lst2C[0].iV)                                                     // 一番多い項目が同じvの場合は個数の少ない方を変更
                    {
                        if (lst1C[0].iC >= lst2C[0].iC)                                                 // 偶数個目の方を2番目に多い項目に変更
                        {

                            for (int i = 1; i < lst1C.Count; i++)
                            {
                                if (lst1C[i].iC == 0) { break; }
                                iOut += lst1C[i].iC;
                            }
                            for (int i = 0; i < lst2C.Count; i++)
                            {
                                if (i == 1) { continue; }                                               // 2番目の項目は抜かす
                                if (lst2C[i].iC == 0) { break; }
                                iOut += lst2C[i].iC;
                            }
                        }
                        else                                                                            // 奇数個目の方を2番目に多い項目に変更
                        {

                            for (int i = 0; i < lst1C.Count; i++)
                            {
                                if (i == 1) { continue; }                                               // 2番目の項目は抜かす
                                if (lst1C[i].iC == 0) { break; }
                                iOut += lst1C[i].iC;
                            }
                            for (int i = 1; i < lst2C.Count; i++)
                            {
                                if (lst2C[i].iC == 0) { break; }
                                iOut += lst2C[i].iC;
                            }
                        }
                    }
                    else                                                                                // 一番多い項目が違うvの場合そのvでそれぞれ統一
                    {
                        for (int i = 1; i < lst1C.Count; i++)
                        {
                            if (lst1C[i].iC == 0) { break; }
                            iOut += lst1C[i].iC;
                        }
                        for (int i = 1; i < lst2C.Count; i++)
                        {
                            if (lst2C[i].iC == 0) { break; }
                            iOut += lst2C[i].iC;
                        }
                    }
                }
            }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

        // 情報
        private class ClsPos
        {
            public int iV { get; set; } = 0;                    // v
            public int iC { get; set; } = 0;                    // 個数
        }

}