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.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Numerics;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        const bool IsTest = false;

        const string t1 = "4\n3 1 3 2";
        const string t2 = "6\n105 119 105 119 105 119";
        const string t3 = "4\n1 1 1 1";
        public static void Main(string[] args)
        {
            if (!IsTest) {
                new Program().Solve(new ConsoleInput(Console.In));
            } else {
                new Program().Solve(new ConsoleInput(new StringReader(t1)));
                new Program().Solve(new ConsoleInput(new StringReader(t2)));
                new Program().Solve(new ConsoleInput(new StringReader(t3)));
            }
        }

        public void Solve(ConsoleInput cin)
        {
            cin.ReadLine();
            var n = cin.Read<int> ();
            cin.ReadLine();
            var v = cin.ReadArray<int>(n);

            var v0 = new Dictionary<int, int> ();
            var v1 = new Dictionary<int, int> ();
            for (var i = 0; i < v.Length; i += 2) {
                var t0 = v[i + 0];
                if (!v0.ContainsKey(t0)) {
                    v0[t0] = 0;
                }
                v0[t0]++;
                var t1 = v[i + 1];
                if (!v1.ContainsKey(t1)) {
                    v1[t1] = 0;
                }
                v1[t1]++;
            }
            var v0a = new List<Tuple<int, int>> ();
            foreach (var i in v0) {
                v0a.Add(new Tuple<int, int>(i.Key, i.Value));
            }
            var v1a = new List<Tuple<int, int>> ();
            foreach (var i in v1) {
                v1a.Add(new Tuple<int, int>(i.Key, i.Value));
            }
            v0a.Sort((a, b) => {
                if (a.Item2 > b.Item2) {
                    return -1;
                } else if (a.Item2 < b.Item2) {
                    return 1;
                } else {
                    return 0;
                }
            });
            v1a.Sort((a, b) => {
                if (a.Item2 > b.Item2) {
                    return -1;
                } else if (a.Item2 < b.Item2) {
                    return 1;
                } else {
                    return 0;
                }
            });
            int r;
            if (v0a[0].Item1 == v1a[0].Item1) {
                if (v0a.Count > 1) {
                    if (v1a.Count > 1) {
                        var d0 = v0a[0].Item2 - v0a[1].Item2;
                        var d1 = v1a[0].Item2 - v1a[1].Item2;
                        if (d0 > d1) {
                            r = v0a[0].Item2 + v1a[1].Item2;
                        } else {
                            r = v0a[1].Item2 + v1a[0].Item2;
                        }
                    } else {
                        // v1a.Count == 1 ie v1a[0].Length = n/2;
                        r = v1a[0].Item2 + v0a[1].Item2;
                    }
                } else {
                    // v0a.Count == 1 ie ...
                    if (v1a.Count > 1) {
                        r = v0a[0].Item2 + v1a[1].Item2;
                    } else {
                        r = v0a[0].Item2;
                    }
                }
            } else {
                r = v0a[0].Item2 + v1a[0].Item2;
            }
            Console.WriteLine((n - r));
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private readonly char _separator = ' ';
        private string _curLine;
        private string[] _curLineSplitted;
        private int _curItemIndex;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
        }
        public T Read<T>()
        {
            var converter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(T));
            if (converter == null) {
                throw new Exception(string.Format("TypeDescriptor.GetConverter {0}", typeof(T).Name));
            }
            return (T)converter.ConvertFromString(ReadString());
        }
        public T[] ReadArray<T>(long N)
        {
            var ret = new T[N];
            for (long i = 0; i < N; i++) {
                ret[i] = Read<T>();
            }
            return ret;
        }
        public Tuple<T> ReadLineAs<T>()
        {
            ReadLine();
            return new Tuple<T>(Read<T>());
        }
        public Tuple<T, S> ReadLineAs<T, S>()
        {
            ReadLine();
            return new Tuple<T, S>(Read<T>(), Read<S>());
        }
        public Tuple<T, S, U> ReadLineAs<T, S, U>()
        {
            ReadLine();
            return new Tuple<T, S, U>(Read<T>(), Read<S>(), Read<U>());
        }
        public Tuple<T, S, U, V> ReadLineAs<T, S, U, V>()
        {
            ReadLine();
            return new Tuple<T, S, U, V>(Read<T>(), Read<S>(), Read<U>(), Read<V>());
        }
        public Tuple<T, S, U, V, R> ReadLineAs<T, S, U, V, R>()
        {
            ReadLine();
            return new Tuple<T, S, U, V, R>(Read<T>(), Read<S>(), Read<U>(), Read<V>(), Read<R>());
        }

        public string ReadString()
        {
            return _curLineSplitted[_curItemIndex++];
        }
        public void ReadLine()
        {
            _curLine = _stream.ReadLine();
            if (_curLine == null) {
                throw new System.Exception("No more lines");
            }
            _curLineSplitted = _curLine.Split(_separator);
            _curItemIndex = 0;
        }
    }
}