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 static System.Math;
using static _20200225.Cin;
using static _20200225.Util;
using Pair = _20200225.VTuple<long, long>;
using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>;
using System.Text;

namespace _20200225
{
    public class Program
    {
        public static void Main(string[] args)
        {
            // Abc075_B(); 10m
            // Code_Festival_2017_Qualc_B(); 22m
            // Arc054_A(); 37m
            Arc103_A();
        }

        public static void Arc103_A()
        {
            long N = rl;
            long[] A = rla;

            HashMap<long, long> hm0 = new HashMap<long, long>();
            HashMap<long, long> hm1 = new HashMap<long, long>();
            for (int i = 0; i < N; i++)
            {
                if(i % 2 == 0)
                {
                    hm0[A[i]]++;
                }
                else
                {
                    hm1[A[i]]++;
                }
            }

            long hm0k = hm0.Keys.OrderByDescending(k => hm0[k]).Max();
            long hm1k = hm1.Keys.OrderByDescending(k => hm1[k]).Max();

            var hm0Vals = hm0.Values.OrderByDescending(m => m).ToList();
            long hm0a = hm0Vals[0];
            long hm0b = (hm0Vals.Count > 1) ? hm0Vals[1] : 0;
            var hm1Vals = hm1.Values.OrderByDescending(m => m).ToList();
            long hm1a = hm1Vals[0];
            long hm1b = (hm1Vals.Count > 1) ? hm1Vals[1] : 0;

            if (hm0k == hm1k)
            {
                long ans1 = (N / 2) - hm0a + (N / 2) - hm1b;
                long ans2 = (N / 2) - hm0b + (N / 2) - hm1a;
                Console.WriteLine(Min(ans1,ans2));
            }
            else
            {
                long ans = (N/2) - hm0a + (N/2) - hm1a;
                Console.WriteLine(ans);
            }

        }

        public static void Arc054_A()
        {
            long l = rl;
            long x = rl;
            long y = rl;
            long s = rl;
            long d = rl;

            long tokei = 0;
            long hantokei = 0;
            if (s == d)
            {
                Console.WriteLine(0);
                return;
            }
            else if (d > s)
            {
                tokei = d - s;
                hantokei = s + l - d;
            }
            else
            {
                tokei = l - s + d;
                hantokei = s - d;
            }

            double tokeiTime = (double)tokei / Abs(x + y);
            double hantokeiTime = (double)hantokei / Abs(x - y);

            Console.WriteLine(Min(tokeiTime,hantokeiTime));
        }

        public static void Code_Festival_2017_Qualc_B()
        {
            long N = rl;
            long[] A = rla;
            long a = 1;
            long b = 1;
            for (int i = 0; i < N; i++)
            {
                a *= 3;
                if (A[i] % 2 == 0)
                {
                    b *= 2;
                }
            }
            Console.WriteLine(a - b);
        }

        public static void Abc075_B()
        {
            long H = rl;
            long W = rl;
            string[] s = new string[H];
            for (int i = 0; i < H; i++)
            {
                s[i] = rs;
            }

            string[] ans = new string[H];
            FillArray(ans, string.Empty);

            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if (s[i][j] == '#')
                    {
                        ans[i] += '#';
                        continue;
                    }

                    int cnt = 0;
                    for (int dx = -1; dx <= 1; dx++)
                    {
                        for (int dy = -1; dy <= 1; dy++)
                        {
                            if (0 <= i + dy && i + dy < H &&
                                0 <= j + dx && j + dx < W)
                            {
                                if (s[i + dy][j + dx] == '#')
                                    cnt++;
                            }
                        }
                    }
                    ans[i] += cnt.ToString();
                }
            }

            for (int i = 0; i < H; i++)
            {
                Console.WriteLine(ans[i]);
            }
        }
    }
    public class HashMap<K,V>:Dictionary<K,V>{V i;static Func<V>j=System.Linq.Expressions.Expression.Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))).Compile();public HashMap(){}public HashMap(V a){i=a;}new public V this[K a]{get{V b;if(TryGetValue(a,out b))return b;else return base[a]=i!=null?i:j();}set{base[a]=value;}}}public static class Util{public static readonly long INF=(long)1e17;public readonly static long MOD=(long)1e9+7;public static void DontAutoFlush(){var a=new System.IO.StreamWriter(Console.OpenStandardOutput()){AutoFlush=false};Console.SetOut(a);}public static void Flush(){Console.Out.Flush();}public static T[]Sort<T>(T[]a){Array.Sort<T>(a);return a;}public static T[]SortDecend<T>(T[]a){Array.Sort<T>(a);Array.Reverse(a);return a;}public static void Swap<T>(ref T a,ref T b){T c=a;a=b;b=c;}public static int GCD(int a,int b){return(b==0)?a:GCD(b,a%b);}public static void ChMax(ref long a,long b){if(a<b)a=b;}public static void ChMin(ref long a,long b){if(a>b)a=b;}public static long ModAdd(long a,long b){long c=a+b;if(c>=MOD)return c%MOD;return c;}public static long ModMul(long a,long b){long c=a*b;if(c>=MOD)return c%MOD;return c;}public static void ChModAdd(ref long a,long b){a+=b;if(a>=MOD)a%=MOD;}public static void ChModMul(ref long a,long b){a*=b;if(a>=MOD)a%=MOD;}public static void FillArray<T>(T[]a,T b){int c=a.Length;for(int d=0;d<c;d++)a[d]=b;}public static void FillArray<T>(T[,]a,T b){int c=a.GetLength(0);int d=a.GetLength(1);for(int e=0;e<c;e++)for(int f=0;f<d;f++){a[e,f]=b;}}public static void FillArray<T>(T[,,]a,T b){int c=a.GetLength(0);int d=a.GetLength(1);int e=a.GetLength(2);for(int f=0;f<c;f++)for(int g=0;g<d;g++){for(int h=0;h<e;h++){a[f,g,h]=b;}}}public static long[]Accumulate(long[]a){long[]b=new long[a.Length+1];for(int c=0;c<a.Length;c++)b[c+1]=b[c]+a[c];return b;}public static double[]Accumulate(double[]a){double[]b=new double[a.Length+1];for(int c=0;c<a.Length;c++)b[c+1]=b[c]+a[c];return b;}}public static class Cin{public static long rl{get{return ReadLong();}}public static long[]rla{get{return ReadLongArray();}}public static double rd{get{return ReadDouble();}}public static double[]rda{get{return ReadDoubleArray();}}public static string rs{get{return ReadString();}}public static int ReadInt(){return int.Parse(k());}public static long ReadLong(){return long.Parse(k());}public static double ReadDouble(){return double.Parse(k());}public static string ReadString(){return k();}public static int[]ReadIntArray(){i=null;return Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);}public static long[]ReadLongArray(){i=null;return Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);}public static double[]ReadDoubleArray(){i=null;return Array.ConvertAll(Console.ReadLine().Split(' '),double.Parse);}public static void ReadCols(out long[]a,out long[]b,long c){a=new long[c];b=new long[c];for(int d=0;d<c;d++){a[d]=ReadLong();b[d]=ReadLong();}}public static void ReadCols(out long[]a,out long[]b,out long[]c,long d){a=new long[d];b=new long[d];c=new long[d];for(int e=0;e<d;e++){a[e]=ReadLong();b[e]=ReadLong();c[e]=ReadLong();}}public static int[][]ReadIntTable(int a){i=null;int[][]b=new int[a][];for(int c=0;c<a;c++)b[c]=ReadIntArray();return b;}public static long[][]ReadLongTable(long a){i=null;long[][]b=new long[a][];for(long c=0;c<a;c++)b[c]=ReadLongArray();return b;}static string[]i{get;set;}static int j{get;set;}static string k(){if(i==null||i.Length<=j){i=Console.ReadLine().Split(' ');j=0;}return i[j++];}}public struct VTuple<T1,T2>:IComparable<VTuple<T1,T2>>,IEquatable<VTuple<T1,T2>>{public T1 First;public T2 Second;public VTuple(T1 a,T2 b){First=a;Second=b;}public int CompareTo(VTuple<T1,T2>a){int b=Comparer<T1>.Default.Compare(First,a.First);if(b!=0)return b;return Comparer<T2>.Default.Compare(Second,a.Second);}public override bool Equals(object a){return a is VTuple<T1,T2>&&Equals((VTuple<T1,T2>)a);}public bool Equals(VTuple<T1,T2>a){return EqualityComparer<T1>.Default.Equals(First,a.First)&&EqualityComparer<T2>.Default.Equals(Second,a.Second);}public override int GetHashCode(){int a=First!=null?First.GetHashCode():0;int b=Second!=null?Second.GetHashCode():0;uint c=((uint)a<<5)|((uint)a>>27);return((int)c+a)^b;}}
}