Language: Java

import java.io.PrintWriter;
import java.util.*;

public class ARC103C {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] even = new int[n/2];
    int[] odd = new int[n/2];

    HashMap<Integer, Integer> mapEven = new HashMap<>();
    HashMap<Integer, Integer> mapOdd = new HashMap<>();

    PrintWriter out = new PrintWriter(System.out);


    public static void main(String[] args) {
        new ARC103C().run();
    }

    void run() {
        for (int i=0; i<n; i++) {
            if (i%2==0) even[i/2] = sc.nextInt();
            if (i%2!=0) odd[i/2] = sc.nextInt();
        }

        int cnt = 0;
        for (int i=0; i<n/2; i++) {
            if (even[i]==odd[i]) cnt++;
        }

        if (cnt==n/2) {
            out.print(n/2);
            out.flush();
            return;
        }

        for (int i=0; i<n/2; i++) {
            if (!mapEven.containsKey(even[i])) {
                mapEven.put(even[i], 1);
            } else {
                int tmp = mapEven.get(even[i]);
                mapEven.put(even[i], tmp+1);
            }

            if (!mapOdd.containsKey(odd[i])) {
                mapOdd.put(odd[i], 1);
            } else {
                int tmp = mapOdd.get(odd[i]);
                mapOdd.put(odd[i], tmp+1);
            }
        }


        TreeMap<Integer, Integer> newmapEven = sortMapByValue(mapEven);
        TreeMap<Integer, Integer> newmapOdd = sortMapByValue(mapOdd);

//        out.println(newmapEven);
//        out.println(newmapOdd);



        Map.Entry<Integer, Integer> entryEven = newmapEven.entrySet().iterator().next();
        Map.Entry<Integer, Integer> entryOdd = newmapOdd.entrySet().iterator().next();

        if (entryEven.getKey()!=entryOdd.getKey()) {
            out.print(n-entryEven.getValue()-entryOdd.getValue());
        } else {
            if (n/2-entryEven.getValue() < n/2-entryOdd.getValue()) {
                newmapOdd.entrySet().iterator().next();
                Map.Entry<Integer, Integer> entryOddSecond = newmapOdd.entrySet().iterator().next();
                out.print(n-entryEven.getValue()-entryOddSecond.getValue());
            } else {
                newmapEven.entrySet().iterator().next();
                Map.Entry<Integer, Integer> entryEvenSecond = newmapEven.entrySet().iterator().next();
                out.print(n-entryOdd.getValue()-entryEvenSecond.getValue());
            }
        }

        out.flush();

    }

    public TreeMap<Integer, Integer> sortMapByValue(HashMap<Integer, Integer> map){
        Comparator<Integer> comparator = new ValueComparator(map);
        //TreeMap is a map sorted by its keys.
        //The comparator is used to sort the TreeMap by keys.
        TreeMap<Integer, Integer> result = new TreeMap<Integer, Integer>(comparator);
        result.putAll(map);
        return result;
    }

    class ValueComparator implements Comparator<Integer>{

        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();

        public ValueComparator(HashMap<Integer, Integer> map){
            this.map.putAll(map);
        }

        @Override
        public int compare(Integer s1, Integer s2) {
            if(map.get(s1) >= map.get(s2)){
                return -1;
            }else{
                return 1;
            }
        }
    }
}


Compiler output:
Main.java:4: error: class ARC103C is public, should be declared in a file named ARC103C.java
public class ARC103C {
       ^
1 error