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# (.NET Core 3.1.201) (judge verdict: Time Limit Exceeded)

using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;

class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int[] v = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

		List<int> k = new List<int>();
		List<int> kc = new List<int>();

		List<int> g = new List<int>();
		List<int> gc = new List<int>();
		HashSet<int> vs = new HashSet<int>();

		for (int i = 0;i < N; i++)
        {
			vs.Add(v[i]);
			if (i % 2 == 0)
			{
				int tmp = g.IndexOf(v[i]);
				if (tmp == -1)
                {
					g.Add(v[i]);
					gc.Add(1);
				}
				else
				{
					gc[tmp]++;
				}
			}
			else
			{
				int tmp = k.IndexOf(v[i]);
				if (tmp == -1)
				{
					k.Add(v[i]);
					kc.Add(1);
				} 
				else
				{
					kc[tmp]++;
				}
			}
        }

		if (vs.Count() == 1)
			Console.WriteLine(N / 2);
		else
		{
			int tgm = 0;
			int tkm = 0;
			while (true)
			{
				int gcm = gc.Max();
				int kcm = kc.Max();
				int gci = gc.IndexOf(gcm);
				int kci = kc.IndexOf(kcm);

				if (k[kci] != g[gci])
				{
					if(tgm == 0 && tkm == 0)
                    {
						Console.WriteLine(N - gcm - kcm);
					}
					else if (gcm < kcm)
					{
						Console.WriteLine(N - tgm - kcm);
					}
                    else
                    {
						Console.WriteLine(N - gcm - tkm);
					}
					return;
				}
				tgm = gcm;
				gc[gci] = 0;
				tkm = kcm;
				kc[kci] = 0;
			}
		}
	}
	static class NC
    {
		public static  int num { get; set; }
		public static int count { get; set; }
    }

	/// <summary>
	/// アナグラム
	/// </summary>
	/// <param name="word1"></param>
	/// <param name="word2"></param>
	/// <returns></returns>
	static bool IsAnagramOf(string word1, string word2)
	{
		return word1.OrderBy(x => x).SequenceEqual(word2.OrderBy(x => x));
	}
	/// <summary>
	/// 最小公倍数
	/// </summary>
	/// <param name="a"></param>
	/// <param name="b"></param>
	/// <returns></returns>
	public static long Lcm(long a, long b)
	{
		return a * b / Gcd(a, b);
	}

	/// <summary>
	/// 最大公約数
	/// </summary>
	/// <param name="a"></param>
	/// <param name="b"></param>
	/// <returns></returns>
	public static long Gcd(long a, long b)
	{
		if (a < b)
			// 引数を入替えて自分を呼び出す
			return Gcd(b, a);
		while (b != 0)
		{
			var remainder = a % b;
			a = b;
			b = remainder;
		}
		return a;
	}
}




//string s = Console.ReadLine();
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];
//int N = int.Parse(Console.ReadLine());
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());
//Boolean ok = false;

//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.ReadKey();
//Console.WriteLine(cnt);

//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];