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 (GCC 5.4.1) (judge verdict: Wrong Answer)

//q1
// pactice
 
#pragma warning(disable:4996)
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wwrite-strings"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#define MAX_NUMBER 100000
#define MAX_STRING 700000

	int aOdd[MAX_NUMBER/2];
	int aEven[MAX_NUMBER/2];
	int aOddPattern[MAX_NUMBER];
	int aEvenPattern[MAX_NUMBER];
	char sInput[MAX_STRING+1]="";

int main() {
 
	char* psInput=NULL;
	int nNumberOfNumber=0;
 
	int i=0;
	int iTemp=0;
	int iOddTopNumber=0;
	int iOddTopCount=0;
	int iOddTopNumber_Temp=0;
	int iOddTopCount_Temp=0;

	int iEvenTopNumber=0;
	int iEvenTopCount=0;
	int iEvenTopNumber_Temp=0;
	int iEvenTopCount_Temp=0;

	int iHaveSameNumber=0;

	for(i=0;i;i++){
		aOdd[i]=0;
		aEven[i]=0;
		aOddPattern[i]=0;
		aEvenPattern[i]=0;
	}
	// read line 1
	gets(sInput);
	nNumberOfNumber=atoi(sInput);

	// read line 2
	gets(sInput);
	psInput = strtok(sInput," ");
	for (i=0;i<nNumberOfNumber;i++){
		iTemp=atoi(psInput);
		if(i%2){
			//Odd
			aOdd[i/2]=iTemp;

			aOddPattern[iTemp-1]=aOddPattern[iTemp-1]+1;

			if(aOddPattern[iTemp-1]>iOddTopCount){
				iOddTopNumber=iTemp;
				iOddTopCount=aOddPattern[iTemp-1];
			}

		} else {
			// Even
			aEven[i/2]=iTemp;

			aEvenPattern[iTemp-1]=aEvenPattern[iTemp-1]+1;
			if(aEvenPattern[iTemp-1]>iEvenTopCount){
				iEvenTopNumber=iTemp;
				iEvenTopCount=aEvenPattern[iTemp-1];
			}
		}
		psInput = strtok(NULL," ");
	}
	if(iOddTopNumber==iEvenTopNumber){
		iHaveSameNumber=1;
		for(i=0;i<nNumberOfNumber;i++){
			if(iOddTopNumber!=i+1 && iOddTopCount == aOddPattern[i]){
				iOddTopNumber=i+1;
				iHaveSameNumber=0;
			}
		}
		if(iHaveSameNumber){
			for(i=0;i<nNumberOfNumber;i++){
				if(iEvenTopNumber!=i+1 && iEvenTopCount == aEvenPattern[i]){
					iEvenTopNumber=i+1;
					iHaveSameNumber=0;
				}
			}
		}
	}

	if(!iHaveSameNumber){
		printf("%d\n",(nNumberOfNumber-iOddTopCount-iEvenTopCount));
	} else {
		if(iOddTopCount>iEvenTopCount){
			iEvenTopNumber_Temp=iEvenTopNumber;
			iEvenTopNumber=0;
			iEvenTopCount_Temp=iEvenTopCount;
			iEvenTopCount=0;
			for(i=0;i<nNumberOfNumber;i++){
				if(iOddTopNumber!=i+1 && iEvenTopCount < aEvenPattern[i]){
					iEvenTopNumber=i;
					iEvenTopCount=aEvenPattern[i];
				}
			}
			if(!iEvenTopNumber){
				iEvenTopNumber=iEvenTopNumber_Temp;
				iEvenTopCount=iEvenTopCount_Temp;
				printf("%d\n",(nNumberOfNumber-iOddTopCount));
			}else {
				printf("%d\n",(nNumberOfNumber-iOddTopCount-iEvenTopCount));
			}
		} else {
			iOddTopNumber_Temp=iOddTopNumber;
			iOddTopNumber=0;
			iOddTopCount_Temp=iOddTopCount;
			iOddTopCount=0;
			for(i=0;i<nNumberOfNumber;i++){
				if(iEvenTopNumber!=i+1 && iOddTopCount < aOddPattern[i]){
					iOddTopNumber=i;
					iOddTopCount=aOddPattern[i];
				}
			}
			if(!iOddTopNumber){
				iOddTopNumber=iOddTopNumber_Temp;
				iOddTopCount=iOddTopCount_Temp;
				printf("%d\n",(nNumberOfNumber-iEvenTopCount));
			}else {
				printf("%d\n",(nNumberOfNumber-iOddTopCount-iEvenTopCount));
			}
		}
	}
 

	return 0;
}