open Printf
open Scanf

let id x = x
let pair x y = x, y

let n = scanf "%d" id
let vs = Array.init n @@ fun _ -> scanf " %d" id

module IMap = Map.Make(struct type t = int let compare = Pervasives.compare end)

let odd = ref IMap.empty
let even = ref IMap.empty

let incrmap mapr key =
  if IMap.mem key !mapr then
    mapr := IMap.add key (IMap.find key !mapr + 1) !mapr
  else
    mapr := IMap.add key 1 !mapr

let maxi mapr =
  let lis = IMap.bindings !mapr in
  let lis = List.sort (fun (k1,v1) (k1,v2) -> v2 - v1) lis in
  match lis with
  | [] -> failwith ""
  | (v, n) :: rest -> (v, n, rest)

let () =
  for i = 0 to n - 1 do
    if i mod 2 == 0 then begin
      incrmap odd vs.(i)
    end else begin
      incrmap even vs.(i)
    end
  done;
  let (k1, v1, rest1) = maxi odd in
  let (k2, v2, rest2) = maxi even in
  let run k1 k2 v1 v2 rest1 rest2 =
    if k1 <> k2 then begin
      let n1 = List.fold_left (fun acc (v, n) -> acc + n) 0 rest1 in
      let n2 = List.fold_left (fun acc (v, n) -> acc + n) 0 rest2 in
      n1 + n2
    end else if v1 > v2 then begin
      let n1 = List.fold_left (fun acc (v, n) -> acc + n) 0 rest1 in
      match rest2 with
      | [] -> n1 + n / 2
      | (k, v) :: _ -> n1 + n / 2 - v
    end else if v1 < v2 then begin
      let n2 = List.fold_left (fun acc (v, n) -> acc + n) 0 rest2 in
      match rest1 with
      | [] -> n2 + n / 2
      | (k, v) :: _ -> n2 + n / 2 - v 
    end else begin
      (* k1 = k2, v1 = v2 *)
      let rec loop rest1 rest2 =
        match rest1, rest2 with
        | [], [] -> 0
        | [], (k', v') :: rest' -> v'
        | (k', v') :: rest', [] -> v'
        | (k1', v1') :: rest1', (k2', v2') :: rest2' ->
          if k1 <> k2 then begin
            if v1' < v2' then
              let n1 = List.fold_left (fun acc (v, n) -> acc + n) 0 rest1' in
              let n2 = List.fold_left (fun acc (v, n) -> acc + n) 0 rest2' in
              n1 + n2 + v2'
            else if v1' > v2' then
              let n1 = List.fold_left (fun acc (v, n) -> acc + n) 0 rest1' in
              let n2 = List.fold_left (fun acc (v, n) -> acc + n) 0 rest2' in
              n1 + n2 + v1'
            else failwith ""
          end else
            (* k1' = k2', v1' = v2' *)
            (* v1' + v2' + loop rest1' rest2' *)
            n / 0
      in
      v1 + loop rest1 rest2
    end
  in
  let result = run k1 k2 v1 v2 rest1 rest2 in
  printf "%d\n" result
