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 Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)



import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = n / 2;
        int[] even = new int[m];
        int[] odd = new int[m];
        for (int i = 0; i < m; i++) {
            even[i] = sc.nextInt();
            odd[i] = sc.nextInt();
        }
        Map<Integer, Integer> evenMap = new HashMap<>();
        Map<Integer, Integer> oddMap = new HashMap<>();
        for (int i = 0; i < m; i++) {
            if (evenMap.containsKey(even[i])) {
                evenMap.put(even[i], evenMap.get(even[i]) + 1);
            } else {
                evenMap.put(even[i], 1);
            }
            if (oddMap.containsKey(odd[i])) {
                oddMap.put(odd[i], oddMap.get(odd[i]) + 1);
            } else {
                oddMap.put(odd[i], 1);
            }
        }

        List<Paramater> evenList = new ArrayList<>();
        List<Paramater> oddList = new ArrayList<>();
        for (Map.Entry<Integer, Integer> entry : evenMap.entrySet()) {
            Paramater parameter = new Paramater();
            parameter.setParam1(entry.getKey());
            parameter.setParam2(entry.getValue());
            evenList.add(parameter);
        }
        for (Map.Entry<Integer, Integer> entry : oddMap.entrySet()) {
            Paramater parameter = new Paramater();
            parameter.setParam1(entry.getKey());
            parameter.setParam2(entry.getValue());
            oddList.add(parameter);
        }

        Collections.sort(evenList, new TestComparator());
        Collections.sort(oddList, new TestComparator());

        if (evenList.size() == 1 && oddList.size() == 1) {
            if (evenList.get(0).getParam1() == oddList.get(0).getParam1()) {
                System.out.println(m);
            } else {
                System.out.println(0);
            }
        } else if (evenList.size() == 1 && oddList.size() > 1) {
            if (evenList.get(0).getParam1() == oddList.get(0).getParam1()) {
                System.out.println(m - oddList.get(1).getParam2());
            } else {
                System.out.println(m - oddList.get(0).getParam2());
            }
        } else if (evenList.size() > 1 && oddList.size() == 1) {
            if (evenList.get(0).getParam1() == oddList.get(0).getParam1()) {
                System.out.println(m - evenList.get(1).getParam2());
            } else {
                System.out.println(m - evenList.get(0).getParam2());
            }
        } else {
            int e1i = evenList.get(0).getParam1();
            int e1n = evenList.get(0).getParam2();
            int e2i = evenList.get(1).getParam1();
            int e2n = evenList.get(1).getParam2();
            int o1i = oddList.get(0).getParam1();
            int o1n = oddList.get(0).getParam2();
            int o2i = oddList.get(1).getParam1();
            int o2n = oddList.get(1).getParam2();
            if (e1i == o1i) {
                System.out.println(Math.min(n - e2n - o1n, n - e1n - o2n));
            } else {
                System.out.println(n - e1n - o1n);
            }

        }
    }

}
//複数キーのソート
class Paramater {
    private int param1;
    private int param2;

    public int getParam1() {
        return param1;
    }

    public void setParam1(int param1) {
        this.param1 = param1;
    }

    public int getParam2() {
        return param2;
    }

    public void setParam2(int param2) {
        this.param2 = param2;
    }

}

class TestComparator implements Comparator<Paramater> {
    @Override
    public int compare(Paramater o1, Paramater o2) {
        return o2.getParam2() - o1.getParam2();
    }

}