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: Accepted)

#include <stdio.h>
#include <stdlib.h>

struct key_value {
  int key;
  int value;
};
struct tree_map {
    struct key_value *center;
    struct tree_map *left;
    struct tree_map *right;
};
struct kv_tupple {
    struct key_value *left;
    struct key_value *right;
};
struct tree_map *add_map(int key, struct tree_map *pointer);
void show_tree_map(struct tree_map *pointer);
struct key_value *make_kv(int key);
struct tree_map *make_node(int key);

struct kv_tupple *make_kv_tupple();
void find_top2(struct kv_tupple *tupple, struct tree_map *pointer);
int need_num(int sum, struct key_value *pointer);

struct tree_map
*add_map(int key, struct tree_map *pointer)
{
  if(NULL == pointer) {
    pointer = make_node(key);
  } else {
    if(pointer->center->key == key){
      pointer->center->value++;
    }else if(pointer->center->key < key){
      pointer->right = add_map(key, pointer->right);
    } else {
      pointer->left = add_map(key, pointer->left);
    }
  }
  return pointer;
}

void
show_tree_map(struct tree_map *pointer)
{
  if(NULL != pointer->left ){
    show_tree_map(pointer->left);
  }
  printf("key=%d  value=%d\n", pointer->center->key, pointer->center->value);
  if(NULL != pointer->right ){
    show_tree_map(pointer->right);
  }
}

struct key_value
*make_kv(int key)
{
  struct key_value *pointer = malloc(sizeof(struct key_value));
  pointer->key = key;
  pointer->value = 1;
  return pointer;
}

struct tree_map
*make_node(int key)
{
  struct tree_map *pointer = malloc(sizeof(struct tree_map));
  pointer->center = make_kv(key);
  pointer->left = NULL;
  pointer->right = NULL;
  return pointer;
}

struct kv_tupple
*make_kv_tupple()
{
  struct kv_tupple *pointer = malloc(sizeof(struct kv_tupple));
  pointer->left = NULL;
  pointer->right = NULL;
  return pointer;
}

void
find_top2(struct kv_tupple *tupple, struct tree_map *pointer)
{
  if(NULL != pointer->left ){
    find_top2(tupple, pointer->left);
  }
  if(NULL == tupple->left || tupple->left->value < pointer->center->value) {
    tupple->right = tupple->left;
    tupple->left = pointer->center;
  } else if(NULL == tupple->right || tupple->right->value < pointer->center->value) {
    tupple->right = pointer->center;
  }
  if(NULL != pointer->right ){
    find_top2(tupple, pointer->right);
  }
}

int
need_num(int sum, struct key_value *pointer)
{
 if(NULL == pointer){
   return sum;
 } else {
   return sum - pointer->value;
 }
}

int
main(void)
{
  int N, v;
  scanf("%d", &N);
  struct tree_map *map1=NULL;
  struct tree_map *map2=NULL;
  int sum1=N/2+N%2;
  int sum2=N/2;
  struct kv_tupple *tupple1 = make_kv_tupple();
  struct kv_tupple *tupple2 = make_kv_tupple();

  for(int i = 0; i < N; i++) {
    scanf("%d", &v);
    if(i%2==0) {
      map1 = add_map(v, map1);
    } else {
      map2 = add_map(v, map2);
    }
  }
  find_top2(tupple1, map1);
  find_top2(tupple2, map2);

  if(tupple1->left->key != tupple2->left->key) {
    printf("%d\n", need_num(sum1, tupple1->left) + need_num(sum2, tupple2->left));
  } else {
    int ans1 = need_num(sum1, tupple1->left) + need_num(sum2, tupple2->right);
    int ans2 = need_num(sum1, tupple1->right) + need_num(sum2, tupple2->left);
    if(ans1<ans2) {
      printf("%d\n", ans1);
    } else {
      printf("%d\n", ans2);
    }
  }
  return 0;
}